diff options
author | Yoshiyuki Hirano <yhirano@me.com> | 2017-12-05 15:25:12 +0900 |
---|---|---|
committer | Yoshiyuki Hirano <yhirano@me.com> | 2017-12-05 15:40:22 +0900 |
commit | 649f19cab1d4dd805c915912ede29c86655084cd (patch) | |
tree | b6e1481d8e1a41ee28b63117e569dd1cbf8cf1b5 /Gemfile.lock | |
parent | c383c4142a1ce3b7bbfa241957cd81f398c91231 (diff) | |
download | rails-649f19cab1d4dd805c915912ede29c86655084cd.tar.gz rails-649f19cab1d4dd805c915912ede29c86655084cd.tar.bz2 rails-649f19cab1d4dd805c915912ede29c86655084cd.zip |
Fix example code in ActiveJob::Core [ci skip]
1) It seems that it raise error on example code in `ActiveJob::Core`.
Before:
```ruby
class DeliverWebhookJob < ActiveJob::Base
def serialize
super.merge('attempt_number' => (@attempt_number || 0) + 1)
end
def deserialize(job_data)
super
@attempt_number = job_data['attempt_number']
end
rescue_from(Timeout::Error) do |exception|
raise exception if @attempt_number > 5
retry_job(wait: 10)
end
def perform
raise Timeout::Error
end
end
```
Then it run `DeliverWebhookJob.perform_now` in `rails console`. And raise error:
NoMethodError: undefined method `>' for nil:NilClass
from /app/jobs/deliver_webhook_job.rb:12:in `block in <class:DeliverWebhookJob>'
So I thought it's necessary to fix it.
After:
```ruby
class DeliverWebhookJob < ActiveJob::Base
attr_writer :attempt_number
def attempt_number
@attempt_number ||= 0
end
def serialize
super.merge('attempt_number' => attempt_number + 1)
end
def deserialize(job_data)
super
self.attempt_number = job_data['attempt_number']
end
rescue_from(Timeout::Error) do |exception|
raise exception if attempt_number > 5
retry_job(wait: 10)
end
def perform
raise Timeout::Error
end
end
```
Then it run `DeliverWebhookJob.perform_now` in `rails console`. And it does'nt raise error NoMethodError.
2) Use `Timeout::Error` instead of `TimeoutError` (`TimeoutError` is deprecated).
Diffstat (limited to 'Gemfile.lock')
0 files changed, 0 insertions, 0 deletions