Ejemplo n.º 1
0
def test_configure_task_schedule_in_and_schedule_at(job_store):
    with pytest.raises(ValueError):
        tasks.configure_task(
            name="my_name",
            job_store=job_store,
            schedule_at=pendulum.datetime(2000, 1, 1, tz="Europe/Paris"),
            schedule_in={"hours": 2},
        )
Ejemplo n.º 2
0
def test_configure_task_schedule_in_and_schedule_at(job_manager):
    with pytest.raises(ValueError):
        tasks.configure_task(
            name="my_name",
            job_manager=job_manager,
            schedule_at=conftest.aware_datetime(2000, 1, 1, tz_offset=1),
            schedule_in={"hours": 2},
        )
Ejemplo n.º 3
0
    def configure_task(self,
                       name: str,
                       *,
                       allow_unknown: bool = True,
                       **kwargs: Any) -> jobs.JobDeferrer:
        """
        Configure a task for deferring, using its name

        Parameters
        ----------
        name : str
            Name of the task. If not explicitly defined, this will be the dotted path
            to the task (``my.module.my_task``)

        **kwargs: Any
            Parameters from `Task.configure`

        Returns
        -------
        ``jobs.JobDeferrer``
            Launch ``.defer(**task_kwargs)`` on this object to defer your job.
        """
        from procrastinate import tasks

        self.perform_import_paths()
        try:
            return self.tasks[name].configure(**kwargs)
        except KeyError as exc:
            if allow_unknown:
                return tasks.configure_task(name=name,
                                            job_manager=self.job_manager,
                                            **kwargs)
            raise exceptions.TaskNotFound from exc
Ejemplo n.º 4
0
def test_configure_task(job_manager):
    job = tasks.configure_task(
        name="my_name", job_manager=job_manager, lock="sher", task_kwargs={"yay": "ho"}
    ).job

    assert job.lock == "sher"
    assert job.task_kwargs == {"yay": "ho"}
Ejemplo n.º 5
0
def test_configure_task_schedule_at(job_store):
    job = tasks.configure_task(
        name="my_name",
        job_store=job_store,
        schedule_at=pendulum.datetime(2000, 1, 1, tz="Europe/Paris"),
    ).job

    assert job.scheduled_at == pendulum.datetime(2000, 1, 1, tz="Europe/Paris")
Ejemplo n.º 6
0
def test_configure_task_schedule_in(job_manager, mocker):
    now = conftest.aware_datetime(2000, 1, 1, tz_offset=1)
    mocker.patch.object(utils, "utcnow", return_value=now)
    job = tasks.configure_task(
        name="my_name", job_manager=job_manager, schedule_in={"hours": 2}
    ).job

    assert job.scheduled_at == conftest.aware_datetime(2000, 1, 1, 2, tz_offset=1)
Ejemplo n.º 7
0
def test_configure_task_schedule_at(job_manager):
    job = tasks.configure_task(
        name="my_name",
        job_manager=job_manager,
        schedule_at=conftest.aware_datetime(2000, 1, 1, tz_offset=1),
    ).job

    assert job.scheduled_at == conftest.aware_datetime(2000, 1, 1, tz_offset=1)
Ejemplo n.º 8
0
def test_configure_task_schedule_in(job_store):
    now = pendulum.datetime(2000, 1, 1, tz="Europe/Paris")
    with pendulum.test(now):
        job = tasks.configure_task(name="my_name",
                                   job_store=job_store,
                                   schedule_in={
                                       "hours": 2
                                   }).job

    assert job.scheduled_at == pendulum.datetime(2000,
                                                 1,
                                                 1,
                                                 2,
                                                 tz="Europe/Paris")
Ejemplo n.º 9
0
    def configure_task(self, name: str, **kwargs: Any) -> jobs.JobDeferrer:
        """
        Configure a task for deferring, using its name

        Parameters
        ----------
        name : str
            Name of the task. If not explicitly defined, this will be the dotted path
            to the task (``my.module.my_task``)

        **kwargs: Any
            Parameters from `Task.configure`

        Returns
        -------
        ``jobs.JobDeferrer``
            Launch ``.defer(**task_kwargs)`` on this object to defer your job.
        """
        from procrastinate import tasks

        return tasks.configure_task(name=name,
                                    job_store=self.job_store,
                                    **kwargs)
Ejemplo n.º 10
0
def test_configure_task_no_lock(job_store):
    job = tasks.configure_task(name="my_name", job_store=job_store).job

    assert uuid.UUID(job.lock)