Giter VIP home page Giter VIP logo

pydisque's Introduction

pydisque

Client for Disque, an in-memory, distributed job queue.

Build Status

Documentation

Read The Docs

Usage

Create a new Disque client by passing a list of nodes:

from pydisque.client import Client
client = Client(["127.0.0.1:7711", "127.0.0.1:7712", "127.0.0.1:7713"])
client.connect()

If it can't connect to first node, it will try to connect to second, etc.., if it can't connect to any node, it will raise a redis.exceptions.ConnectionError as you can imagine.

Now you can add jobs:

client.add_job("test_queue", json.dumps(["print", "hello", "world", time.time()]), timeout=100)

It will push the job "print" to the queue "test_queue" with a timeout of 100 ms, and return the id of the job if it was received and replicated in time. If it can't reach the node - maybe it was shutdown etc. - it will retry to connect to another node in given node list, and then send the job. If there is no avail nodes in your node list, it will obviously raise a ConnectionError

Then, your workers will do something like this:

while True:
    jobs = client.get_job(['test_queue'])
    for queue_name, job_id, job in jobs:
        job = json.loads(job)
        print ">>> received job:", job
        client.ack_job(job_id)

also check examples directory.

While waiting jobs your connected node may go down, pydisque will try to connect to next node, so you can restart your nodes without taking down your clients.

Documentation

For now please check docstrings in disque/client.py, implemented commands are

  • info
  • add_job
  • get_job
  • ack_job
  • nack_job
  • fast_ack
  • working
  • qlen
  • qstat
  • qpeek
  • qscan
  • jscan
  • enqueue
  • dequeue
  • del_job
  • show
  • pause
  • hello

Installation

You can install it using pip.

$ pip install pydisque

License

This project is licensed under the terms of the MIT license

Credits

pydisque's People

Contributors

abdul-khalid avatar canardleteer avatar kaspar030 avatar lovelle avatar toolness avatar ybrs avatar ybrsmm avatar zii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pydisque's Issues

Python 3 Support...

I am more then happy to tackle this one myself, but I noticed quite a few hiccups when I was trying to use this with a Python 3.2 project.

Leaving it as an "issue" for now, and I will try to resolve it "the right way," before this module gets too popular :)

Password Authentication using pydisque

It is required at times to keep the disque server password protected. Is there a way or shouldn't there be one to pass password as parameter while listening to the queue through disque client?

A few more bugs with Py3.2...

SUMMARY: Just a warning for other people who may be interested in using this library with Python 3.2!

I found a few more bugs in Python 3.2 execution while writing some new unit tests for new Disque commands.

Mostly, I was brutally sloppy in implementing the 'six' library, but as learning some more complete Py2->Py3 transitional code is something of interest to me, I'm more then happy to take the task upon myself to fix it.

more usable interface

Is there a plan to make a more "humane" interface?

By this, for example, I mean returning a job object from get_job:

jobs = c.get_job(['q'])
job = jobs[0]
print job.payload
job.ack()

Other niceties would be returning a dictionary from qstat. It seems "info" returns a dictionary, but I think the redis library does that.

izip_longest in python3

python3

from pydisque.client import Client
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/pydisque/client.py", line 6, in <module>
    from itertools import izip_longest
ImportError: cannot import name 'izip_longest'

PAUSE needs to be implemented...

If anyone else can get to this before me... Got a lot going on out here.

...

PAUSE option1 [option2 ... optionN]

Control the paused state of a queue, possibly broadcasting the command to other nodes in the cluster. Disque queues can be paused in both directions, input and output, or both. Pausing a queue makes it not available for input or output operations. Specifically:

A queue paused in input will have change behavior in the following way:

ADDJOB returns a -PAUSED error for queues paused in input.
The node where the queue is paused, no longer accept to replicate jobs for this queue when requested by other nodes. Since ADDJOB by default uses synchronous replication, it means that if the queue is paused in enough nodes, adding jobs with a specified level of replication may fail. In general the node where the queue is paused will not create new jobs in the local node about this queue.
The job no longer accepts ENQUEUE messages from other nodes. Those messages are usually used by nodes in out of memory conditions that replicate jobs externally (not holding a copy), in order to put the job in the queue of some random node, among the nodes having a copy of a job.
Active jobs that reach their retry time, are not put back into the queue. Instead their retry timer is updated and the node will try again later.

Basically a queue paused in input never creates new jobs for this queue, and never puts active jobs (jobs for which the node have a copy but are not currently queued) back in the queue, for all the time the queue is paused.

A queue paused in output instead will behave in the following way:

GETJOB will block even if there are jobs available in the specified queue, instead of serving the jobs. But GETJOB will unblock if the queue output pause will be cleared later.
The node will not provide jobs to other nodes in the context of nodes federation, for paused queues.

So a queue paused in output will stop to act as a source of messages for both local and non local clients.

The paused state can be set for each queue using the PAUSE command followed by options to specify how to change the paused state. Possible options are:

in: pause the queue in input.
out: pause the queue in output.
all: pause the queue in input and output (same as specifying both the in and out options).
none: clear the paused state in input and output.
state: just report the current queue state.
bcast: send a PAUSE command to all the reachable nodes of the cluster to set the same queue in the other nodes to the same state.

The command always returns the state of the queue after the execution of the specified options, so the return value is one of in, out, all, none.

Queues paused in input or output are never evicted to reclaim memory, even if they are empty and inactive for a long time, since otherwise the paused state would be forgot.

For example in order to block output for the queue myqueue in all the nodes currently reachable, the following command should be send to a single node:

PAUSE myqueue out bcast

To specify all is the same as to specify both in and out, so the two following forms are equivalent:

PAUSE myqueue in out
PAUSE myqueue all

To just get the current state use:

PAUSE myqueue state
"none"

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.