Skip to content

Commit f2742fe

Browse files
committed
run: serialize arguments for celery task
1 parent 85d54b8 commit f2742fe

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

invenio_jobs/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class Job(db.Model, Timestamp):
4949
active = db.Column(db.Boolean, default=True, nullable=False)
5050
title = db.Column(db.String(255), nullable=False)
5151
description = db.Column(db.Text)
52-
# default_args = db.Column(JSON, default=lambda: dict(), nullable=True)
5352
task = db.Column(db.String(255))
5453
default_queue = db.Column(db.String(64))
5554
schedule = db.Column(JSON, nullable=True)
@@ -177,6 +176,12 @@ def dump(self):
177176
dict_run["args"] = serialized_args
178177
return dict_run
179178

179+
@property
180+
def dict_args(self):
181+
"""Return run arguments."""
182+
_args = self.args
183+
return json.loads(_args)
184+
180185

181186
class Task:
182187
"""Celery Task model."""
@@ -208,3 +213,4 @@ def all(cls):
208213
def get(cls, id_):
209214
"""Get registered task by id."""
210215
return cls(current_jobs.registry.get(id_))
216+

invenio_jobs/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def execute_run(self, run_id, kwargs=None):
3333
task = current_jobs.registry.get(run.job.task).task
3434
update_run(run, status=RunStatusEnum.RUNNING, started_at=datetime.now(timezone.utc))
3535
try:
36-
result = task.apply(kwargs=run.args, throw=True)
36+
result = task.apply(kwargs=run.dict_args, throw=True)
3737
except SystemExit as e:
3838
update_run(
3939
run,

0 commit comments

Comments
 (0)