Class: InboxSync::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/inbox-sync/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/inbox-sync/runner.rb', line 9

def initialize(*args)
  opts, syncs = [
    args.last.kind_of?(Hash) ? args.pop : {},
    args.flatten
  ]

  @syncs = syncs || []
  @interval = opts[:interval].kind_of?(Fixnum) ? opts[:interval] : -1
  @logger = opts[:logger] || Logger.new(STDOUT)
  @shutdown = false
  @running_syncs_thread = nil

  Signal.trap('SIGINT', lambda{ self.stop })
  Signal.trap('SIGQUIT', lambda{ self.stop })
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



7
8
9
# File 'lib/inbox-sync/runner.rb', line 7

def interval
  @interval
end

#loggerObject (readonly)

Returns the value of attribute logger.



7
8
9
# File 'lib/inbox-sync/runner.rb', line 7

def logger
  @logger
end

#syncsObject (readonly)

Returns the value of attribute syncs.



7
8
9
# File 'lib/inbox-sync/runner.rb', line 7

def syncs
  @syncs
end

Instance Method Details

#startObject



25
26
27
28
29
30
31
32
# File 'lib/inbox-sync/runner.rb', line 25

def start
  startup
  loop do
    break if @shutdown
    loop_run
  end
  shutdown
end

#stopObject



34
35
36
37
# File 'lib/inbox-sync/runner.rb', line 34

def stop
  main_log "Stop signal - waiting for any running syncs to finish."
  @shutdown = true
end