Giter Site home page Giter Site logo

elric's Introduction

Elric

A Simple Distributed Job Scheduler Based on Redis and Apscheduler.

Features:

  • Master-Slave Architecture
  • Distributed Job Based on Redis
  • Support Cron/Data/Interval/Immediate Job

Usage

Setup environment in settings.py:

DISTRIBUTED_LOCK_CONFIG = {
    'server': {
        'host': 'localhost',
        'port': 6379,
        'password': None,
        'db': 1,
    },
    'resource': 'elric_distributed_lock',
    'retry_count': 5,
    'retry_delay': 0.2,
}

JOB_QUEUE_CONFIG = {
    'server': {
        'host': 'localhost',
        'port': 6379,
        'password': None,
        'db': 1,
    },
    'max_length': 100000,
    'buffer_time': 10
}

FILTER_CONFIG = {
    'server': {
        'host': 'localhost',
        'port': 6379,
        'password': None,
        'db': 0,
    }
}

JOB_STORE_CONFIG = {
    'server': {},
    'maximum_records': 3
}

Create a master instance and start:

rq_master = RQMasterExtend()
rq_master.start()

Implement some jobs/functions:

def test_job(language=None):
    print 'my favorite language is {language}'.format(language=language)

Create a worker instace, specify worker's name and listening keys. Submit job and start worker.

# worker will only receive job from listen_keys that have been provided here
rq_worker = RQWorker(name='test', listen_keys=['job1', ])
# submit job to master
rq_worker.submit_job(test_job, 'job1', kwargs={'language': 'python'})
# start worker, then worker will receive and execute job from master by listening job queue on listen keys you provided
rq_worker.start()

Running the example code

This example illustrates how to submit different type of jobs to master.

Step 1. Setup environment in settings.py

Step 2. Start master

cd example
python test_master.py

Step 3. Start master

python test_worker.py

For more information

Documentation described in this blog post.

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.