Class: Faktory::Launcher

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/faktory/launcher.rb

Constant Summary collapse

PROCTITLES =
[]

Constants included from Util

Util::EXPIRY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#fire_event, #hostname, #identity, #logger, #process_nonce, #safe_thread, #server, #watchdog

Methods included from ExceptionHandler

#handle_exception

Constructor Details

#initialize(options) ⇒ Launcher

Returns a new instance of Launcher.



11
12
13
14
15
# File 'lib/faktory/launcher.rb', line 11

def initialize(options)
  @manager = Faktory::Manager.new(options)
  @done = false
  @options = options
end

Instance Attribute Details

#managerObject

Returns the value of attribute manager.



9
10
11
# File 'lib/faktory/launcher.rb', line 9

def manager
  @manager
end

Instance Method Details

#heartbeatObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/faktory/launcher.rb', line 47

def heartbeat
  title = ['faktory-worker', Faktory::VERSION, @options[:tag]].compact.join(" ")
  PROCTITLES << proc { title }
  PROCTITLES << proc { "[#{Processor.busy_count} of #{@options[:concurrency]} busy]" }
  PROCTITLES << proc { "stopping" if stopping? }

  loop do
    $0 = PROCTITLES.map {|p| p.call }.join(" ")

    begin
      Faktory.server {|c| c.beat }
    rescue => ex
      # best effort, try again in a few secs
    end
    sleep 10
  end
end

#quietObject

Stops this instance from processing any more jobs,



23
24
25
26
# File 'lib/faktory/launcher.rb', line 23

def quiet
  @done = true
  @manager.quiet
end

#runObject



17
18
19
20
# File 'lib/faktory/launcher.rb', line 17

def run
  @thread = safe_thread("heartbeat", &method(:heartbeat))
  @manager.start
end

#stopObject

Shuts down the process. This method does not return until all work is complete and cleaned up. It can take up to the timeout to complete.



31
32
33
34
35
36
37
# File 'lib/faktory/launcher.rb', line 31

def stop
  deadline = Time.now + @options[:timeout]

  @done = true
  @manager.quiet
  @manager.stop(deadline)
end

#stopping?Boolean

Returns:

  • (Boolean)


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

def stopping?
  @done
end