GithubHelp home page GithubHelp logo

isabella232 / celery_mutex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from paylogic/celery_mutex

0.0 0.0 0.0 81 KB

Mutex for Celery Tasks, based on provided keys.

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

celery_mutex's Introduction

Celey Mutex

Celery Mutex is a mutex for Celery Tasks, optionally refined based on provided keys. This mutex prevents execution of concurrent tasks, as opposed to delaying execution.

Installation

Simply run pip install celery_mutex

Requirements

Celery Mutex relies on ZooKeeper.

Usage

Celery Mutex takes advantage of Abstract Tasks for Celery. To utilize this abstract task, add it as a base for the task:

import celery_mutex

@app.task(base=celery_mutex.MutexTask)
def my_task(a, b):
    return a + b

A new configuration variable is required in order to let Celery Mutex know about your ZooKeeper servers:

ZOOKEEPER_HOSTS = 'localhost:2181'

This is a comma-separated list of hosts to connect to.

By default a mutex times out after one hour. This can be changed globally by setting MUTEX_TIMEOUT or per-task by setting mutex_timeout on the task. For both the value is an integer for the number of seconds to set the time out.

A second configuration option allows you to refine the mutex for a given task. By default, Celery Mutex only allows one instance of a task at a time. However, there may be a need to further refine what is controlled by the mutex. This can be done by setting mutex_keys on the task. The value is a list of keys that are to be used for determining exclusivity.

Using our above example, adding the two optional parameters would yield:

import celery_mutex

@app.task(base=celery_mutex.MutexTask, mutex_timeout=30, mutex_keys=('a',))
def my_task(a, b):
    return a + b

This would cause the mutex to only prevent execution for tasks that share the same value for "a".

celery_mutex's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.