Class: Afterparty::Worker

Inherits:
Object
  • Object
show all
Includes:
QueueHelpers
Defined in:
lib/afterparty/worker.rb

Instance Method Summary collapse

Methods included from QueueHelpers

#[], #authenticate, #clear, #completed, #completed_with_scores, #config_login, #handle_exception, #initialize, #jobs, #jobs_empty?, #jobs_with_scores, #last_completed, #next_valid_job, #run, #total_jobs_count, #valid_jobs

Instance Method Details

#consumeObject



5
6
7
8
9
10
11
12
# File 'lib/afterparty/worker.rb', line 5

def consume
  @stopped = false
  # puts "starting worker with namespace [#{@options[:namespace]}]."
  @thread = Thread.new {
    consume_sync
  }
  @thread
end

#consume_nextObject



14
15
16
17
18
# File 'lib/afterparty/worker.rb', line 14

def consume_next
  if (job = next_valid_job)
    run job
  end
end

#consume_syncObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/afterparty/worker.rb', line 20

def consume_sync
  while !@stopped
    job = next_valid_job
    if job
      puts "Executing job: #{job.id}"
      run job
    else
      sleep(@options[:sleep])
    end
  end
end

#stopObject



32
33
34
35
# File 'lib/afterparty/worker.rb', line 32

def stop
  @stopped = true
  @thread.join(0) if @thread
end