Class: Tasque::Task

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
StateMachine::MacroMethods
Defined in:
lib/tasque/task.rb

Constant Summary collapse

MAX_ATTEMPTS =
3

Class Method Summary collapse

Class Method Details

.autoreprocess(reprocess_limit = nil) ⇒ Object



58
59
60
61
62
# File 'lib/tasque/task.rb', line 58

def autoreprocess(reprocess_limit = nil)
  Tasque::Task.to_reprocess.limit(reprocess_limit.to_i).each do |task|
    task.reprocess
  end.count
end

.do_fetch(type) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/tasque/task.rb', line 27

def do_fetch(type)
  minimum_priority = Tasque.config.minimum_priority
  task = self.with_task(type).to_process.minimum_priority(minimum_priority).lock(true).first
  if task and task.can_pickup?
    task.pickup
    task
  end
end

.fetch(type) {|task| ... } ⇒ Object

Yields:

  • (task)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tasque/task.rb', line 36

def fetch(type, &block)
  task = nil
  if Tasque.config.use_mutex && defined?(RedisMutex)
    RedisMutex.with_lock(Tasque.config.mutex_name, Tasque.config.mutex_options) do
      task = do_fetch(type)
    end
  else
    transaction do
      task = do_fetch(type)
    end
  end
  yield(task) if task
  !!task
end

.monitoringObject



51
52
53
54
55
56
# File 'lib/tasque/task.rb', line 51

def monitoring
  {
    queue: Tasque::Task.to_process.count,
    errors: Tasque::Task.with_error.finished_in(1.hour).count
  }
end