Module: Shinq::Launcher

Defined in:
lib/shinq/launcher.rb

Instance Method Summary collapse

Instance Method Details

#initializeObject



6
7
8
# File 'lib/shinq/launcher.rb', line 6

def initialize
  Shinq.clear_all_connections!
end

#lifecycle_limit?Boolean

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/shinq/launcher.rb', line 54

def lifecycle_limit?
  return false unless Shinq.configuration.lifecycle
  return (Shinq.configuration.lifecycle < @loop_count)
end

#runObject

Wait configured queue and proceed each of them until stop.



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

#stopObject



50
51
52
# File 'lib/shinq/launcher.rb', line 50

def stop
  @stop = true
end