Class: Litejob::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/litejob/client.rb

Overview

Litejob::Client is responsible for pushing job payloads to the SQLite queue.

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



9
10
11
# File 'lib/litejob/client.rb', line 9

def initialize
  @queue = Litequeue.instance
end

Instance Method Details

#delete(id) ⇒ Object



23
24
25
26
27
# File 'lib/litejob/client.rb', line 23

def delete(id)
  payload = @queue.delete(id)
  Litejob.logger.info("[litejob]:[DEL] job=#{id}")
  JSON.parse(payload)
end

#push(jobclass, params, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/litejob/client.rb', line 13

def push(jobclass, params, options = {})
  delay = options[:delay] || 0
  attempts = options[:attempts] || 5
  queue = options[:queue]
  payload = JSON.dump({class: jobclass, params: params, attempts: attempts, queue: queue})
  job_id, job_queue = atomic_push(payload, delay, queue)
  Litejob.logger.info("[litejob]:[ENQ] queue=#{job_queue} class=#{jobclass} job=#{job_id}")
  [job_id, job_queue]
end