Skip to main content

Background job processing for Plain.

Project description

Worker

Process background jobs with a database-driven worker.

Jobs are defined using the Job base class and the run() method at a minimum.

from plain.worker import Job, register_job
from plain.email import send_mail


@register_job
class WelcomeUserJob(Job):
    def __init__(self, user):
        self.user = user

    def run(self):
        send_mail(
            subject="Welcome!",
            message=f"Hello from Plain, {self.user}",
            from_email="welcome@plainframework.com",
            recipient_list=[self.user.email],
        )

You can then create an instance of the job and call run_in_worker() to enqueue it for a background worker to pick up.

user = User.objects.get(pk=1)
WelcomeUserJob(user).run_in_worker()

Workers are run using the plain worker run command.

Installation

Install plain.worker and add it to your INSTALLED_PACKAGES.

# app/settings.py
INSTALLED_PACKAGES = [
    ...
    "plain.worker",
]

Jobs can be defined in any Python file, but it is suggested to use app/jobs.py or app/{pkg}/jobs.py as those will be imported automatically so the @register_job will fire.

Local development

In development, you will typically want to run the worker alongside your app. With plain.dev you can do this by adding it to the [tool.plain.dev.run] section of your pyproject.toml file. Currently, you will need to use something like watchfiles to add auto-reloading to the worker.

# pyproject.toml
[tool.plain.dev.run]
worker = {cmd = "watchfiles --filter python \"plain worker run --stats-every 0 --max-processes 2\" ."}
worker-slow = {cmd = "watchfiles --filter python \"plain worker run --queue slow --stats-every 0 --max-processes 2\" ."}

Job parameters

TODO

Admin

TODO

Job history

TODO

Scheduled jobs

TODO

Monitoring

TODO

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plain_worker-0.22.3.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plain_worker-0.22.3-py3-none-any.whl (33.7 kB view details)

Uploaded Python 3

File details

Details for the file plain_worker-0.22.3.tar.gz.

File metadata

  • Download URL: plain_worker-0.22.3.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.16

File hashes

Hashes for plain_worker-0.22.3.tar.gz
Algorithm Hash digest
SHA256 cb29c6b017d29f18a1471b26890a0a5fbd67c5215a79c36208fd4bd9a433008a
MD5 061e1153f000c6c4540be78c9050ae0b
BLAKE2b-256 c3d27f58152e08c1df2c0ff768a01ad958f03977a6d06d603832d1da5d394b8c

See more details on using hashes here.

File details

Details for the file plain_worker-0.22.3-py3-none-any.whl.

File metadata

File hashes

Hashes for plain_worker-0.22.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3eeb4a673e0f4e393d52cd9531e68cb1964074be936aa656a3e3f9a0d000ce9c
MD5 8702dc69d91ea203a1a74464b8db931b
BLAKE2b-256 b26e2e7bfc3219ce9f1b3b2ce44abae081004fb659a66f813b5d90f2a20d6177

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page