Skip to content

Commit

Permalink
tasks: use utcnow
Browse files Browse the repository at this point in the history
  • Loading branch information
yashlamba authored and slint committed Dec 10, 2024
1 parent e91c8d4 commit 662e4b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion invenio_jobs/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def create(
task=task,
description=description,
title=title,
**attrs
**attrs,
),
)

Expand Down
10 changes: 5 additions & 5 deletions invenio_jobs/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""Tasks."""

import traceback
from datetime import datetime, timezone
from datetime import datetime

from celery import shared_task
from invenio_db import db
Expand All @@ -32,27 +32,27 @@ def execute_run(self, run_id, kwargs=None):
"""Execute and manage a run state and task."""
run = Run.query.filter_by(id=run_id).one_or_none()
task = current_jobs.registry.get(run.job.task).task
update_run(run, status=RunStatusEnum.RUNNING, started_at=datetime.now(timezone.utc))
update_run(run, status=RunStatusEnum.RUNNING, started_at=datetime.utcnow())
try:
result = task.apply(kwargs=run.args, throw=True)
except SystemExit as e:
update_run(
run,
status=RunStatusEnum.CANCELLED,
finished_at=datetime.now(timezone.utc),
finished_at=datetime.utcnow(),
)
raise e
except Exception as e:
update_run(
run,
status=RunStatusEnum.FAILED,
finished_at=datetime.now(timezone.utc),
finished_at=datetime.utcnow(),
message=f"{e.__class__.__name__}: {str(e)}\n{traceback.format_exc()}",
)
return

update_run(
run,
status=RunStatusEnum.SUCCESS,
finished_at=datetime.now(timezone.utc),
finished_at=datetime.utcnow(),
)

0 comments on commit 662e4b8

Please sign in to comment.