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
24
25
# 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
  @sync_groups = []

  Signal.trap('SIGINT',  lambda{ raise Interrupt, 'SIGINT'  })
  Signal.trap('SIGQUIT', lambda{ raise Interrupt, 'SIGQUIT' })
  Signal.trap('TERM',    lambda{ raise Interrupt, 'TERM'    })
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

#shutdown?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/inbox-sync/runner.rb', line 43

def shutdown?
  !!@shutdown
end

#startObject



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

def start
  startup!
  loop do
    loop_run
    break if shutdown?
  end
  shutdown!
end

#stopObject



36
37
38
39
40
41
# File 'lib/inbox-sync/runner.rb', line 36

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