Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankrb committed Jul 8, 2024
1 parent 08cbe4d commit 7141a12
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/anemoi/registry/commands/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def add_arguments(self, command_parser):
default=0,
)
command_parser.add_argument("--loop", help="Run in a loop", action="store_true")
command_parser.add_argument(
"--check-todo",
help="See if there are tasks for this worker and exit with 0 if there are task to do.",
action="store_true",
)

def run(self, args):
kwargs = vars(args)
Expand Down
12 changes: 12 additions & 0 deletions src/anemoi/registry/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging
import os
import signal
import sys
import threading
import time

Expand Down Expand Up @@ -36,6 +37,7 @@ def __init__(
heartbeat=60,
max_no_heartbeat=0,
loop=False,
check_todo=False,
request={},
):
"""Run a worker that will process tasks in the queue.
Expand All @@ -56,6 +58,7 @@ def __init__(
self.heartbeat = heartbeat
self.max_no_heartbeat = max_no_heartbeat
self.loop = loop
self.check_todo = check_todo

self.wait = wait
self.stop_if_finished = stop_if_finished
Expand All @@ -67,6 +70,15 @@ def __init__(
raise ValueError(f"Target directory {target_dir} must already exist")

def run(self):
if self.check_todo:
task = self.choose_task()
if task:
LOG.info("There are tasks to do.")
sys.exit(0)
else:
LOG.info("No tasks to do.")
sys.exit(1)

if self.loop:
while True:
res = self.process_one_task()
Expand Down

0 comments on commit 7141a12

Please sign in to comment.