barn-py
Lightweight scheduler and worker for Django using a database as backend.
The task worker and scheduler use the database as a queue to store and find tasks to process
and you can forget about using transaction.on_commit.
If you need a billion messages per second, please leave.
Examples
Use generic models
from django.http import HttpRequest, HttpResponse
from django.db import transaction
from barn.decorators import task
@transaction.atomic
def index(request: HttpRequest) -> HttpResponse:
html = "<html><body>Hello</body></html>"
# do something with database
dummy.delay(view="index", code="12")
return HttpResponse(html)
@task
def dummy(view: str, code: str) -> str:
# task called inside transaction
return "ok"
Use your models (prefered)
You can specify your own model for schedule and task and this approach is preferred.
from django.db import models
from django.core.mail import send_mail
from barn.models import AbstractTask
class EndOfTrialPeriodTask(AbstractTask):
user = models.ForeignKey('auth.User', models.CASCADE)
def process(self) -> None:
# go somewhere and do something...
self.user.is_active = False
self.user.save()
NotifyEndOfTrialPeriodTask.objects.create(user_id=self.user_id)
class NotifyEndOfTrialPeriodTask(AbstractTask):
user = models.ForeignKey('auth.User', models.CASCADE)
def process(self) -> None:
if self.user.email:
send_mail(
"End of trial period",
f"Hello {self.user.get_full_name()}. Your trial period has ended.",
"from@example.com",
[self.user.email],
fail_silently=False,
)
class EndOfSubscriptionTask(AbstractTask):
user = models.ForeignKey('auth.User', models.CASCADE)
def process(self) -> None:
# go somewhere and do something...
Metadata
Release files for task-barn 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| task_barn-0.2.0.tar.gz | 19.2 kB | Without provenance | Details for task_barn-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| task_barn-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for task_barn-0.2.0-py3-none-any.whl |
Total release size: 32.8 kB
Release files / task_barn-0.2.0.tar.gz
| Download URL | task_barn-0.2.0.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
06f6091aa61470bc17c9468c973767c883a21eb6e78091d3bd59221da8cdbc9a
|
|
BLAKE2b-256 checksum How to use checksums |
568fd96815ee18e284045d147cb1747b9f95dcb758db9e6d5718de8ddc41fcb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / task_barn-0.2.0-py3-none-any.whl
| Download URL | task_barn-0.2.0-py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fe771871b637cd15740de75fc7431fea063ebcf20ecc237fee3974f369808c73
|
|
BLAKE2b-256 checksum How to use checksums |
77c3025a97c2161e50c2443e2dbd3d1d5b7bbf4303e50c8e9d94c5c90345876b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Security for task-barn 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.