Class: Sidejobs::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/sidejobs/queue.rb

Instance Method Summary collapse

Instance Method Details

#add(data, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/sidejobs/queue.rb', line 4

def add(data, options={})
  Job.create(
    data: data,
    queue: (options[:queue] || 'default'),
    priority: (options[:priority] || 0),
    scheduled_at: options[:schedule_at]
  )
end

#fetchObject



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

def fetch
  Job.where(state: %w(pending failing)).where(
    'attempts < ?',
    Sidejobs.configuration.max_attempts
  ).where(
    'scheduled_at <= ? OR scheduled_at IS NULL',
    Time.now
  ).order(priority: :desc).limit(Sidejobs.configuration.batch_size)
end