Class: Afterparty::Worker
- Inherits:
-
Object
- Object
- Afterparty::Worker
show all
- Includes:
- QueueHelpers
- Defined in:
- lib/afterparty/worker.rb
Instance Attribute Summary
Attributes included from QueueHelpers
#options
Instance Method Summary
collapse
#authenticate, #clear, #completed, #config_login, #handle_exception, #initialize, #jobs, #jobs_empty?, #last_completed, #next_valid_job, #run, #total_jobs_count, #valid_jobs
Instance Method Details
#consume ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/afterparty/worker.rb', line 5
def consume
@stopped = false
@thread = Thread.new {
consume_sync
}
@thread
end
|
#consume_next ⇒ Object
13
14
15
16
17
|
# File 'lib/afterparty/worker.rb', line 13
def consume_next
if (job = next_valid_job)
run job
end
end
|
#consume_sync ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/afterparty/worker.rb', line 19
def consume_sync
while !@stopped
job = next_valid_job
if job
puts "Executing job: #{job.id}" if job.respond_to? :id
run job
else
sleep(@options[:sleep])
end
end
end
|
#stop ⇒ Object
31
32
33
34
|
# File 'lib/afterparty/worker.rb', line 31
def stop
@stopped = true
@thread.join(0) if @thread
end
|