Class: Kiqit::JobCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/kiqit/job_creator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue, worker, klass_name, id, method, *args) ⇒ JobCreator

Returns a new instance of JobCreator.



7
8
9
10
11
12
13
14
# File 'lib/kiqit/job_creator.rb', line 7

def initialize(queue, worker, klass_name, id, method, *args)
  @queue       = queue
  @worker      = worker
  @klass_name  = klass_name
  @id          = id
  @method      = method
  @args        = args
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



5
6
7
# File 'lib/kiqit/job_creator.rb', line 5

def args
  @args
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/kiqit/job_creator.rb', line 4

def id
  @id
end

#klass_nameObject (readonly)

Returns the value of attribute klass_name.



4
5
6
# File 'lib/kiqit/job_creator.rb', line 4

def klass_name
  @klass_name
end

#methodObject (readonly)

Returns the value of attribute method.



4
5
6
# File 'lib/kiqit/job_creator.rb', line 4

def method
  @method
end

#queueObject (readonly)

Returns the value of attribute queue.



4
5
6
# File 'lib/kiqit/job_creator.rb', line 4

def queue
  @queue
end

#workerObject (readonly)

Returns the value of attribute worker.



4
5
6
# File 'lib/kiqit/job_creator.rb', line 4

def worker
  @worker
end

Instance Method Details

#enqueue(delay = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kiqit/job_creator.rb', line 16

def enqueue(delay=nil)
  params = {}
  if delay
    delay = delay.is_a?(Hash) ? delay[:delay] : delay
    params["at"] = (Time.now + delay).to_i
  end

  params.merge!({"queue" => queue, "class" => worker, "args" => [klass_name, id, method, *args]})

  Sidekiq::Client.push(params)
end