This release is a pre-release and may not be stable for production use.
Django Universal Worker Service
Django implementation of the IVOA UWS pattern.
The Universal Worker Service (UWS) pattern defines how to manage asynchronous execution of jobs on a service. Any application of the pattern defines a family of related services with a common service contract. Possible uses of the pattern are also described.
Url: https://www.ivoa.net/documents/UWS/ DOI: 10.5479/ADS/bib/2016ivoa.spec.1024H
Installation
Django UWS is available via Pypi:
pip install django-uws
Django Quick start
- add
uwsto yourINSTALLED_APPSsetting likes this:
INSTALLED_APPS = [
...
'uws',
...
]
Additionally you may want to set the following settings:
CELERY_TIMEZONE = "Europe/Amsterdam"
CELERY_USE_UTC = True
# Recommended to use an environment variable to set the broker URL.
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", "amqp://guest@localhost:5672")
- Include the uws URLconf in your project urls.py like this:
...
path('uws/', include('uws.urls')), # 'uws/' can be replaced by the name of your service if necessary.
...
- Run
python manage.py migrate uwsto create the UWS models. Optionally:python manage.py migrate uws --database uwsby specifying
DATABASE_ROUTERS = [
...
"uws.database_router.UWSDatabaseRouter",
...
]
and a `uws` entry in your `DATABASES` setting
- Add Celery configuration
Create a
celery.pyfile in the Django<project>folder (next tosettings.py,wsgi.pyetc.) with the following content:
import os
from celery import Celery
# Set the default Django settings module for the 'celery' program.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.default_settings")
app = Celery("project") # Change to something related to your Service
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()
Worker configuration
The worker configuration still uses a Django project layout and can be merged with an existing Django application serving the API or as a standalone worker instance. Setting it up is similar to the steps for the api:
-
Create a
workers(or similarly named) directory to store the code for your workers -
Create worker files. An example would be:
from uws.classes import UWSJob
from uws.client import Client
from uws.workers import Worker
class Echo(Worker):
"""A worker echoing all parameters"""
def __init__(self):
self._type = "echo"
def run(self, job: UWSJob, job_token: str, client: Client) -> None:
data = [{"key": p.key, "value": p.value} for p in job.parameters]
client.add_results(job.jobId, data, job_token)
- Set the following Django settings (if not already present):
CELERY_TIMEZONE = "Europe/Amsterdam"
CELERY_USE_UTC = True
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", "amqp://guest@localhost:5672")
# Classes of available workers
UWS_WORKERS = ["workers.echo.Echo"]
# Web path to UWS api, recommended to use an environment variable
UWS_HOST = os.getenv("UWS_HOST", "https://example.com/uws/")
Contributing
For developer access to this repository, please send a message on the ESAP channel on Rocket Chat.
License
This project is licensed under the Apache License version 2.0.
Metadata
Release files for django-uws 0.2.dev370864
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 |
|---|---|---|---|---|
| django-uws-0.2.dev370864.tar.gz | 16.1 kB | Without provenance | Details for django-uws-0.2.dev370864.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_uws-0.2.dev370864-py3-none-any.whl | Python 3 | none | any | Details for django_uws-0.2.dev370864-py3-none-any.whl |
Total release size: 35.8 kB
Release files / django-uws-0.2.dev370864.tar.gz
| Download URL | django-uws-0.2.dev370864.tar.gz |
|---|---|
| Size | 16.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1913143b5463294615e3e1804fdc7c44d2e230eeab6c95f06f680d0f784f4d7d
|
|
BLAKE2b-256 checksum How to use checksums |
a662d0c405c8f5719bc88d60983a487973d714634f674094696e7737f8892277
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.6
|
Release files / django_uws-0.2.dev370864-py3-none-any.whl
| Download URL | django_uws-0.2.dev370864-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f00d6f36c63acb8fef7ea0473f668f1925b3c964089b6791637be2f83edcc15
|
|
BLAKE2b-256 checksum How to use checksums |
a4b9d79034515ea0f432a31e58307cc643dff3dfadddf260a28a28dc55b51538
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.6
|
Security for django-uws 0.2.dev370864
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.