Module: Workhorse::Enqueuer
- Included in:
- Workhorse
- Defined in:
- lib/workhorse/enqueuer.rb
Instance Method Summary collapse
-
#enqueue(job, queue: nil, priority: 0, perform_at: Time.now, description: nil) ⇒ Object
Enqueue any object that is serializable and has a ‘perform` method.
-
#enqueue_active_job(job, perform_at: Time.now, queue: nil, description: nil) ⇒ Object
Enqueue an ActiveJob job.
-
#enqueue_op(cls, *args) ⇒ Object
Enqueue the execution of an operation by its class and params.
Instance Method Details
#enqueue(job, queue: nil, priority: 0, perform_at: Time.now, description: nil) ⇒ Object
Enqueue any object that is serializable and has a ‘perform` method
4 5 6 7 8 9 10 11 12 |
# File 'lib/workhorse/enqueuer.rb', line 4 def enqueue(job, queue: nil, priority: 0, perform_at: Time.now, description: nil) return DbJob.create!( queue: queue, priority: priority, perform_at: perform_at, description: description, handler: Marshal.dump(job) ) end |
#enqueue_active_job(job, perform_at: Time.now, queue: nil, description: nil) ⇒ Object
Enqueue an ActiveJob job
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/workhorse/enqueuer.rb', line 15 def enqueue_active_job(job, perform_at: Time.now, queue: nil, description: nil) wrapper_job = Jobs::RunActiveJob.new(job.serialize) queue ||= job.queue_name if job.queue_name.present? db_job = enqueue( wrapper_job, queue: queue, priority: job.priority || 0, perform_at: Time.at(perform_at), description: description ) job.provider_job_id = db_job.id return db_job end |
#enqueue_op(cls, *args) ⇒ Object
Enqueue the execution of an operation by its class and params
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/workhorse/enqueuer.rb', line 30 def enqueue_op(cls, *args) case args.size when 0 workhorse_args = {} op_args = {} when 1 workhorse_args = args.first op_args = {} when 2 workhorse_args, op_args = *args else fail ArgumentError, "wrong number of arguments (#{args.size + 1} for 2..3)" end job = Workhorse::Jobs::RunRailsOp.new(cls, op_args) enqueue job, **workhorse_args end |