12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/shinq/launcher.rb', line 12
def run
worker_name = Shinq.configuration.worker_name
worker_class = Shinq.configuration.worker_class
@loop_count = 0
until @stop
begin
queue = Shinq::Client.dequeue(table_name: worker_name.pluralize)
next Shinq.logger.info("Queue is empty (#{Time.now})") unless queue
if Shinq.configuration.abort_on_error
worker_class.new.perform(queue)
Shinq::Client.done
else
Shinq::Client.done
worker_class.new.perform(queue)
end
Shinq.clear_all_connections!
rescue => e
Shinq.logger.error(format_error_message(e))
sleep Shinq.configuration.sleep_sec_on_error
Shinq::Client.abort if Shinq.configuration.abort_on_error && queue
Shinq.clear_all_connections!
break
end
@loop_count += 1
if lifecycle_limit?
Shinq.logger.info("Lifecycle Limit pid(#{Process.pid})")
break
end
end
end
|