271 Commits (83fa0adf15daf718fac416214529072ac297293d)

Author SHA1 Message Date
Thomas Matecki ee215a1853 Create get_dependencies_statuses method on Job
This method shall be used in Queue#enqueue_dependendents to determine if all of a dependents' dependencies have been _FINISHED_.
5 years ago
Babatunde Olusola e1cbc3736c
Implement Customizable Serializer Support (#1219)
* Implement Customizable Serializer Support

* Refractor serializer instance methods

* Update tests with other serializers

* Edit function description

* Edit function description

* Raise appropriate exception

* Update tests for better code coverage

* Remove un-used imports and un-necessary code

* Refractor resolve_serializer

* Remove un-necessary alias from imports

* Add documentation

* Refractor tests, improve documentation
5 years ago
Selwin Ong d8bd455c12
enqueue_at should support explicit args and kwargs (#1211) 5 years ago
Ivan Kiryanov ed67de22c6 Add job status setting in enqueue_at (and in enqueue_in) methods (#1181)
* Add job status setting in enqueue_at (and in enqueue_in) methods

Update tests for this change
Closes: #1179

* Add status param to create_job func, rework enqueue_at status setting
6 years ago
Selwin Ong baa0cc268a
Job scheduling (#1163)
* First RQScheduler prototype

* WIP job scheduling

* Fixed Python 2.7 tests

* Added ScheduledJobRegistry.get_scheduled_time(job)

* WIP on scheduler's threading mechanism

* Fixed test errors

* Changed scheduler.acquire_locks() to instance method

* Added scheduler.prepare_registries()

* Somewhat working implementation of RQ scheduler

* Only call stop_scheduler if there's a scheduler present

* Use OSError rather than ProcessLookupError for PyPy compatibility

* Added `auto_start` argument to scheduler.acquire_locks()

* Make RQScheduler play better with timezone

* Fixed test error

* Added --with-scheduler flag to rq worker CLI

* Fix tests on Python 2.x

* More Python 2 fixes

* Only call `scheduler.start` if worker is run in non burst mode

* Fixed an issue where running worker with scheduler would fail sometimes

* Make `worker.stop_scheduler()` more resilient to errors

* worker.dequeue_job_and_maintain_ttl() should also periodically run maintenance tasks

* Scheduler can now work with worker in both burst and non burst mode

* Fixed scheduler logging message

* Always log scheduler errors when running

* Improve scheduler error logging message

* Removed testing code

* Scheduler should periodically try to acquire locks for other queues it doesn't have

* Added tests for scheduler.should_reacquire_locks

* Added queue.enqueue_in()

* Fixes queue.enqueue_in() in Python 2.7

* First stab at documenting job scheduling

* Remove unused methods

* Remove Python 2.6 logging compatibility code

* Remove more unused imports

* Added convenience methods to access job registries from queue

* Added test for worker.run_maintenance_tasks()

* Simplify worker.queue_names() and worker.queue_keys()

* Updated changelog to mention RQ's new job scheduling mechanism.
6 years ago
Thomas Matecki 80c82f731f Multi Dependency Support - Registration & Enqueue Call (#1155)
* Multi Dependency Support - Registration & Enqueue Call

Internal API changes to support multiple dependencies.
* Store all of a job's _dependencies_ in a redis set. Delete that set when a job is deleted.
* Add Job#fetch_dependencies method - which return all jobs a job is dependent upon and optionally _WATCHES_ all dependency ids.
* Use Job#fetch_dependencies in Queue#call_enqueue. `fetch_dependencies` now sets WATCH and raises InvalidJobDependency, rather than call_enqueue.

`Queue` and `Job` public APIs still expect single ids of jobs for `depends_on` but internally register them in a way that could support multiple jobs being passed as dependencies.

Next up: need to update Queue#enqueue_dependents

* Use existing fetch_many method to get dependencies.

Modify fetch_dependencies to use fetch_many.

* Remove default value for fetch_many's connection parameter

* PR review housekeeping

* Remove a duplicate test
* Oneline something
* Fix missing colon in dependencies key
* Delete job key, dependents and dependencies at once

* More Fixes From Code Review

Updates to Job, Queue and associated tests.

* When Checking dependencies Avoid, trip to Redis

* When checking the status of a job, we have a 'clean' status of all dependencies(returned from Job#fetch_dependencies) and the job keys are WATCHed, so there's no reason to go back to Redis to get the status _again_.
* Looks as though, the `_status` set in `Job#restore` was bytes while it was converted to text(`as_text`) in `Job#get_status` - for consistency(and tests) converting to text in `restore` as well.
* In `Queue#enqueue_call`, moved WATCH of dependencies_key to before fetching dependencies. This doesn't really matter but seems more _correct_ - one can imagine some rogue API adding a dependency after they've been fetched but before they've been WATCHEed.

* Update Job#get_status to get _local_ status

* If refresh=False is passed, don't get status from Redis; return the value of _status. This is to avoid a trip to Redis if the caller can guarantee that the value of `_status` is _clean_.

* More Fixups

* Expire dependency keys in Job#cleanup
* Consistency in Job#fetch_dependencies
6 years ago
Ivan Piskunov cfc02816ea Fix dependent jobs enqueueing (#1145)
If Queue was subclassed and enqueue_job changed, these changes should affect on dependent jobs' enqueueing too.
6 years ago
Selwin Ong b14c4e288d
Added checks for 0 ttl (#1110) 6 years ago
Selwin Ong c4cbb3af2f
RQ v1.0! (#1059)
* Added FailedJobRegistry.

* Added job.failure_ttl.

* queue.enqueue() now supports failure_ttl

* Added registry.get_queue().

* FailedJobRegistry.add() now assigns DEFAULT_FAILURE_TTL.

* StartedJobRegistry.cleanup() now moves expired jobs to FailedJobRegistry.

* Failed jobs are now added to FailedJobRegistry.

* Added FailedJobRegistry.requeue()

* Document the new `FailedJobRegistry` and changes in custom exception handler behavior.

* Added worker.disable_default_exception_handler.

* Document --disable-default-exception-handler option.

* Deleted worker.failed_queue.

* Deleted "move_to_failed_queue" exception handler.

* StartedJobRegistry should no longer move jobs to FailedQueue.

* Deleted requeue_job

* Fixed test error.

* Make requeue cli command work with FailedJobRegistry

* Added .pytest_cache to gitignore.

* Custom exception handlers are no longer run in reverse

* Restored requeue_job function

* Removed get_failed_queue

* Deleted FailedQueue

* Updated changelog.

* Document `failure_ttl`

* Updated docs.

* Remove job.status

* Fixed typo in test_registry.py

* Replaced _pipeline() with pipeline()

* FailedJobRegistry no longer fails on redis-py>=3

* Fixes test_clean_registries

* Worker names are now randomized

* Added a note about random worker names in CHANGES.md

* Worker will now stop working when encountering an unhandled exception.

* Worker should reraise SystemExit on cold shutdowns

* Added anchor.js to docs

* Support for Sentry-SDK (#1045)

* Updated RQ to support sentry-sdk

* Document Sentry integration

* Install sentry-sdk before running tests

* Improved rq info CLI command to be more efficient when displaying lar… (#1046)

* Improved rq info CLI command to be more efficient when displaying large number of workers

* Fixed an rq info --by-queue bug

* Fixed worker.total_working_time bug (#1047)

* queue.enqueue() no longer accepts `timeout` argument (#1055)

* Clean worker registry (#1056)

* queue.enqueue() no longer accepts `timeout` argument

* Added clean_worker_registry()

* Show worker hostname and PID on cli (#1058)

* Show worker hostname and PID on cli

* Improve test coverage

* Remove Redis version check when SSL is used

* Bump version to 1.0

* Removed pytest_cache/README.md

* Changed worker logging to use exc_info=True

* Removed unused queue.dequeue()

* Fixed typo in CHANGES.md

* setup_loghandlers() should always call logger.setLevel() if specified
6 years ago
Wolfgang Langner abf6881114 Fix #1040 queue default timeout bug. (#1042)
Add test for queue default_timeout.
6 years ago
Darshan Rai ada2ad03ca modify zadd calls for redis-py 3.0 (#1016)
* modify zadd calls for redis-py 3.0

redis-py 3.0 changes the zadd interface that accepts a single
mapping argument that is expected to be a dict.
https://github.com/andymccurdy/redis-py#mset-msetnx-and-zadd

* change FailedQueue.push_job_id to always push a str

redis-py 3.0 does not attempt to cast values to str and is left
to the user.

* remove Redis connection patching

Since in redis-py 3.0, Redis == StrictRedis class, we no longer
need to patch _zadd and other methods.
Ref: https://github.com/rq/rq/pull/1016#issuecomment-441010847
7 years ago
Selwin Ong 6559b0ffd7
Replace "timeout" argument in queue.enqueue() with "job_timeout" (#1010) 7 years ago
Paul Robertson e86fb57366 add is_async property to queue (#982) 7 years ago
chevell c2b939d2df Replace 'async' keyword with 'is_async' for Queue objects (#977)
* Replaced async keyword with is_async in the Queue class to fix reserved keyword syntax errors in Python 3.7

* Updated tests to use is_async keyword when instantiating Queue objects

* Updated docs to reference is_async keyword for Queue objects

* Updated tox.ini, setup.py and .travis.yml with references to Python 3.7
7 years ago
stj 487ef72f21 Define redis key prefix as class variable (#939)
* Define redis key prefix as class variable

Some prefixes were hardcoded in several places. This made it hard to
use custom prefixes via subclasses.

Resolves #920

* fixup! Define redis key prefix as class variable
7 years ago
Selwin Ong 1d7b5e834b
Worker statistics (#897)
* First stab at implementing worker statistics.

* Moved worker data restoration logic to worker.refresh().

* Failed and successfull job counts are now properly incremented.

* Worker now keeps track of total_working_time

* Ensure job.ended_at is set in the case of unhandled job failure.

* handle_job_failure shouldn't crash if job.started_at is not present.
8 years ago
Selwin Ong 92c88d3f4d Merge pull request #878 from theodesp/Issue-731
Fixed #731 - Support for deleting Queues
8 years ago
Theo c095fe1825 Fixed #731 - Code review issues. Added delete_jobs parameter and pipelining. 8 years ago
Theo 160fe99323 Fixed #731 - Support for deleting Queues 8 years ago
Theo 096c5ad3c2 Fixed #866 - Flak8 errors 8 years ago
Selwin Ong 801b3b7293 Added non zero check for Queue class. 8 years ago
Selwin Ong 5f5e113790 Merge pull request #831 from katichev/explicit_cleanup
Replace job id with job instance in the job stack. Remove implicit "cleanup" call from "job.save"
8 years ago
Amjith Ramanujam 3cf5850afc Honor the job_class for failed_queue. 8 years ago
Yaniv Greenberg 39e43207a6 * Added support to use strings to specify both result_ttl and ttl.
* Added Days as possible timeout string (as 'd')
8 years ago
Alexey Katichev 3596449cc0 remove implicit cleanup call from job.save 8 years ago
luojiebin cd529d0ce1 Fixed issue#72 (#818)
* Added a custom exception for timeout transfer

* Added a util to transfer timeout to a united format

* Transfer timeout format when creating a queue or enqueue jobs

* Fixed typos

* Fixed bug in transfer_timeout function

* Added test for function transfer_timeout

* Updated transfer_timeout to allow uppercase unit

* Renamed function in utils
8 years ago
Felipe Lacerda cab89254b5 Make `Queue.enqueue_job()` execute immediately if `async=False` (#798)
Currently, the job is being performed inside `enqueue_call()`, which
means that `async=False` has no effect if `enqueue_job()` is called
directly. This commit fixes that.
8 years ago
Marko Mrdjenovic c8a955fbb1 Merge commit '83007b20740a97f085a14d3840d1e434350c6600'
# Conflicts:
#	rq/queue.py
9 years ago
Selwin Ong 83007b2074 Merge pull request #786 from jezdez/backend-class-overrides
Allow passing backend classes from CLI and other APIs
9 years ago
Marko Mrdjenovic 3da3eab11d moved job run to separate method to make async jobs easier 9 years ago
Benjamin Root efb30b45a3 Take a different tack, and enable the exclusion of meta from saves 9 years ago
Jannis Leidel c019662430
Allow passing backend classes (job, queue, worker, connection) from CLI and other APIs
This includes:

- a partial refactor of the CLI to organize the shared options
- extends the tests in areas where passing custom backend classes makes sense
- allow setting the core CLI options as env vars
- minor cosmetic changes here and there
9 years ago
Michael DeWulf 9e8922a099 Don't run lrem directly if we have a pipeline 9 years ago
Selwin Ong 6721463fdf queue.enqueue_call should call Job.exists with connection parameters. 9 years ago
Julien Surloppe dc3bba9362 Another check on failed status and test 9 years ago
Julien Surloppe 88a3c60177 Fix get job on failed queue 9 years ago
Stefan Hammer f9bff3d12b Merge branch 'master' into 739_fix_race_condition 9 years ago
Michael DeWulf f3f61bbc15 Pass pipeline to push_job_id from enqueue_job 9 years ago
Samuel Colvin afc7469c27 fetch_job - check correct queue, fix #728 9 years ago
Stefan Hammer 301e5c927b Raise an exception if a given dependency does not exist
Adapted some tests to the change: the dependency has to be saved first.
9 years ago
Stefan Hammer 67ae9277e5 completely pipelined enqueue_dependents 9 years ago
Stefan Hammer 7b8d4e075e protecting dependency enqueuing with redis WATCH 9 years ago
Selwin Ong e9d227c3df Dependent jobs are now correctly enqueued even if their parent jobs have result_ttl=0. 9 years ago
Eduard Carreras c27a6434a8 Set job as finished when not working in async mode 10 years ago
Tornstrom 50a114a0a8 Allow meta when enqueing 10 years ago
Javier Lopez d3d9a20680 Do not call pipeline.execute() if pipeline is given as argument 10 years ago
Javier Lopez 8a6bc08e47 Added pipeline named argument to enqueue_job 10 years ago
Javier Lopez b4f157516e enqueue_dependents now uses origin queue to enqueue
Current implementation is using the first job queue
to insert the dependent jobs. This makes RQ to ignore
the original queue where the jobs were enqueued.

With this change, we will use job origin attribute to
fetch the original queue, then insert the dependent
job to the fetched queue.

fixes issue #512
10 years ago
Jean-Christophe SAAD-DUPUY 8fbf5452fa fix: return (None, None) for dequeue_any if no result 10 years ago
Jean-Christophe SAAD-DUPUY 59d193590c fix: remove recursive call to dequeue_any 10 years ago
Dustin Falgout 91a3aa7493 make args and kwargs explicit for enqueue_call function
closes #466
10 years ago
Selwin Ong edd139d86f Sync jobs should be cleaned up after execution. 10 years ago
Vincent Driessen 94258761ae Make string formatting consistent 10 years ago
RyanMTB 9a00b0eca6 Updated Worker API 10 years ago
Selwin Ong cff6fbff41 Merge pull request #477 from glaslos/ttl_tests_fixes
TTL tests and fixes
10 years ago
Tamir Duberstein 985a2664a4 Prevent `Queue#dequeue` from blowing the stack
In the case of many sequential jobs having been deleted, a recursive
implementation of `Queue#dequeue` is prone to blowing the stack in the
absence of tail-recursion support. Change the implementation from
recursive to iterative to work around this issue in CPython.
10 years ago
Vlad Pronsky 933e6697cd Fixed redis drivers bug 10 years ago
glaslos 24d5e08992 Merge branch 'master' into ttl_tests_fixes
Conflicts:
	tests/test_job.py
11 years ago
Taras Semenenko 3dfd044767 Add missed `multi` command after `watch`
`watch` command should be used in conjunction with `multi` command
which was missed in enqueuing of job with dependencies.
Fix #487
11 years ago
glaslos c155918d6d lrem only first occurrence of the job id (we expect only one) 11 years ago
Vincent Driessen b8d425b318 Various PEP8 fixes. 11 years ago
Vincent Driessen fac2b10309 Auto-sort imports using isort. 11 years ago
glaslos 703ab0e355 removed merged comment 11 years ago
glaslos 646f1cda22 Merge branch 'master' into ttl_tests_fixes
Conflicts:
	rq/queue.py
11 years ago
glaslos 5b5ab4860f passing on the ttl 11 years ago
Selwin Ong dac0be6cc7 Added DeferredJobsRegistry to keep track of deferred jobs. 11 years ago
Selwin Ong 3e674fbe6a queue.enqueue() should set job.origin. 11 years ago
Selwin Ong 9320496402 Simplify FailedQueue.quarantine and ensure that a deferred job's status is set to Queued when enqueued. 11 years ago
Selwin Ong 7fd2ac8ca6 Added "DEFERRED" Job status for jobs that have unsatisfied dependencies. 11 years ago
Selwin Ong 0a0a81da6d Merge pull request #463 from conslo/skip-queue
Skip queue
11 years ago
Jonathan Tushman 1ae5a12a81 merging master 11 years ago
Travis Johnson add4d625b6 Merge branch 'nvie' into skip-queue
Conflicts:
	rq/queue.py
11 years ago
Jonathan Tushman 82333d2ad5 triggering shutdown by setting a redis flag 11 years ago
Travis Johnson db75958ad2 use 'at_front' instead of 'skip_queue' 11 years ago
Selwin Ong e1801c5c44 Merge pull request #453 from glaslos/job_ttl
TTL for jobs
11 years ago
Travis Johnson ac61f502a1 skip_queue functionality 11 years ago
Travis Johnson f60e4884df a comment typo 11 years ago
glaslos 8a3fd91e2e renaming job.job_ttl to job.ttl 11 years ago
glaslos 55c541bc59 added job ttl to queue.enqueue() 11 years ago
Travis Johnson af4b0436c1 instantiate a job instead of fetch
this removes the need for the depended on job.id already being saved
11 years ago
Travis Johnson 14d1186241 use internal job_class for check 11 years ago
Travis Johnson 3467868f1f allow depends_on to be a job id or a job itself
Other parts of the code (i.e.: the `.create()` method) allow the `depends_on` kwarg to be a `Job` object *or* a job id. This is an attempt to allow that same idea within the `.enqueue_call()` method for a queue. Since this part of the code requires actually knowing the precise redis key for the job that's depended on, my intuition is that a `.fetch()` is the only way to solve this.
11 years ago
Selwin Ong 18c6ea64ef Merge pull request #419 from selwin/registry-len
Added JobStartedRegistry.count
11 years ago
Selwin Ong 202be75b21 Merge pull request #415 from foxx/feature/custom-job-ids
Allow job ID to be set on enqueue/enqueue_call() - fixes #412
11 years ago
Selwin Ong c1dc30eae3 Added __len__ method to Queue. 11 years ago
foxx 30ea76ddd6 Fixed silly typo 11 years ago
foxx 0466562a13 Fixes from comments in #415
Added tox/vagrant tmp dir to gitignore
Removed unused import
Renamed id to job_id in enqueue_call() as per comments in #415
11 years ago
Selwin Ong a28575088b Implemented WorkingQueue.cleanup(). 11 years ago
foxx f5779c194f Renamed job_id to id, and fixed py3 bug, per #415 11 years ago
Vincent Driessen fc803f5d0d Fix various flake8 complaints. 11 years ago
foxx 6bb8b26114 Allow job ID to be set on enqueue/enqueue_call() - fixes #412 11 years ago
Vincent Driessen 3de8a47f06 Merge pull request #390 from selwin/pipeline-dependency-registration
job.register_dependency() should support pipelining
11 years ago
Selwin Ong fc19a64670 job.register_dependency() should support pipelining. 11 years ago
Vincent Driessen 12932a433b Merge pull request #382 from selwin/cancel-should-remove-from-queue
job.cancel() should remove itself from queue
11 years ago
Selwin Ong 638211df20 job.cancel() should remove itself from queue. 11 years ago
Selwin Ong 141278bb42 Queue.__init__ supports job_class argument. 11 years ago
Vincent Driessen 83382f51d0 PEP8ify. 11 years ago
Vincent Driessen b048e23875 Merge pull request #342 from friedcell/master
make job class dynamic
11 years ago
Vincent Driessen ab9e6b852e Fix PEP8 complaints. 11 years ago
Vincent Driessen 38ec259b6e Enable the most modern Python syntax. 11 years ago