Skip to main content

Cadasta Worker Toolbox

Project description

Build Status Requirements Status

A collection of helpers to assist in quickly building asynchronous workers for the Cadasta system.

Architecture

The Cadasta asynchronous system is designed so that both the scheduled tasks and the task results can be tracked by the central Cadasta Platform. To ensure that this takes place, all Celery workers must be correctly configured to support these features.

Tracking Scheduled Tasks

To keep our system aware of all tasks being scheduled, the Cadasta Platform has a process running to consume task messages off of a task-monitor queue and insert those messages into our database. To support this design, all task producers (including worker nodes) must publish their task messages to both the normal destination queues and the task-monitor queue. This is acheived by registering all queues with a Topic Exchange, setting the task-monitor queue to subscribe to all messages sent to the exchange, and setting standard work queues to subscribe to messages with a matching routing_key. Being that the Cadasta Platform is designed to work with Amazon SQS and the SQS backend only keeps exchange/queue declarations in memory, each message producer must have this set up within their configuration.

Tracking Task Results

TODO

Library

cadasta.workertoolbox.conf.Config

The Config class was built to simplify configuring Celery settings, helping to ensure that all workers adhere to the architecture requirements of the Cadasta asynchronous system. An instance of the Config should come configured with all Celery settings that are required by our system. It is the aim of the class to not require much customization on the part of the developer. However, some customization may be needed when altering configuration between environments (e.g. if dev settings vary greatly from prod settings).

Required Arguments

queues

The only required argument is the queues array. This should contain an array of names for queues that are to be used by the given worker. This includes queues from which the node processes tasks and queues into which the node will schedule tasks. It is not necessary to include the 'celery' or 'platform.fifo' queues, as these will be added automatically. The input of the queues variable will be stored as QUEUES on the Config instance.

Optional Arguments

Any Celery setting may be submitted. It is internal convention that we use the lowercase Celery settings rather than their older upper-case counterparts. This will ensure that they are displayed when calling repr on the Conf instance.

result_backend

TODO

task_queues

TODO

Note: It is recommended that developers not alter this setting.

task_routes

TODO

Note: It is recommended that developers not alter this setting.

Internal Variables

By convention, all variables pertinent to only the Config class (i.e. not used by Celery) should be written entirely uppercase.

RESULT_DB_USER

Variable used to populate the default result_backend template.

RESULT_DB_PASS

Variable used to populate the default result_backend template.

RESULT_DB_HOST

Variable used to populate the default result_backend template.

RESULT_DB_NAME

Variable used to populate the default result_backend template.

PLATFORM_QUEUE_NAME

Defaults to 'platform.fifo'.

Note: It is recommended that developers not alter this setting.

cadasta.workertoolbox.tests.build_functional_tests

When provided with a Celery app instance, this function generates a suite of functional tests to ensure that the provided application’s configuration and functionality conforms with the architecture of the Cadasta asynchronous system.

An example, where an instanciated and configured Celery() app instance exists in a parallel celery module:

from cadasta.workertoolbox.tests import build_functional_tests

from .celery import app

FunctionalTests = build_functional_tests(app)

To run these tests, use your standard test runner (e.g. pytest) or call manually from the command-line:

python -m unittest path/to/tests.py

Development

Testing

pip install -r requirements-test.txt
./runtests

Deploying

pip install -r requirements-deploy.txt
python setup.py clean build publish tag

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cadasta-workertoolbox-0.1.4.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

cadasta_workertoolbox-0.1.4-py2.py3-none-any.whl (11.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file cadasta-workertoolbox-0.1.4.tar.gz.

File metadata

File hashes

Hashes for cadasta-workertoolbox-0.1.4.tar.gz
Algorithm Hash digest
SHA256 3860ddcb517fa4ce7e5a16697efc2a203f1e1cf0d7d8dc4108675147e53c474c
MD5 a1d85b0c98542cd10cf752efcec8bb2f
BLAKE2b-256 d0d23a330da42706ac81f30f6f4c51679e55df9f8212231fb66cbd3649a0d62e

See more details on using hashes here.

File details

Details for the file cadasta_workertoolbox-0.1.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for cadasta_workertoolbox-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ea503c05d4c538fa122204e2e75992087337f89072d97951f3de8a19b5fddc0b
MD5 1fbcfee1e9f8ffc124e5f15142a902c6
BLAKE2b-256 3ce4e3a8f822f0bb6334d31c19660338d05ec5cebc7e7ca7192bfc88cd911955

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page