Module: Shinq::Launcher

Defined in:
lib/shinq/launcher.rb

Instance Method Summary collapse

Instance Method Details

#lifecycle_limit?Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/shinq/launcher.rb', line 38

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

#runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/shinq/launcher.rb', line 6

def run
  worker_name = Shinq.configuration.worker_name
  worker_class = worker_name.camelize.constantize

  @loop_count = 0

  until @stop
    queue = Shinq::Client.dequeue(table_name: worker_name.pluralize)
    next Shinq.logger.info("Queue is empty (#{Time.now})") unless queue

    begin
      worker_class.new.perform(queue)
    rescue => e
      Shinq::Client.abort
      raise e
    end

    Shinq::Client.done

    @loop_count += 1

    if lifecycle_limit?
      Shinq.logger.info("Lifecycle Limit pid(#{Process.pid})")
      break
    end
  end
end

#stopObject



34
35
36
# File 'lib/shinq/launcher.rb', line 34

def stop
  @stop = true
end