Class: ActiveJob::Status::Storage
- Inherits:
-
Object
- Object
- ActiveJob::Status::Storage
- Defined in:
- lib/activejob-status/storage.rb
Instance Method Summary collapse
- #delete(job) ⇒ Object
-
#initialize(options = {}) ⇒ Storage
constructor
A new instance of Storage.
- #job_id(job) ⇒ Object
- #key(job) ⇒ Object
- #read(job) ⇒ Object
- #store ⇒ Object
- #update(job, message, force: false) ⇒ Object
- #write(job, message, force: false) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Storage
Returns a new instance of Storage.
6 7 8 9 10 11 |
# File 'lib/activejob-status/storage.rb', line 6 def initialize( = {}) .assert_valid_keys(:expires_in, :throttle_interval) @expires_in = [:expires_in] @throttle = ActiveJob::Status::Throttle.new([:throttle_interval]) end |
Instance Method Details
#delete(job) ⇒ Object
42 43 44 |
# File 'lib/activejob-status/storage.rb', line 42 def delete(job) store.delete(key(job)) end |
#job_id(job) ⇒ Object
17 18 19 |
# File 'lib/activejob-status/storage.rb', line 17 def job_id(job) job.is_a?(String) ? job : job.job_id end |
#key(job) ⇒ Object
21 22 23 |
# File 'lib/activejob-status/storage.rb', line 21 def key(job) "activejob:status:#{job_id(job)}" end |
#read(job) ⇒ Object
25 26 27 |
# File 'lib/activejob-status/storage.rb', line 25 def read(job) store.read(key(job)) || {} end |
#store ⇒ Object
13 14 15 |
# File 'lib/activejob-status/storage.rb', line 13 def store @store ||= ActiveJob::Status.store end |
#update(job, message, force: false) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/activejob-status/storage.rb', line 35 def update(job, , force: false) @throttle.wrap(force: force) do = read(job).merge() store.write(key(job), , expires_in: @expires_in) end end |
#write(job, message, force: false) ⇒ Object
29 30 31 32 33 |
# File 'lib/activejob-status/storage.rb', line 29 def write(job, , force: false) @throttle.wrap(force: force) do store.write(key(job), , expires_in: @expires_in) end end |