-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Celery worker the root process (#1560)
* make celery worker main process in container * enable hot reloading option for debugging * restore all Turbinia logging
- Loading branch information
1 parent
252410c
commit 77b4068
Showing
7 changed files
with
96 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Celery worker app. | ||
Configures and Starts the Turbinia Celery worker. | ||
""" | ||
import celery | ||
import logging | ||
import os | ||
|
||
from turbinia import debug | ||
from turbinia import celeryconfig | ||
from turbinia import config | ||
from turbinia import task_utils | ||
from turbinia.config import logger | ||
|
||
config.LoadConfig() | ||
|
||
config.TURBINIA_COMMAND = 'celeryworker' | ||
|
||
|
||
@celery.signals.setup_logging.connect | ||
def on_setup_logging(**kwargs): | ||
"""Setup Turbinia logging as Celery overrides all handlers.""" | ||
logger.setup() | ||
turbinia_log = logging.getLogger('turbinia') | ||
turbinia_log.setLevel('INFO') | ||
if os.getenv('TURBINIA_DEBUG', '') == '1': | ||
turbinia_log.setLevel('DEBUG') | ||
|
||
|
||
app = celery.Celery( | ||
'turbinia', broker=config.CELERY_BROKER, backend=config.CELERY_BACKEND) | ||
app.config_from_object(celeryconfig) | ||
app.task(task_utils.task_runner, name='task_runner') | ||
|
||
debug.initialize_debugmode_if_requested() | ||
|
||
if __name__ == '__main__': | ||
app.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Celery confguration. | ||
Sets configuration for the Turbinia Celery components. | ||
""" | ||
from turbinia import config | ||
|
||
config.LoadConfig() | ||
|
||
accept_content = ['json'] | ||
broker_connection_retry_on_startup = True | ||
# Store Celery task results metadata | ||
result_backend = config.CELERY_BACKEND | ||
task_default_queue = config.INSTANCE_ID | ||
# Re-queue task if Celery worker abruptly exists | ||
task_reject_on_worker_lost = True | ||
task_track_started = True | ||
worker_cancel_long_running_tasks_on_connection_loss = True | ||
worker_concurrency = 1 | ||
worker_prefetch_multiplier = 1 | ||
# Avoid task duplication | ||
worker_deduplicate_successful_tasks = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters