Module: Delayed::Backend::Sequel::LazyJob::ClassMethods

Defined in:
lib/delayed/backend/sequel.rb

Instance Method Summary collapse

Instance Method Details

#clear_locks!(worker_name) ⇒ Object

When a worker is exiting, make sure we don’t have any locked jobs.



58
59
60
# File 'lib/delayed/backend/sequel.rb', line 58

def clear_locks!(worker_name)
  Job.filter("locked_by = '#{worker_name}'").update(:locked_at => nil, :locked_by => nil)
end

#db_time_nowObject



62
63
64
# File 'lib/delayed/backend/sequel.rb', line 62

def db_time_now
  Time.now
end

#delete_allObject



70
71
72
# File 'lib/delayed/backend/sequel.rb', line 70

def delete_all
  Job.delete()
end

#find(id) ⇒ Object



74
75
76
# File 'lib/delayed/backend/sequel.rb', line 74

def find(id)
  self[id]
end

#find_available(worker_name, limit = 5, max_run_time = Worker.max_run_time) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/delayed/backend/sequel.rb', line 48

def find_available(worker_name, limit = 5, max_run_time = Worker.max_run_time)
  right_now = db_time_now
  filters   = []
  filters << "(run_at <= '#{make_db_timestamp(right_now)}' AND (locked_at IS NULL OR locked_at < '#{make_db_timestamp(right_now - max_run_time)}') OR locked_by = '#{worker_name}') AND failed_at IS NULL"
  filters << "priority >= #{Worker.min_priority.to_i}" if Worker.min_priority
  filters << "priority <= #{Worker.max_priority.to_i}" if Worker.max_priority
  Job.filter(filters.join(' and ')).order(:priority, :run_at).limit(limit).all()
end

#make_db_timestamp(time) ⇒ Object



66
67
68
# File 'lib/delayed/backend/sequel.rb', line 66

def make_db_timestamp(time)
  "#{time.strftime('%Y-%m-%d %H:%M:%S')}.#{time.usec}#{time.strftime('%z')}"
end