Client-side stubs for celery task execution
Project description
Celery stubs
This is a small library for client side function stubs for celery.
The name stubs
does not refer to the testing aspect but rather to a proxy behavior coming from the stub / skeleton pattern known from remote method invocations. At celery, there is no need to create a skeleton, since this is handled by the middleware.
The stubs approach uses the send_task
to schedule a remote task for execution. Since the stub does not know the arguments to apply, this is the part of the blueprint method.
Example
## Server
@app.task(name="calculate_sum")
def sum(a, b):
return a + b
## Client
# Proxy Definition
class _CalculateSumTask(celery_client_stubs.AsyncRemoteTask):
def __init__(self, celery, *args):
super().__init__("calculate_sum", celery, *args)
def celery_sum(celery, a, b):
return _CalculateSumTask(celery, a, b)
# Definition of methods
app = Celery(...)
...
def sum(a, b):
return celery_sum(app, a, b)
# Usage
async_result = sum(1, 2).schedule_immediately()
# Wait for method to complete ...
Task Factory
The class itself provides an RemoteTaskFactory
, that can be used:
# Definition
class MyRemoteTasks(celery_client_stubs.RemoteTaskFactory):
def sum(self, a, b):
task = celery.AsyncRemoteTask("calculate_sum", self._celery, a, b)
return task
# Usage
app = Celery(...)
tasks = MyRemoteTasks(app)
async_result = tasks.sum(1, 2).schedule_immediately()
Licensing
This library is published under BSD-3-Clause license, just like Celery is.
Versioning
This library follows semantic versioning 2.0. Any breaking change will produce a new major release. Versions below 1.0 are considered to have a unstable interface.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file celery_client_stubs-0.7.0.tar.gz
.
File metadata
- Download URL: celery_client_stubs-0.7.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eebfea265db50ba854169e52c9dab62f9f72f25930655bdea86c24700242ce8 |
|
MD5 | 56a9b78aa6b10158036b25591266eeca |
|
BLAKE2b-256 | 9940856218c6edfbcd4adc92bfaf0cdb9c0d57331cc7586a1fd8ee6b7dad49dc |
File details
Details for the file celery_client_stubs-0.7.0-py3-none-any.whl
.
File metadata
- Download URL: celery_client_stubs-0.7.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 038c75f02b0f98e0ab5c1b21c905c97c05e08024a4e328936a8725c4cdd8cb27 |
|
MD5 | 7f8b9b09e7092c76a0e2f35dd3690eeb |
|
BLAKE2b-256 | 26d88cb83e764286d91d309e57a4c11e7ff77077cb170a56880d2de0448b5048 |