Skip to content
Snippets Groups Projects
Commit 7b0b641d authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

Added `--single` CLI option to shut down the Worker after one task.

parent 9390483d
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@ changed functionality, fixed bugs).
- Worker can be told to shut down by the Manager. The environment (for example systemd
on Linux) is responsible for restarting Flamenco Worker after such a shutdown.
- Added `--version` CLI option to show the version of Flamenco Worker and quit.
- Added `--single` or `-1` CLI option to shut down the Worker after executing a single task.
## Version 2.0.8 (released 2017-09-07)
......
......@@ -31,6 +31,8 @@ def main():
help="Starts up in testing mode, in which only a handful of "
"test-specific task types are accepted. This overrides the task_types "
"in the configuration file.")
parser.add_argument('-1', '--single', action='store_true',
help="Runs a single tasks, then exits.")
args = parser.parse_args()
if args.version:
......@@ -55,6 +57,9 @@ def main():
confparser.erase('worker_id')
confparser.erase('worker_secret')
if args.single:
log.info('Running in single-task mode, will stop after performing one task.')
# Find the Manager using UPnP/SSDP if we have no manager_url.
if not confparser.value('manager_url'):
from . import ssdp_discover
......@@ -108,6 +113,7 @@ def main():
push_log_max_entries=confparser.value('push_log_max_entries', int),
push_act_max_interval=confparser.interval_secs('push_act_max_interval_seconds'),
initial_state='testing' if args.test else 'awake',
run_single_task=args.single,
)
mir = may_i_run.MayIRun(
......
......@@ -62,6 +62,7 @@ class TaskRunner:
return False
self._log.info('Task %s completed succesfully.', task_id)
self.current_command = None
return True
async def abort_current_task(self):
......
......@@ -56,6 +56,7 @@ class FlamencoWorker:
# Indicates the state in which the Worker should start
initial_state = attr.ib(validator=attr.validators.instance_of(str), default='awake')
run_single_task = attr.ib(validator=attr.validators.instance_of(bool), default=False)
# When Manager tells us we may no longer run our current task, this is set to True.
# As a result, the cancelled state isn't pushed to Manager any more. It is reset
......@@ -433,6 +434,11 @@ class FlamencoWorker:
except Exception:
self._log.exception('While notifying manager of failure, another error happened.')
finally:
if self.run_single_task:
self._log.info('Running in single-task mode, exiting.')
self.go_to_state_shutdown()
return
if self.state == WorkerState.AWAKE:
# Schedule a new task run unless shutting down or sleeping; after a little delay to
# not hammer the world when we're in some infinite failure loop.
......@@ -637,7 +643,7 @@ class FlamencoWorker:
using systemd on Linux with Restart=always will do this.
"""
self._log.info('Shutting down by request of the Flamenco Manager')
self._log.info('Shutting down by request of the Manager or due to single-task mode')
self.state = WorkerState.SHUTTING_DOWN
# Don't bother acknowledging this status, as we'll push an "offline" status anyway.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment