Class: FiberJob::Client
- Inherits:
-
Object
- Object
- FiberJob::Client
- Defined in:
- lib/fiber_job/client.rb
Overview
Client handles job enqueueing and scheduling operations. Provides the core interface for adding jobs to queues with immediate, delayed, or scheduled execution.
This class is used internally by Job class methods and can also be used directly for advanced job management scenarios.
Class Method Summary collapse
-
.enqueue(job_class, *args) ⇒ String
Enqueues a job for immediate execution.
-
.enqueue_at(timestamp, job_class, *args) ⇒ String
Enqueues a job for execution at a specific time.
-
.enqueue_in(delay_seconds, job_class, *args) ⇒ String
Enqueues a job for execution after a specified delay.
Class Method Details
.enqueue(job_class, *args) ⇒ String
Enqueues a job for immediate execution. The job will be added to the appropriate queue and processed by the next available worker.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fiber_job/client.rb', line 33 def self.enqueue(job_class, *args) jid = JID.generate payload = { 'jid' => jid, 'class' => job_class.name, 'args' => args, 'enqueued_at' => Time.now.to_f } queue_name = job_class.queue Queue.push(queue_name, payload) jid end |
.enqueue_at(timestamp, job_class, *args) ⇒ String
Enqueues a job for execution at a specific time. The job will be scheduled and executed when the specified time is reached.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fiber_job/client.rb', line 96 def self.enqueue_at(, job_class, *args) jid = JID.generate payload = { 'jid' => jid, 'class' => job_class.name, 'args' => args, 'enqueued_at' => Time.now.to_f } queue_name = job_class.queue Queue.schedule(queue_name, payload, .to_f) FiberJob.logger.info "Scheduled #{job_class.name} (#{jid}) to run at #{Time.at()}" jid end |
.enqueue_in(delay_seconds, job_class, *args) ⇒ String
Enqueues a job for execution after a specified delay. The job will be scheduled for future execution and moved to the regular queue when the delay period expires.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fiber_job/client.rb', line 62 def self.enqueue_in(delay_seconds, job_class, *args) jid = JID.generate scheduled_at = Time.now.to_f + delay_seconds payload = { 'jid' => jid, 'class' => job_class.name, 'args' => args, 'enqueued_at' => Time.now.to_f } queue_name = job_class.queue Queue.schedule(queue_name, payload, scheduled_at) FiberJob.logger.info "Scheduled #{job_class.name} (#{jid}) to run in #{delay_seconds}s" jid end |