How to use the procrastinate.exceptions.TaskNotFound 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 / unit / test_tasks.py View on Github external
def test_load_task_not_a_task():
    with pytest.raises(exceptions.TaskNotFound):
        tasks.load_task("json.loads")
github peopledoc / procrastinate / tests / unit / test_worker.py View on Github external
        (exceptions.TaskNotFound(), "failed"),
    ],
)
async def test_process_job(
    mocker, test_worker, job_factory, connector, side_effect, status
):
    async def coro(*args, **kwargs):
        pass

    test_worker.run_job = mocker.Mock(side_effect=side_effect or coro)
    job = job_factory(id=1)
    await test_worker.job_store.defer_job_async(job)

    await test_worker.process_job(job=job)

    test_worker.run_job.assert_called_with(
        job=job, worker_id=0,
github peopledoc / procrastinate / tests / unit / test_worker_sync.py View on Github external
def test_worker_load_task_known_missing(test_worker):
    test_worker.known_missing_tasks.add("foobarbaz")
    with pytest.raises(exceptions.TaskNotFound):
        test_worker.load_task("foobarbaz", worker_id=2)
github peopledoc / procrastinate / tests / unit / test_worker.py View on Github external
async def test_run_job_not_found(app):
    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.TaskNotFound):
        await test_worker.run_job(job=job, worker_id=3)
github peopledoc / procrastinate / tests / unit / test_worker_sync.py View on Github external
def test_worker_load_task_new_missing(test_worker):

    with pytest.raises(exceptions.TaskNotFound):
        test_worker.load_task("foobarbaz", worker_id=2)

    assert test_worker.known_missing_tasks == {"foobarbaz"}
github peopledoc / procrastinate / tests / unit / test_tasks.py View on Github external
def test_load_task_not_found():
    with pytest.raises(exceptions.TaskNotFound):
        tasks.load_task("foobarbaz")
github peopledoc / procrastinate / procrastinate / worker.py View on Github external
def load_task(self, task_name: str, worker_id: int) -> tasks.Task:
        if task_name in self.known_missing_tasks:
            raise exceptions.TaskNotFound(f"Cancelling job for {task_name} (not found)")

        try:
            # Simple case: the task is already known
            return self.app.tasks[task_name]
        except KeyError:
            pass

        # Will raise if not found or not a task
        try:
            task = tasks.load_task(task_name)
        except exceptions.ProcrastinateException:
            self.known_missing_tasks.add(task_name)
            raise

        context = self.context_for_worker(worker_id=worker_id)
github peopledoc / procrastinate / procrastinate / tasks.py View on Github external
def load_task(path: str) -> "Task":
    try:
        task = utils.load_from_path(path, Task)
    except exceptions.LoadFromPathError as exc:
        raise exceptions.TaskNotFound(f"Task at {path} cannot be imported: {str(exc)}")

    return task