Skip to content
Snippets Groups Projects
Commit 6bec2192 authored by Milan Jaros's avatar Milan Jaros
Browse files

add task only one

parent 90a83b64
Branches
No related tags found
No related merge requests found
......@@ -80,6 +80,7 @@ def main():
trunner=trunner,
tuqueue=tuqueue,
task_types=confparser.value('task_types').split(),
task_only_one=confparser.value('task_only_one', bool),
worker_id=confparser.value('worker_id'),
worker_secret=confparser.value('worker_secret'),
loop=loop,
......
......@@ -17,6 +17,7 @@ DEFAULT_CONFIG = {
('manager_url', ''),
('task_types', 'unknown sleep blender-render'),
('task_update_queue_db', 'flamenco-worker.db'),
('task_only_one', 'False'),
('may_i_run_interval_seconds', '5'),
('worker_id', ''),
('worker_secret', ''),
......
......@@ -34,6 +34,7 @@ class FlamencoWorker:
trunner = attr.ib() # Instance of flamenco_worker.runner.TaskRunner
tuqueue = attr.ib(validator=attr.validators.instance_of(upstream_update_queue.TaskUpdateQueue))
task_types = attr.ib(validator=attr.validators.instance_of(list))
task_only_one = attr.ib(validator=attr.validators.instance_of(bool))
worker_id = attr.ib(validator=attr.validators.instance_of(str))
worker_secret = attr.ib(validator=attr.validators.instance_of(str))
......@@ -123,7 +124,7 @@ class FlamencoWorker:
if not do_register:
await self.signon(may_retry_loop=may_retry_loop)
self.schedule_fetch_task()
self.schedule_fetch_task(0, True)
@staticmethod
def hostname() -> str:
......@@ -214,7 +215,7 @@ class FlamencoWorker:
# always either a task being executed or a task fetch scheduled.
self.loop.run_forever()
def schedule_fetch_task(self, delay=0):
def schedule_fetch_task(self, delay=0, first=False):
"""Schedules a task fetch.
If a task fetch was already queued, that one is cancelled.
......@@ -222,6 +223,10 @@ class FlamencoWorker:
:param delay: delay in seconds, after which the task fetch will be performed.
"""
if first and self.task_only_one:
self.shutdown()
return
# The current task may still be running, as fetch_task() calls schedule_fetch_task() to
# schedule a future run. This may result in the task not being awaited when we are
# shutting down.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment