добавил обработчик задач
All checks were successful
Deploy timelaps / deploy (push) Successful in 5s
All checks were successful
Deploy timelaps / deploy (push) Successful in 5s
This commit is contained in:
0
camlaps/management/__init__.py
Normal file
0
camlaps/management/__init__.py
Normal file
0
camlaps/management/commands/__init__.py
Normal file
0
camlaps/management/commands/__init__.py
Normal file
31
camlaps/management/commands/run_timelapse_worker.py
Normal file
31
camlaps/management/commands/run_timelapse_worker.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import time
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from ...services.timelapse_worker import run_one_job
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Запуск обработчика очереди таймлапсов.'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--once', action='store_true', help='Обработать только одну задачу и выйти.')
|
||||
parser.add_argument(
|
||||
'--sleep',
|
||||
type=int,
|
||||
default=5,
|
||||
help='Пауза между итерациями в loop-режиме (секунды).',
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
once = options['once']
|
||||
sleep_seconds = options['sleep']
|
||||
|
||||
if once:
|
||||
run_one_job()
|
||||
return
|
||||
|
||||
while True:
|
||||
processed = run_one_job()
|
||||
if not processed:
|
||||
time.sleep(sleep_seconds)
|
||||
Reference in New Issue
Block a user