2018-02-14 22:13:32 +00:00
|
|
|
from celery import Celery
|
|
|
|
import os
|
|
|
|
|
2018-02-15 21:23:29 +00:00
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webodm.settings')
|
|
|
|
|
2018-02-14 22:13:32 +00:00
|
|
|
app = Celery('tasks')
|
2018-02-15 21:23:29 +00:00
|
|
|
app.config_from_object('django.conf:settings', namespace='CELERY')
|
2021-09-07 01:51:05 +00:00
|
|
|
app.conf.result_backend_transport_options = {
|
|
|
|
'retry_policy': {
|
|
|
|
'timeout': 5.0
|
|
|
|
}
|
|
|
|
}
|
2018-02-15 21:23:29 +00:00
|
|
|
|
|
|
|
app.conf.beat_schedule = {
|
|
|
|
'update-nodes-info': {
|
|
|
|
'task': 'worker.tasks.update_nodes_info',
|
|
|
|
'schedule': 30,
|
|
|
|
'options': {
|
|
|
|
'expires': 14,
|
|
|
|
'retry': False
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'cleanup-projects': {
|
|
|
|
'task': 'worker.tasks.cleanup_projects',
|
|
|
|
'schedule': 60,
|
|
|
|
'options': {
|
|
|
|
'expires': 29,
|
|
|
|
'retry': False
|
|
|
|
}
|
|
|
|
},
|
2023-11-06 16:21:10 +00:00
|
|
|
'cleanup-tasks': {
|
|
|
|
'task': 'worker.tasks.cleanup_tasks',
|
|
|
|
'schedule': 3600,
|
|
|
|
'options': {
|
|
|
|
'expires': 1799,
|
|
|
|
'retry': False
|
|
|
|
}
|
|
|
|
},
|
2019-04-01 20:49:56 +00:00
|
|
|
'cleanup-tmp-directory': {
|
|
|
|
'task': 'worker.tasks.cleanup_tmp_directory',
|
|
|
|
'schedule': 3600,
|
|
|
|
'options': {
|
|
|
|
'expires': 1799,
|
|
|
|
'retry': False
|
|
|
|
}
|
|
|
|
},
|
2018-02-15 21:23:29 +00:00
|
|
|
'process-pending-tasks': {
|
|
|
|
'task': 'worker.tasks.process_pending_tasks',
|
|
|
|
'schedule': 5,
|
|
|
|
'options': {
|
|
|
|
'expires': 2,
|
|
|
|
'retry': False
|
|
|
|
}
|
|
|
|
},
|
2023-09-01 20:16:13 +00:00
|
|
|
'check-quotas': {
|
|
|
|
'task': 'worker.tasks.check_quotas',
|
|
|
|
'schedule': 3600,
|
|
|
|
'options': {
|
|
|
|
'expires': 1799,
|
|
|
|
'retry': False
|
|
|
|
}
|
|
|
|
},
|
2018-02-15 21:23:29 +00:00
|
|
|
}
|
2018-02-14 22:13:32 +00:00
|
|
|
|
2020-01-20 21:52:01 +00:00
|
|
|
# Mock class for handling async results during testing
|
|
|
|
class MockAsyncResult:
|
|
|
|
def __init__(self, celery_task_id, result = None):
|
|
|
|
self.celery_task_id = celery_task_id
|
|
|
|
if result is None:
|
|
|
|
if celery_task_id == 'bogus':
|
|
|
|
self.result = None
|
|
|
|
else:
|
|
|
|
self.result = MockAsyncResult.results.get(celery_task_id)
|
|
|
|
else:
|
|
|
|
self.result = result
|
|
|
|
MockAsyncResult.results[celery_task_id] = result
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
return self.result
|
|
|
|
|
|
|
|
def ready(self):
|
|
|
|
return self.result is not None
|
|
|
|
|
|
|
|
MockAsyncResult.results = {}
|
|
|
|
MockAsyncResult.set = lambda cti, r: MockAsyncResult(cti, r)
|
|
|
|
|
2018-02-14 22:13:32 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
app.start()
|