How to use the procrastinate.jobs function in procrastinate

To help you get started, we’ve selected a few procrastinate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github peopledoc / procrastinate / tests / integration / test_aiopg_connector.py View on Github external
async def test_defer_job(aiopg_job_store, get_all):
    queue = "marsupilami"
    job = jobs.Job(
        id=0, queue=queue, task_name="bob", lock="sher", task_kwargs={"a": 1, "b": 2}
    )
    pk = await aiopg_job_store.defer_job(job=job)

    result = get_all("procrastinate_jobs", "id", "args", "status", "lock", "task_name")
    assert result == [
        {
            "id": pk,
            "args": {"a": 1, "b": 2},
            "status": "todo",
            "lock": "sher",
            "task_name": "bob",
        }
github peopledoc / procrastinate / tests / integration / test_admin.py View on Github external
queueing_lock="queueing_lock2",
        task_name="task_bar",
        task_kwargs={"key": "b"},
    )
    j2 = attr.evolve(j2, id=await pg_job_store.defer_job_async(j2))
    await pg_job_store.finish_job(j2, jobs.Status.FAILED)

    j3 = job_factory(
        queue="q2",
        lock="lock3",
        queueing_lock="queueing_lock3",
        task_name="task_foo",
        task_kwargs={"key": "c"},
    )
    j3 = attr.evolve(j3, id=await pg_job_store.defer_job_async(j3))
    await pg_job_store.finish_job(j3, jobs.Status.SUCCEEDED)

    return [j1, j2, j3]
github peopledoc / procrastinate / tests / unit / test_worker.py View on Github external
async def test_run_job_error(app):
    def job(a, b):  # pylint: disable=unused-argument
        raise ValueError("nope")

    task = tasks.Task(job, app=app, queue="yay", name="job")
    task.func = job

    app.tasks = {"job": task}

    job = jobs.Job(
        id=16,
        task_kwargs={"a": 9, "b": 3},
        lock="sherlock",
        queueing_lock="houba",
        task_name="job",
        queue="yay",
    )
    test_worker = worker.Worker(app, queues=["yay"])
    with pytest.raises(exceptions.JobError):
        await test_worker.run_job(job=job, worker_id=3)
github peopledoc / procrastinate / procrastinate / store.py View on Github external
async def get_stalled_jobs(
        self,
        nb_seconds: int,
        queue: Optional[str] = None,
        task_name: Optional[str] = None,
    ) -> Iterable[jobs.Job]:

        rows = await self.connector.execute_query_all_async(
            query=sql.queries["select_stalled_jobs"],
            nb_seconds=nb_seconds,
            queue=queue,
            task_name=task_name,
        )
        return [jobs.Job.from_row(row) for row in rows]
github peopledoc / procrastinate / procrastinate / healthchecks.py View on Github external
async def get_status_count_async(self) -> Dict[jobs.Status, int]:
        result = await self.connector.execute_query_all_async(
            query=sql.queries["count_jobs_status"],
        )
        result_dict = {r["status"]: int(r["count"]) for r in result}
        return {status: result_dict.get(status.value, 0) for status in jobs.Status}
github peopledoc / procrastinate / procrastinate / store.py View on Github external
async def fetch_job(self, queues: Optional[Iterable[str]]) -> Optional[jobs.Job]:

        row = await self.connector.execute_query_one_async(
            query=sql.queries["fetch_job"], queues=queues
        )

        # fetch_tasks will always return a row, but is there's no relevant
        # value, it will all be None
        if row["id"] is None:
            return None

        return jobs.Job.from_row(row)
github peopledoc / procrastinate / procrastinate / app.py View on Github external
def task(
        self,
        _func: Optional[Callable] = None,
        *,
        queue: str = jobs.DEFAULT_QUEUE,
        name: Optional[str] = None,
        retry: retry_module.RetryValue = False,
        pass_context: bool = False,
    ) -> Any:
        """
        Declare a function as a task. This method is meant to be used as a decorator::

            @app.task(...)
            def my_task(args):
                ...

        or::

            @app.task
            def my_task(args):
                ...