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) ⇒ Object
Enqueue any object that is serializable and has a ‘perform` method.
-
#enqueue_active_job(job) ⇒ 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) ⇒ Object
Enqueue any object that is serializable and has a ‘perform` method
4 5 6 7 8 9 10 11 |
# File 'lib/workhorse/enqueuer.rb', line 4 def enqueue(job, queue: nil, priority: 0, perform_at: Time.now) return DbJob.create!( queue: queue, priority: priority, perform_at: perform_at, handler: Marshal.dump(job) ) end |
#enqueue_active_job(job) ⇒ Object
Enqueue an ActiveJob job
14 15 16 |
# File 'lib/workhorse/enqueuer.rb', line 14 def enqueue_active_job(job) enqueue job, queue: job.queue_name, priority: job.priority end |
#enqueue_op(cls, *args) ⇒ Object
Enqueue the execution of an operation by its class and params
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/workhorse/enqueuer.rb', line 19 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 |