def worker(app: procrastinate.App, queue: Iterable[str]): """ Launch a worker, listening on the given queues (or all queues). """ queues = list(queue) or None queue_names = ", ".join(queues) if queues else "all queues" click.echo(f"Launching a worker on {queue_names}") app.run_worker(queues=queues) # type: ignore
def worker_(app: procrastinate.App, queues: str, **kwargs): """ Launch a worker, listening on the given queues (or all queues). Values default to App.worker_defaults and then App.run_worker() defaults values. """ queue_list = [q.strip() for q in queues.split(",")] if queues else None if queue_list is None: queue_names = "all queues" else: queue_names = ", ".join(queue_list) click.echo(f"Launching a worker on {queue_names}") app.run_worker(queues=queue_list, **kwargs) # type: ignore
def configure_job( app: procrastinate.App, task_name: str, configure_kwargs: Dict[str, Any], unknown: bool, ) -> jobs.JobDeferrer: app.perform_import_paths() try: return app.tasks[task_name].configure(**configure_kwargs) except KeyError: if unknown: return app.configure_task(name=task_name, **configure_kwargs) else: raise click.BadArgumentUsage(f"Task {task_name} not found.")
async def test_wait_for_jobs_stop_from_signal(pg_job_store, kill_own_pid): """ Testing than ctrl+c interrupts the wait """ pg_job_store.socket_timeout = 2 app = App(job_store=pg_job_store) async def stop(): await asyncio.sleep(0.5) kill_own_pid() before = time.perf_counter() await asyncio.gather(app.run_worker_async(), stop()) after = time.perf_counter() # If we wait less than 1 sec, it means the wait didn't reach the timeout. assert after - before < 1
def configure_task( app: procrastinate.App, task_name: str, configure_kwargs: Dict[str, Any], allow_unknown: bool, ) -> jobs.JobDeferrer: return app.configure_task(name=task_name, allow_unknown=allow_unknown, **configure_kwargs)
def healthchecks(app: procrastinate.App): """ Check the state of procrastinate. """ db_ok = app.check_connection() # type: ignore # If app or DB is not configured correctly, we raise before this point click.echo("App configuration: OK") click.echo("DB connection: OK") if not db_ok: raise click.ClickException( "Connection to the database works but the procrastinate_jobs table was not " "found. Have you applied database migrations (see " "`procrastinate schema -h`)?") click.echo("Found procrastinate_jobs table: OK")
def close_connection(procrastinate_app: procrastinate.App, *args, **kwargs): # There's an internal click param named app, we can't name our variable "app" too. procrastinate_app.close_connection() # type: ignore
from procrastinate import AiopgConnector, App from .settings import settings queue = App(connector=AiopgConnector( dsn=settings.POSTGRES_DSN, options=f"-c search_path={settings.QUEUE_SCHEMA}", ), )