2015-02-08 08:52:47 -05:00
|
|
|
* Add an `:only` option to `perform_enqueued_jobs` to filter jobs based on
|
|
|
|
type.
|
|
|
|
|
|
|
|
This allows specific jobs to be tested, while preventing others from
|
|
|
|
being performed unnecessarily.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
def test_hello_job
|
|
|
|
assert_performed_jobs 1, only: HelloJob do
|
|
|
|
HelloJob.perform_later('jeremy')
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
An array may also be specified, to support testing multiple jobs.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
def test_hello_and_logging_jobs
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_performed_jobs 2, only: [HelloJob, LoggingJob] do
|
|
|
|
HelloJob.perform_later('jeremy')
|
|
|
|
LoggingJob.perform_later('stewie')
|
|
|
|
RescueJob.perform_later('david')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Fixes #18802.
|
|
|
|
|
|
|
|
*Michael Ryan*
|
|
|
|
|
2015-01-30 15:40:49 -05:00
|
|
|
* Allow keyword arguments to be used with Active Job.
|
|
|
|
|
|
|
|
Fixes #18741.
|
|
|
|
|
|
|
|
*Sean Griffin*
|
|
|
|
|
2015-01-08 04:40:00 -05:00
|
|
|
* Add `:only` option to `assert_enqueued_jobs`, to check the number of times
|
2015-01-10 06:17:57 -05:00
|
|
|
a specific kind of job is enqueued.
|
|
|
|
|
|
|
|
Example:
|
2015-01-08 04:40:00 -05:00
|
|
|
|
|
|
|
def test_logging_job
|
|
|
|
assert_enqueued_jobs 1, only: LoggingJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
HelloJob.perform_later('jeremy')
|
|
|
|
end
|
2015-01-07 23:33:01 -05:00
|
|
|
end
|
|
|
|
|
2015-01-08 04:40:00 -05:00
|
|
|
*George Claghorn*
|
2014-12-30 13:26:39 -05:00
|
|
|
|
2015-01-08 04:40:00 -05:00
|
|
|
* `ActiveJob::Base.deserialize` delegates to the job class.
|
2014-12-31 10:31:25 -05:00
|
|
|
|
|
|
|
Since `ActiveJob::Base#deserialize` can be overridden by subclasses (like
|
|
|
|
`ActiveJob::Base#serialize`) this allows jobs to attach arbitrary metadata
|
2015-01-10 06:17:57 -05:00
|
|
|
when they get serialized and read it back when they get performed.
|
|
|
|
|
|
|
|
Example:
|
2014-12-30 13:26:39 -05:00
|
|
|
|
2015-01-08 04:40:00 -05:00
|
|
|
class DeliverWebhookJob < ActiveJob::Base
|
|
|
|
def serialize
|
|
|
|
super.merge('attempt_number' => (@attempt_number || 0) + 1)
|
|
|
|
end
|
2014-12-30 13:26:39 -05:00
|
|
|
|
2015-01-08 04:40:00 -05:00
|
|
|
def deserialize(job_data)
|
|
|
|
super
|
|
|
|
@attempt_number = job_data['attempt_number']
|
|
|
|
end
|
2014-12-30 13:26:39 -05:00
|
|
|
|
2015-01-08 04:40:00 -05:00
|
|
|
rescue_from(TimeoutError) do |exception|
|
|
|
|
raise exception if @attempt_number > 5
|
|
|
|
retry_job(wait: 10)
|
|
|
|
end
|
2014-12-30 13:26:39 -05:00
|
|
|
end
|
|
|
|
|
2014-12-31 10:31:25 -05:00
|
|
|
*Isaac Seymour*
|
2014-12-30 13:26:39 -05:00
|
|
|
|
2014-11-28 12:00:06 -05:00
|
|
|
Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activejob/CHANGELOG.md) for previous changes.
|