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.
We raise our own exception which hides the real error (often an ImportError),
making it difficult to see what happend. Instead, save the original exception
too.
This change could use far better test coverage, but I'm not sure how to
test it without refactoring more of the code than I think is reasonable
in the scope of this work.
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.
Basically, I don't want to enforce users to configure _any_ logging
stack when writing a basic worker, like this:
from rq import Worker, Queue, Connection
with Connection():
q = Queue()
w = Worker([q])
w.work(burst=True)
In case you want to disable logging altogether, you can configure your
logging stack to do so.
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).