Module: Workhorse::Enqueuer
- Included in:
- Workhorse
- Defined in:
- lib/workhorse/enqueuer.rb
Overview
Module providing job enqueuing functionality. Extended by the main Workhorse module to provide enqueuing capabilities. Supports plain Ruby objects, ActiveJob instances, and Rails operations.
Instance Method Summary collapse
-
#enqueue(job, queue: nil, priority: 0, perform_at: Time.now, description: nil) ⇒ Workhorse::DbJob
Enqueues any object that is serializable and has a ‘perform` method.
-
#enqueue_active_job(job, perform_at: Time.now, queue: nil, description: nil) ⇒ Workhorse::DbJob
Enqueues an ActiveJob job instance.
-
#enqueue_op(cls, *args) ⇒ Workhorse::DbJob
Enqueues the execution of a Rails operation by its class and parameters.
Instance Method Details
#enqueue(job, queue: nil, priority: 0, perform_at: Time.now, description: nil) ⇒ Workhorse::DbJob
Enqueues any object that is serializable and has a ‘perform` method.
14 15 16 17 18 19 20 21 22 |
# File 'lib/workhorse/enqueuer.rb', line 14 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) ⇒ Workhorse::DbJob
Enqueues an ActiveJob job instance.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/workhorse/enqueuer.rb', line 31 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) ⇒ Workhorse::DbJob
Enqueues the execution of a Rails operation by its class and parameters.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/workhorse/enqueuer.rb', line 51 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 |