diff --git a/PKG-INFO b/PKG-INFO index da68b29..ae0cda2 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,10 +1,10 @@ Metadata-Version: 1.0 Name: swh.scheduler -Version: 0.0.18 +Version: 0.0.19 Summary: Software Heritage Scheduler Home-page: https://forge.softwareheritage.org/diffusion/DSCH/ Author: Software Heritage developers Author-email: swh-devel@inria.fr License: UNKNOWN Description: UNKNOWN Platform: UNKNOWN diff --git a/swh.scheduler.egg-info/PKG-INFO b/swh.scheduler.egg-info/PKG-INFO index da68b29..ae0cda2 100644 --- a/swh.scheduler.egg-info/PKG-INFO +++ b/swh.scheduler.egg-info/PKG-INFO @@ -1,10 +1,10 @@ Metadata-Version: 1.0 Name: swh.scheduler -Version: 0.0.18 +Version: 0.0.19 Summary: Software Heritage Scheduler Home-page: https://forge.softwareheritage.org/diffusion/DSCH/ Author: Software Heritage developers Author-email: swh-devel@inria.fr License: UNKNOWN Description: UNKNOWN Platform: UNKNOWN diff --git a/swh/scheduler/utils.py b/swh/scheduler/utils.py index 7f0be87..d95e0be 100644 --- a/swh/scheduler/utils.py +++ b/swh/scheduler/utils.py @@ -1,22 +1,49 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +import datetime + + def get_task(task_name): """Retrieve task object in our application instance by its fully qualified python name. Args: task_name (str): task's name (e.g swh.loader.git.tasks.LoadDiskGitRepository) Returns: Instance of task """ from swh.scheduler.celery_backend.config import app for module in app.conf.CELERY_IMPORTS: __import__(module) return app.tasks[task_name] + + +def create_oneshot_task_dict(type, *args, **kwargs): + """Create a oneshot task scheduled for as soon as possible. + + Args: + type (str): Type of oneshot task as per swh-scheduler's db + table task_type's column (Ex: origin-update-git, + swh-deposit-archive-checks) + + Returns: + Expected dictionary for the one-shot task scheduling api + (swh.scheduler.backend.create_tasks) + + """ + return { + 'policy': 'oneshot', + 'type': type, + 'next_run': datetime.datetime.now(tz=datetime.timezone.utc), + 'arguments': { + 'args': args if args else [], + 'kwargs': kwargs if kwargs else {}, + } + } diff --git a/version.txt b/version.txt index e74ee9f..fecc3cb 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v0.0.18-0-g723221e \ No newline at end of file +v0.0.19-0-g255d851 \ No newline at end of file