Class: BackgroundWorker::PersistentState
- Inherits:
-
Object
- Object
- BackgroundWorker::PersistentState
- Defined in:
- lib/background_worker/persistent_state.rb
Instance Attribute Summary collapse
-
#completed ⇒ Object
Returns the value of attribute completed.
-
#data ⇒ Object
Returns the value of attribute data.
-
#detailed_message ⇒ Object
Returns the value of attribute detailed_message.
-
#message ⇒ Object
Returns the value of attribute message.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
-
.get_state_of(job_id) ⇒ Object
Get a report out the queue (was .get_report, then .progress).
Instance Method Summary collapse
-
#initialize(job_id, data) ⇒ PersistentState
constructor
A new instance of PersistentState.
-
#save ⇒ Object
Save persistently (well for an hour at least).
- #set_completed(message, status) ⇒ Object
Constructor Details
#initialize(job_id, data) ⇒ PersistentState
Returns a new instance of PersistentState.
10 11 12 13 14 15 16 17 18 |
# File 'lib/background_worker/persistent_state.rb', line 10 def initialize(job_id, data) @message = 'Waiting for task to queue...' @status = :processing @completed = false @job_id = job_id @data = data save end |
Instance Attribute Details
#completed ⇒ Object
Returns the value of attribute completed.
8 9 10 |
# File 'lib/background_worker/persistent_state.rb', line 8 def completed @completed end |
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/background_worker/persistent_state.rb', line 8 def data @data end |
#detailed_message ⇒ Object
Returns the value of attribute detailed_message.
8 9 10 |
# File 'lib/background_worker/persistent_state.rb', line 8 def @detailed_message end |
#message ⇒ Object
Returns the value of attribute message.
8 9 10 |
# File 'lib/background_worker/persistent_state.rb', line 8 def @message end |
#status ⇒ Object
Returns the value of attribute status.
8 9 10 |
# File 'lib/background_worker/persistent_state.rb', line 8 def status @status end |
Class Method Details
.get_state_of(job_id) ⇒ Object
Get a report out the queue (was .get_report, then .progress)
35 36 37 |
# File 'lib/background_worker/persistent_state.rb', line 35 def self.get_state_of(job_id) Rails.cache.read(job_id) end |
Instance Method Details
#save ⇒ Object
Save persistently (well for an hour at least)
29 30 31 |
# File 'lib/background_worker/persistent_state.rb', line 29 def save Rails.cache.write(@job_id, generate_persistent_hash, expires_in: 1.hour) end |
#set_completed(message, status) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/background_worker/persistent_state.rb', line 20 def set_completed(, status) self.status = status self. = self.completed = true save end |