Giter Site home page Giter Site logo

django-robust's Introduction

django-robust Build Status Coverage Status PyPI Version

install

$ pip install django-robust
INSTALLED_APPS = [
    'robust.apps.RobustConfig',
]
DB = {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
}
DATABASES = {
    'default': DB,
    'robust_ratelimit': DB, # <- same db
}

define tasks

from robust import task

@task()
def heavy_stuff(foo):
    pass

@task(tags=['service1'])
def talk_to_external_service():
    pass

@task(bind=True, retries=3)
def retry_me(self):
    self.retry()

schedule tasks

from .tasks import heavy_stuff

heavy_stuff.delay(foo='bar')

execute tasks

$ ./manage.py robust_worker

run scheduler

standalone

$ ./manage.py robust_beat

embedded

$ ./manage.py robust_worker --beat

cleanup

for cleanup completed tasks add robust.utils.cleanup to robust schedule.

settings

ROBUST_RATE_LIMIT = {
    'service1': (1, timedelta(seconds=10)),  # 1/10s,
    'bar':      (20, timedelta(minutes=1)),  # 20/m
}

ROBUST_SCHEDULE = [
    (timedelta(seconds=1), 'foo.tasks.every_second'),
    (timedelta(minutes=5), 'foo.tasks.every_5_minutes'),
]

ROBUST_LOG_EVENTS = True  # log all task state changes

ROBUST_WORKER_FAILURE_TIMEOUT = 5  # wait 5 seconds when worker faces unexpected errors

ROBUST_NOTIFY_TIMEOUT = 10  # listen to postgres notify for 10 seconds, then poll database

ROBUST_ALWAYS_EAGER = False  # if this is True, tasks will be executed locally instead of being sent to the queue

ROBUST_PAYLOAD_PROCESSOR = 'robust.utils.PayloadProcessor'

ROBUST_SUCCEED_TASK_EXPIRE = datetime.timedelta(hours=1) # succeed tasks cleanup period. Default: 1 hour ago

ROBUST_FAILED_TASK_EXPIRE = datetime.timedelta(weeks=1) # failed tasks cleanup period. Default: 1 week ago

django-robust's People

Contributors

barbuza avatar kidig avatar

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.