Example #1
0
    def __init__(
        self,
        *,
        connector: connector_module.BaseConnector,
        import_paths: Optional[Iterable[str]] = None,
        worker_defaults: Optional[Dict] = None,
        periodic_defaults: Optional[Dict] = None,
    ):
        """
        Parameters
        ----------
        connector :
            Typically an `AiopgConnector`. It will be responsible for all communications
            with the database. Mandatory.
        import_paths :
            List of python dotted paths of modules to import, to make sure
            that the workers know about all possible tasks.
            If you fail to add a path here and a worker encounters
            a task defined at that path, the task will be loaded on the
            fly and run, but you will get a warning.
            You don't need to specify paths that you know have already
            been imported, though it doesn't hurt.
            A `App.task` that has a custom "name" parameter, that is not
            imported and whose module path is not in this list will
            fail to run.
        worker_defaults :
            All the values passed here will override the default values sent when
            launching a worker. See `App.run_worker` for details.
        periodic_defaults :
            Parameters for fine tuning the periodic tasks deferrer. Available
            parameters are:

            - ``max_delay``: ``float``, in seconds. When a worker starts and there's
              a periodic task that has not been deferred, the worker will defer the task
              if it's been due for less that this amount of time. This avoids new
              periodic tasks to be immediately deferred just after their first
              deployment. (defaults to 10 minutes)
        """
        from procrastinate import periodic

        self.connector = connector
        self.tasks: Dict[str, "tasks.Task"] = {}
        self.builtin_tasks: Dict[str, "tasks.Task"] = {}
        self.queues: Set[str] = set()
        self.import_paths = import_paths or []
        self.worker_defaults = worker_defaults or {}
        periodic_defaults = periodic_defaults or {}

        self.job_manager = manager.JobManager(connector=self.connector)
        self.periodic_deferrer = periodic.PeriodicDeferrer(
            job_manager=self.job_manager, **periodic_defaults)

        self._register_builtin_tasks()
Example #2
0
    def __init__(
        self,
        *,
        connector: connector_module.BaseConnector,
        import_paths: Optional[Iterable[str]] = None,
        worker_defaults: Optional[Dict] = None,
        periodic_defaults: Optional[Dict] = None,
    ):
        """
        Parameters
        ----------
        connector :
            Typically an `AiopgConnector`. It will be responsible for all communications
            with the database. Mandatory.
        import_paths :
            List of python dotted paths of modules to import, to make sure that
            the workers know about all possible tasks. If there are tasks in a
            module that is neither imported as a side effect of importing the
            App, nor specified in this list, and a worker encounters a task
            defined in that module, the task will fail (`TaskNotFound`). While
            it is not mandatory to specify paths to modules that you know have
            already been imported, it's a good idea to do so.
        worker_defaults :
            All the values passed here will override the default values sent when
            launching a worker. See `App.run_worker` for details.
        periodic_defaults :
            Parameters for fine tuning the periodic tasks deferrer. Available
            parameters are:

            - ``max_delay``: ``float``, in seconds. When a worker starts and there's
              a periodic task that has not been deferred, the worker will defer the task
              if it's been due for less that this amount of time. This avoids new
              periodic tasks to be immediately deferred just after their first
              deployment. (defaults to 10 minutes)
        """
        from procrastinate import periodic

        super().__init__()

        self.connector = connector
        self.import_paths = import_paths or []
        self.worker_defaults = worker_defaults or {}
        periodic_defaults = periodic_defaults or {}

        self.job_manager = manager.JobManager(connector=self.connector)
        self.periodic_deferrer = periodic.PeriodicDeferrer(**periodic_defaults)

        self._register_builtin_tasks()
Example #3
0
def periodic_deferrer():
    return periodic.PeriodicDeferrer()
Example #4
0
def deferrer(job_store):
    return periodic.PeriodicDeferrer(job_store=job_store)
Example #5
0
def periodic_deferrer(job_manager):
    return periodic.PeriodicDeferrer(job_manager=job_manager)