Skip to main content

fastack-celery

Simple package to integrate celery with fastack.

To-do

There are several to-do lists for the future

Installation

pip install fastack-celery

Usage

Create celery app

Copy the code below and put it in app/main.py:

from fastack_celery import make_celery
celery = make_celery(app)

You can also pass parameters to the celery app.

Configuration

For celery configuration, you can create it via Celery class in your app settings. For example:

# app/settings/local.py
class Celery:
    broker_url = "amqp://strong_user:strong_password@localhost:5672/celery_vhost"
    result_backend = "redis://localhost:6900/0"

For other celery configurations, see here https://docs.celeryproject.org/en/stable/userguide/configuration.html#new-lowercase-settings

Create a task

You can create tasks using the shared_task decorator:

# app/tasks.py

# Sample task from examples/celery/app/tasks.py
@shared_task
def counter_task(id: int):
    session = db.open()
    with session.begin():
        obj: Counter = session.query(Counter).where(Counter.id == id).first()
        if obj:
            print(f"start counting #{id}")
            obj.counter += 1
            state = obj.state
            if state is None or state == Counter.State.NOT_IN_QUEUE:
                obj.state = Counter.State.NOT_IN_QUEUE
            elif state == Counter.State.TERMINATED:
                task_id = obj.task_id  # or current_task.request.id
                celery.control.revoke(task_id, terminate=True)
                obj.task_id = None
            else:
                obj.state = Counter.State.IN_QUEUE
                counter_task.apply_async(args=(id,), countdown=1, task_id=obj.task_id)

            obj.save(session)

        else:
            print(f"Object with id #{id} not found")

By default, all tasks must be stored in app/tasks.py which will be automatically imported by the make_celery function.

Running celery workers

cd your-project
celery -A app.main:celery worker -l info

Metadata

Release files for fastack-celery 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastack-celery 0.1.0
File Size Uploaded Provenance Actions
fastack-celery-0.1.0.tar.gz 3.7 kB Without provenance Details for fastack-celery-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastack-celery 0.1.0
File Interpreter ABI Platform Actions
fastack_celery-0.1.0-py3-none-any.whl Python 3 none any Details for fastack_celery-0.1.0-py3-none-any.whl

Total release size: 7.2 kB

Release files / fastack-celery-0.1.0.tar.gz

Download URL fastack-celery-0.1.0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3e2e4e8e5d1d76bded23bea90c86cf0676b0e33cc17708b0f28e2c01d2884b43
BLAKE2b-256 checksum
How to use checksums
6e5e3a178ffe6c0abe69d1fa35ce79f937fbfd11f64f2ecce609f2837a3c8160
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.8.10 Linux/5.11.0-46-generic

Release files / fastack_celery-0.1.0-py3-none-any.whl

Download URL fastack_celery-0.1.0-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5e1962fc29fe99c4e7ff281c40586929e875a24ac9ade3571bd2e714b1deea60
BLAKE2b-256 checksum
How to use checksums
10be970fd9ab645edde8188a237b9e258d94b9fc98fb8f6a3098fd95fe5823c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.8.10 Linux/5.11.0-46-generic

Security for fastack-celery 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page