Class: Sidekiq::Tasks::Task
- Inherits:
-
Object
- Object
- Sidekiq::Tasks::Task
- Extended by:
- Forwardable
- Includes:
- Validations
- Defined in:
- lib/sidekiq/tasks/task.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
Instance Method Summary collapse
- #enqueue(params = {}) ⇒ Object
- #execute(params = {}, jid: nil) ⇒ Object
-
#initialize(metadata:, strategy:) ⇒ Task
constructor
A new instance of Task.
- #storage ⇒ Object
Methods included from Validations
validate_array_classes!, validate_class!, validate_expected_values!, validate_hash_option!
Constructor Details
#initialize(metadata:, strategy:) ⇒ Task
Returns a new instance of Task.
17 18 19 20 21 22 23 |
# File 'lib/sidekiq/tasks/task.rb', line 17 def initialize(metadata:, strategy:) = @strategy = strategy validate_class!(, [Sidekiq::Tasks::TaskMetadata], "metadata") validate_class!(strategy, [Sidekiq::Tasks::Strategies::Base], "strategy") end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/sidekiq/tasks/task.rb', line 12 def end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
12 13 14 |
# File 'lib/sidekiq/tasks/task.rb', line 12 def strategy @strategy end |
Instance Method Details
#enqueue(params = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/sidekiq/tasks/task.rb', line 25 def enqueue(params = {}) jid = strategy.enqueue_task(name, params) storage.store_enqueue(jid, params) end |
#execute(params = {}, jid: nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sidekiq/tasks/task.rb', line 31 def execute(params = {}, jid: nil) storage.store_execution(jid, "executed_at") begin strategy.execute_task(name, params) rescue => e storage.store_execution(jid, "finished_at") storage.store_execution_error(jid, e) raise end storage.store_execution(jid, "finished_at") end |
#storage ⇒ Object
45 46 47 |
# File 'lib/sidekiq/tasks/task.rb', line 45 def storage @_storage ||= Sidekiq::Tasks::Storage.new(name) end |