Method: Shinq::Client.enqueue

Defined in:
lib/shinq/client.rb

.enqueue(table_name:, job_id:, args:, scheduled_at: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/shinq/client.rb', line 11

def self.enqueue(table_name: , job_id: , args:, scheduled_at: nil)
  if scheduled_at && !schedulable?(table_name: table_name)
    raise ArgumentError, "table #{table_name} is not schedulable. You need column `scheduled_at`"
  end

  case args
  when Hash
    attributes = args.merge(
      job_id: job_id,
      scheduled_at: scheduled_at ? scheduled_at.to_i : nil,
      enqueued_at: Time.now,
    ).compact
    sql = builder.insert(table_name, attributes)
    Shinq.connection.query(sql)
  else
    raise ArgumentError, "`args` should be a Hash"
  end
end