Commit Graph

20 Commits

Author SHA1 Message Date
Vincent Driessen 2982486448 New connection management.
Connections can now be set explicitly on Queues, Workers, and Jobs.
Jobs that are implicitly created by Queue or Worker API calls now
inherit the connection of their creator's.

For all RQ object instances that are created now holds that the
"current" connection is used if none is passed in explicitly.  The
"current" connection is thus hold on to at creation time and won't be
changed for the lifetime of the object.

Effectively, this means that, given a default Redis connection, say you
create a queue Q1, then push another Redis connection onto the
connection stack, then create Q2. In that case, Q1 means a queue on the
first connection and Q2 on the second connection.

This is way more clear than it used to be.

Also, I've removed the `use_redis()` call, which was named ugly.
Instead, some new alternatives for connection management now exist.

You can push/pop connections now:

    >>> my_conn = Redis()
    >>> push_connection(my_conn)
    >>> q = Queue()
    >>> q.connection == my_conn
    True
    >>> pop_connection() == my_conn

Also, you can stack them syntactically:

    >>> conn1 = Redis()
    >>> conn2 = Redis('example.org', 1234)
    >>> with Connection(conn1):
    ...     q = Queue()
    ...     with Connection(conn2):
    ...         q2 = Queue()
    ...     q3 = Queue()
    >>> q.connection == conn1
    True
    >>> q2.connection == conn2
    True
    >>> q3.connection == conn1
    True

Or, if you only require a single connection to Redis (for most uses):

    >>> use_connection(Redis())
2012-03-23 15:10:49 +01:00
Vincent Driessen c684949045 Don't expose the FailedQueue class at the top-level.
This fixes #36.
2012-03-21 15:25:03 +01:00
Vincent Driessen 98ea29b15a Don't expose the Job class at the top-level.
This partially fixes #37.
2012-03-21 15:05:58 +01:00
Vincent Driessen f07d28db86 Organize test fixtures into a separate file. 2012-02-15 21:55:06 +01:00
Vincent Driessen 5717a0ba15 Rename Job.for_call() -> Job.create().
This fixes #34.
2012-02-15 17:01:10 +01:00
Vincent Driessen 7e0b843d06 Implement requeue() method on FailedQueue. 2012-02-15 16:59:27 +01:00
Vincent Driessen 8e85c7eee3 Put Job directly in the top-level `rq` module. 2012-02-15 15:54:02 +01:00
Vincent Driessen 06ce9622ea Add compact() method on Queues, to remove dead messages. 2012-02-14 22:55:51 +01:00
Vincent Driessen 80a615a61c Flake8 style fixes. 2012-02-14 22:55:39 +01:00
Vincent Driessen e4055ca42f Allow queues to be emptied. 2012-02-14 17:53:09 +01:00
Vincent Driessen e05acfedce Fix putting jobs on the failure queue when they fail. 2012-02-10 17:19:30 +01:00
Vincent Driessen 370399f8f7 CHECKPOINT: dequeue_any now returns the queue that was popped from. 2012-02-08 17:55:38 +01:00
Vincent Driessen f516f8df2e CHECKPOINT: Handle failing and unreadable jobs.
Failing (or unreadable) jobs are correctly put on the failure queue by
the worker now.
2012-02-08 15:18:27 +01:00
Vincent Driessen b1650cb9b9 CHECKPOINT: Second part of the big refactoring.
Jobs are now stored in separate keys, and only job IDs are put on Redis
queues.  Much of the code has been hit by this change, but it is for the
good.

No really.
2012-02-08 14:18:17 +01:00
Vincent Driessen 65105b44c3 CHECKPOINT: Initial part of the big refactor. 2012-02-08 00:40:43 +01:00
Vincent Driessen 7fff52d99c Get rid of ugly custom assertion. 2012-02-07 20:59:29 +01:00
Vincent Driessen fcca48a9d7 Rename empty property -> is_empty() method. 2012-02-07 20:53:06 +01:00
Vincent Driessen 7eb8d92605 Put unreadable tasks on the failure queue. 2012-01-30 19:41:13 +01:00
Vincent Driessen 0be1cb6ac0 Change the way jobs are pickled.
There is no job tuple anymore, but instead Jobs are picklable by
themselves natively.  Furthermore, I've added a way to annotate Jobs
with created_at and enqueued_at timestamps, to drive any future Job
performance stats.  (And to enable requeueing, while keeping hold of the
queue that the Job originated from.)

This fixes #17.
2012-01-30 16:52:28 +01:00
Vincent Driessen 1f64157c38 Broke down tests into multiple files. 2012-01-28 07:58:40 +01:00