Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
edulix committed May 1, 2024
1 parent 2c883c6 commit b171104
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
11 changes: 9 additions & 2 deletions frestq/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ def decorator(view_func):
if view_func is not None and not isfunction(view_func):
view_func.action = action
view_func.queue_name = queue
wrapper_func = view_func
else:
def wrapper_func(*args, **kwargs):
print(f"task: Starting task\n\n")
ret = view_func(*args, **kwargs)
print(f"task: Finished task\n\n")
return ret

ActionHandlers.add_action_handler(action, queue, view_func, kwargs)
ActionHandlers.add_action_handler(action, queue, wrapper_func, kwargs)
FScheduler.reserve_scheduler(queue)

return view_func
return wrapper_func

return decorator

Expand Down
27 changes: 20 additions & 7 deletions frestq/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,26 @@ def update_task(msg):

keys = ['output_data', 'status']
for key in keys:
if key in msg.input_data:
if isinstance(msg.input_data[key], str):
logging.debug("SETTING TASK FIELD '%s' to '%s'" % (key,
msg.input_data[key]))
else:
logging.debug("SETTING TASK FIELD '%s' to: %s" % (key,
dumps(msg.input_data[key])))
if key not in msg.input_data:
continue
str_data = (
msg.input_data[key]
if isinstance(msg.input_data[key], str)
else dumps(msg.input_data[key])
)
if (
key == 'status' and
hasattr(task, key) and
task.status == 'finished'
):
logging.debug(
f"({task.id}) **NOT** SETTING TASK FIELD '{key}' to "
f"'{str_data}' because it's already 'finished'"
)
else:
logging.debug(
"({task.id}) SETTING TASK FIELD '{key}' to '{str_data}'"
)
setattr(task, key, msg.input_data[key])
task.last_modified_date = datetime.utcnow()
db.session.add(task)
Expand Down

0 comments on commit b171104

Please sign in to comment.