How to use the procrastinate.App 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 / acceptance / app.py View on Github external
if "p1" in dct:
        dct["p1"] = Param(dct["p1"])
    if "p2" in dct:
        dct["p2"] = Param(dct["p2"])
    return dct


json_dumps = functools.partial(json.dumps, default=encode)
json_loads = functools.partial(json.loads, object_hook=decode)

app = procrastinate.App(
    connector=procrastinate.AiopgConnector(json_dumps=json_dumps, json_loads=json_loads)
)
app.open()

sync_app = procrastinate.App(
    connector=procrastinate.Psycopg2Connector(
        json_dumps=json_dumps, json_loads=json_loads
    )
)
sync_app.open()


@app.task(queue="default")
def sum_task(a, b):
    print(a + b)


@app.task(queue="default")
def sum_task_param(p1: Param, p2: Param):
    if not isinstance(p1, Param):
        raise Exception("wrong type for p1")
github peopledoc / procrastinate / tests / acceptance / test_async.py View on Github external
def pg_app(aiopg_connector):
    return procrastinate.App(connector=aiopg_connector)
github peopledoc / procrastinate / tests / acceptance / app.py View on Github external
return obj.p
    raise TypeError()


def decode(dct):
    if "p1" in dct:
        dct["p1"] = Param(dct["p1"])
    if "p2" in dct:
        dct["p2"] = Param(dct["p2"])
    return dct


json_dumps = functools.partial(json.dumps, default=encode)
json_loads = functools.partial(json.loads, object_hook=decode)

app = procrastinate.App(
    connector=procrastinate.AiopgConnector(json_dumps=json_dumps, json_loads=json_loads)
)
app.open()

sync_app = procrastinate.App(
    connector=procrastinate.Psycopg2Connector(
        json_dumps=json_dumps, json_loads=json_loads
    )
)
sync_app.open()


@app.task(queue="default")
def sum_task(a, b):
    print(a + b)
github peopledoc / procrastinate / procrastinate / cli.py View on Github external
def cli(ctx: click.Context, app: str, **kwargs) -> None:
    """
    Interact with a Procrastinate app. See subcommands for details.

    All arguments can be passed by environment variables: PROCRASTINATE_UPPERCASE_NAME
    or PROCRASTINATE_COMMAND_UPPERCASE_NAME (examples: PROCRASTINATE_APP,
    PROCRASTINATE_DEFER_UNKNOWN, ...).
    """
    if app:
        app_obj = procrastinate.App.from_path(dotted_path=app)
    else:
        # If we don't provide an app, initialize a default one that will fail if it
        # needs a connector.
        app_obj = procrastinate.App(connector=MissingAppConnector())
    app_obj.open()
    ctx.obj = app_obj

    worker_defaults = app_obj.worker_defaults.copy()
    worker_defaults["queues"] = ",".join(worker_defaults.get("queues") or [])
    ctx.default_map = {"worker": worker_defaults}
github peopledoc / procrastinate / procrastinate / cli.py View on Github external
def cli(ctx: click.Context, app: str, **kwargs) -> None:
    """
    Interact with a Procrastinate app. See subcommands for details.

    All arguments can be passed by environment variables: PROCRASTINATE_UPPERCASE_NAME
    or PROCRASTINATE_COMMAND_UPPERCASE_NAME (examples: PROCRASTINATE_APP,
    PROCRASTINATE_DEFER_UNKNOWN, ...).
    """
    if app:
        app_obj = procrastinate.App.from_path(dotted_path=app)
    else:
        # If we don't provide an app, initialize a default one that will fail if it
        # needs a connector.
        app_obj = procrastinate.App(connector=MissingAppConnector())
    app_obj.open()
    ctx.obj = app_obj

    worker_defaults = app_obj.worker_defaults.copy()
    worker_defaults["queues"] = ",".join(worker_defaults.get("queues") or [])
    ctx.default_map = {"worker": worker_defaults}
github peopledoc / procrastinate / procrastinate_demo / app.py View on Github external
import procrastinate

import_paths = ["procrastinate_demo.tasks"]

connector_class = procrastinate.AiopgConnector
# connector_class = procrastinate.Psycopg2Connector

app = procrastinate.App(
    connector=connector_class(),
    import_paths=import_paths,
    worker_defaults={"listen_notify": False},
)