271 Commits (83fa0adf15daf718fac416214529072ac297293d)

Author SHA1 Message Date
Vincent Driessen 4688498e2d Attach job ID when unpickling fails in .dequeue().
This makes the behaviour consistent with .dequeue_any().
13 years ago
Vincent Driessen 54254f2271 Patch the connection instances.
This patches the connection object (which is either a StrictRedis
instance or a Redis instance), to have alternative class methods that
behave exactly like their StrictRedis counterparts, no matter whether
which type the object is.  Only the ambiguous methods are patched.  The
exhaustive list:

- _zadd          (fixes argument order)
- _lrem          (fixes argument order)
- _setex         (fixes argument order)
- _pipeline      (always returns a StrictPipeline)
- _ttl           (fixes return value)
- _pttl          (fixes return value)

This makes it possible to call the methods reliably without polluting
the RQ code any further.
13 years ago
Yaniv Aknin 74c2351232 Refactor dequeue_any to accept arbitrary timeouts
The 'blocking' parameter was replaced with a 'timeout' parameter.

The timeout parameter is interpreted thus:
    0 - no timeout (block forever, equivalent to blocking=True)
    None - non-blocking (return value or None immediately, equivalent to
                         blocking=False)
    <integer> - maximum seconds to block

Upon timing out, a dequeue operation will raise DequeueTimeout.
13 years ago
Vincent Driessen 90b15fd0b6 Don't silently fail when unpickling.
When a pickled job string can't be unpickled because some required
module isn't loadable, this leads to an `UnpickleError` in the worker
(not in the horse).

Currently we just assume "garbage" in the job's data field, and silently
ignore it.

This is bad.

Really bad.

Because it avoids the normal exception handling mechanism that RQ has.

Historically, this "feature" was introduced to ignore any invalid pickle
data ("bad strings") on queues, and go on. However, we must assume data
inside `job.data` to be valid pickle data.

While an invalid _format_ of pickle data (e.g. the string "blablah"
isn't valid) leads to unpickle errors, unpickling errors will also occur
when the job can't be validly constructed in memory for other reasons,
like being unable to load a specific class.

Django is a good example of this: try submitting jobs that use
`django.conf.settings` while the `DJANGO_SETTINGS_MODULE` env var isn't
set. Currently, RQ workers will drop these jobs and dismiss them like
any non-valid pickle data. You won't be notified.

This patch changes RQ's behaviour to never ignore invalid string data on
any queue and _always_ handle these errors explicitly (but without
bringing the main loop down, of course).
13 years ago
Selwin Ong f498de57b6 Always call job.save even on synchronous queues so get_current_job doesn't fail 13 years ago
Vincent Driessen 8581cd6463 Don't allow jobs without Redis connection.
And other connection-related fixes.
13 years ago
Vincent Driessen 4224304291 I like this implementation of an 'enum' better. 13 years ago
Selwin Ong 442b389b97 Job returning None as result are now persisted correctly.
Job status can now be checked via ``status`` property which should
return either "queued", "finished" or "failed".
13 years ago
Selwin Ong 06d75630e0 Execute job immediately if Queue(async=False) 13 years ago
Selwin Ong a5e6765990 Added "result_ttl" property on jobs that determines how long job results are persisted in Redis. 13 years ago
Vincent Driessen d697ddb93a Resolve connections early.
Fixes #101.
13 years ago
Vincent Driessen abac4a5f41 Since we only have the timeout option, don't be too generic. 13 years ago
Vincent Driessen f6374f2dfa Add new way of invoking .enqueue(), either implicitly or explicitly. 13 years ago
Vincent Driessen e6bb7de8c0 Get rid of the ambiguity when passing the timeout argument to .enqueue() calls. 13 years ago
Vincent Driessen f6e67431d7 Refactor the .enqueue() API to not gobble the timeout kwargs.
This fixes #98.
13 years ago
Vincent Driessen a032896453 Add means of specifying the job function using strings. 13 years ago
Goran Peretin 34d161eb11 requeueing preserves job timeout 13 years ago
Goran Peretin 317a58a3b5 quarantine preserves job timeout 13 years ago
Jonas 415a159ac3 Pass connection explicitly to Job.fetch 13 years ago
Vincent Driessen 697a4a89f8 Actually use any given default_timeout for queues. 13 years ago
Selwin Ong 5989228330 Queue.lpop should take connection as argument. 13 years ago
mattdennewitz 9f2f9e367c Class methods now use given "cls" 13 years ago
Vincent Driessen 4885458dde Move this hack to a separate file. 13 years ago
aiko1895 d26db69cbd added backport of total_ordering to work with 2.6 13 years ago
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())
13 years ago
Vincent Driessen 6bc173f122 Bugfix. 13 years ago
Vincent Driessen c684949045 Don't expose the FailedQueue class at the top-level.
This fixes #36.
13 years ago
Vincent Driessen 8a856e79ea Initial attempt at job timeouts. 14 years ago
Vincent Driessen fb587297f6 Requeue should not error when called on a deleted job ID. 14 years ago
Vincent Driessen 5717a0ba15 Rename Job.for_call() -> Job.create().
This fixes #34.
14 years ago
Vincent Driessen 7e0b843d06 Implement requeue() method on FailedQueue. 14 years ago
Vincent Driessen 240d2d941d Extracted method.
This makes the act of moving failed jobs to the failed queue
responsibility of the FailedQueue itself, not of the Worker.

This fixes #32.
14 years ago
Vincent Driessen d64ad225eb Make FailedQueue a full subclass of Queue.
We will add special methods on it in the future.

This fixes #33.
14 years ago
Vincent Driessen 06ce9622ea Add compact() method on Queues, to remove dead messages. 14 years ago
Vincent Driessen c49e564d3c Don't break the API when jobs get deleted. 14 years ago
Vincent Driessen e4055ca42f Allow queues to be emptied. 14 years ago
Vincent Driessen 0a0d9d1ceb Flake8 style fixes. 14 years ago
Vincent Driessen 1a8b80604d Minor refactoring to make the to-failed queue code a bit more readable. 14 years ago
Vincent Driessen e05acfedce Fix putting jobs on the failure queue when they fail. 14 years ago
Vincent Driessen bffe6cbbde Encapsulate internal function call representation.
This means it's not allowed anymore to directly set func, args, and
kwargs.  Instead, use the for_call() constructor.
14 years ago
Vincent Driessen 370399f8f7 CHECKPOINT: dequeue_any now returns the queue that was popped from. 14 years ago
Vincent Driessen f516f8df2e CHECKPOINT: Handle failing and unreadable jobs.
Failing (or unreadable) jobs are correctly put on the failure queue by
the worker now.
14 years ago
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.
14 years ago
Vincent Driessen 65105b44c3 CHECKPOINT: Initial part of the big refactor. 14 years ago
Vincent Driessen fcca48a9d7 Rename empty property -> is_empty() method. 14 years ago
Vincent Driessen 4d2f64d4b6 Mental note to self. 14 years ago
Vincent Driessen 7eb8d92605 Put unreadable tasks on the failure queue. 14 years ago
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.
14 years ago
Vincent Driessen db5753b0d6 Put Job in its own file. 14 years ago
Vincent Driessen 210477c2ab Throw DequeueError when reading unprocessable data from queue. 14 years ago
Vincent Driessen 62ae299114 Fix mathematical meaning of the < operator.
This is used for alphabetical queue ordering.
14 years ago
Vincent Driessen 8678f26df0 Factor out call string. 14 years ago
Vincent Driessen 2ec12f1775 Fix bugje. 14 years ago
Vincent Driessen 1358246238 Better logging output. 14 years ago
Vincent Driessen cc8f05b3c6 Add __str__ to Job. 14 years ago
Vincent Driessen edcc012b2d Document the Queue class. 14 years ago
Vincent Driessen a905961f94 Add some sample scripts. 14 years ago
Vincent Driessen 0ff2984adf Use __slots__, for minimal memory overhead. 14 years ago
Vincent Driessen b5ea5f32fe Variable renamed. 14 years ago
Vincent Driessen 8852859fc4 Improved the __repr__ and __str__ of Queues. 14 years ago
Vincent Driessen b4c1c85276 Add equality and comparison methods. 14 years ago
Vincent Driessen a5ea45af57 Make the dequeue methods return values consistent.
I merely refactored the internal calls. No external API changes have been made in this commit. In order to make the dequeueing methods consistent, each dequeue method now returns a Job instance, which is just a nice lightweight wrapper around the job tuple.

The Job class makes it easier to pass the method call info around, along with some possible meta information, like the queue the job originated from.

This fixes #7.
14 years ago
Vincent Driessen f492a5ae2b Restructure some code.
No functional change, but leave the BLPOP'ing to the Queue, as the
queues know how to pop themselves.
14 years ago
Vincent Driessen 1c9fa66bc1 Greatly simplify the setup.
Jobs don't even need to be tagged.  Any function can be put on queues.
14 years ago
Vincent Driessen 62b6b180f3 Also allow args and kwargs to enqueue() calls on Queue. 14 years ago
Vincent Driessen 196a9815d2 Add dequeue method to Queue. 14 years ago
Vincent Driessen 407f3e8b38 Add ability to put work on alternate queues. 14 years ago
Vincent Driessen 1b8da4a861 Add test for putting work on queues. 14 years ago
Vincent Driessen d721f0708b Refactor the whole Redis connection stuff to be just as easy as in RDB. 14 years ago
Vincent Driessen 518db8c24b Add better connection management.
To start using RQ, push a Redis connection up its stack, like so:

    from rq import push_connection
    push_connection(Redis())
14 years ago
Vincent Driessen f21b2af2b6 Make it an actual PyPI-managable Python package. 14 years ago