{"id":20956640,"url":"https://github.com/fastack-dev/fastack-celery","last_synced_at":"2025-05-14T05:32:19.122Z","repository":{"id":42466417,"uuid":"449878055","full_name":"fastack-dev/fastack-celery","owner":"fastack-dev","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-03T16:48:12.000Z","size":70,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-17T13:37:01.144Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fastack-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-19T22:39:32.000Z","updated_at":"2023-01-05T05:56:51.000Z","dependencies_parsed_at":"2023-12-11T17:43:48.101Z","dependency_job_id":"856c971a-1bee-4a54-9066-c7aab88f807d","html_url":"https://github.com/fastack-dev/fastack-celery","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":0.09999999999999998,"last_synced_commit":"9cf3caeff01dbb93b68979b15f9def5a5ae32e48"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastack-dev%2Ffastack-celery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastack-dev%2Ffastack-celery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastack-dev%2Ffastack-celery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastack-dev%2Ffastack-celery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastack-dev","download_url":"https://codeload.github.com/fastack-dev/fastack-celery/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254076977,"owners_count":22010630,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T01:27:14.859Z","updated_at":"2025-05-14T05:32:18.617Z","avatar_url":"https://github.com/fastack-dev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastack-celery\n\nSimple package to integrate celery with fastack.\n\n## To-do\n\nThere are several to-do lists for the future\n\n- [ ] See [#1](https://github.com/fastack-dev/fastack-celery/issues/1)\n\n## Installation\n\n```\npip install fastack-celery\n```\n\n## Usage\n\n### Create celery app\n\nCopy the code below and put it in `app/main.py`:\n\n```py\nfrom fastack_celery import make_celery\ncelery = make_celery(app)\n```\n\nYou can also pass parameters to the celery app.\n\n### Configuration\n\nFor celery configuration, you can create it via `Celery` class in your app settings. For example:\n\n```py\n# app/settings/local.py\nclass Celery:\n    broker_url = \"amqp://strong_user:strong_password@localhost:5672/celery_vhost\"\n    result_backend = \"redis://localhost:6900/0\"\n```\n\nFor other celery configurations, see here https://docs.celeryproject.org/en/stable/userguide/configuration.html#new-lowercase-settings\n\n### Create a task\n\nYou can create tasks using the `shared_task` decorator:\n\n```py\n# app/tasks.py\n\n# Sample task from examples/celery/app/tasks.py\n@shared_task\ndef counter_task(id: int):\n    session = db.open()\n    with session.begin():\n        obj: Counter = session.query(Counter).where(Counter.id == id).first()\n        if obj:\n            print(f\"start counting #{id}\")\n            obj.counter += 1\n            state = obj.state\n            if state is None or state == Counter.State.NOT_IN_QUEUE:\n                obj.state = Counter.State.NOT_IN_QUEUE\n            elif state == Counter.State.TERMINATED:\n                task_id = obj.task_id  # or current_task.request.id\n                celery.control.revoke(task_id, terminate=True)\n                obj.task_id = None\n            else:\n                obj.state = Counter.State.IN_QUEUE\n                counter_task.apply_async(args=(id,), countdown=1, task_id=obj.task_id)\n\n            obj.save(session)\n\n        else:\n            print(f\"Object with id #{id} not found\")\n```\n\nBy default, all tasks must be stored in `app/tasks.py` which will be automatically imported by the `make_celery` function.\n\n### Running celery workers\n\n```\ncd your-project\ncelery -A app.main:celery worker -l info\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastack-dev%2Ffastack-celery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastack-dev%2Ffastack-celery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastack-dev%2Ffastack-celery/lists"}