def test_add_tasks_from(blueprint):
    other = blueprints.Blueprint()

    @blueprint.task(name="foo")
    def my_task():
        return "foo"

    @other.task(name="bar")
    def my_other_task():
        return "bar"

    blueprint.add_tasks_from(other, namespace="ns")

    assert blueprint.tasks == {"foo": my_task, "ns:bar": my_other_task}
    assert my_other_task.name == "ns:bar"
def test_add_tasks_from_clash_other_alias(blueprint):
    other = blueprints.Blueprint()

    @blueprint.task(name="ns:foo")
    def my_task():
        return "foo"

    @other.task(name="bar", aliases=["foo"])
    def my_other_task():
        return "bar"

    with pytest.raises(exceptions.TaskAlreadyRegistered):
        blueprint.add_tasks_from(other, namespace="ns")

    assert blueprint.tasks == {"ns:foo": my_task}
    assert my_other_task.name == "bar"
Beispiel #3
0
from typing import Optional

from procrastinate import blueprints, job_context

builtin = blueprints.Blueprint()


@builtin.task(pass_context=True, queue="builtin")
async def remove_old_jobs(
    context: job_context.JobContext,
    *,
    max_hours: int,
    queue: Optional[str] = None,
    remove_error: Optional[bool] = False,
) -> None:
    """
    This task cleans your database by removing old jobs. Note that jobs and linked
    events will be irreversibly removed from the database when running this task.

    Parameters
    ----------
    max_hours :
        Only jobs which were finished more than ``max_hours`` ago will be deleted.
    queue :
        The name of the queue in which jobs will be deleted. If not specified, the
        task will delete jobs from all queues.
    remove_error :
        By default only successful jobs will be removed. When this parameter is True
        failed jobs will also be deleted.
    """
    assert context.app
Beispiel #4
0
def blueprint():
    return blueprints.Blueprint()