Class: Core::Scheduler

Inherits:
Object
  • Object
show all
Defined in:
lib/core/scheduler.rb

Direct Known Subclasses

Connectors::Crawler::Scheduler

Instance Method Summary collapse

Constructor Details

#initialize(poll_interval, heartbeat_interval) ⇒ Scheduler

Returns a new instance of Scheduler.



20
21
22
23
24
# File 'lib/core/scheduler.rb', line 20

def initialize(poll_interval, heartbeat_interval)
  @poll_interval = poll_interval
  @heartbeat_interval = heartbeat_interval
  @is_shutting_down = false
end

Instance Method Details

#connector_settingsObject



26
27
28
# File 'lib/core/scheduler.rb', line 26

def connector_settings
  raise 'Not implemented'
end

#shutdownObject



58
59
60
61
# File 'lib/core/scheduler.rb', line 58

def shutdown
  Utility::Logger.info("Shutting down scheduler #{self.class.name}.")
  @is_shutting_down = true
end

#when_triggeredObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/core/scheduler.rb', line 30

def when_triggered
  loop do
    connector_settings.each do |cs|
      if sync_triggered?(cs)
        yield cs, :sync
      end
      if heartbeat_triggered?(cs)
        yield cs, :heartbeat
      end
      if configuration_triggered?(cs)
        yield cs, :configuration
      end
      if filtering_validation_triggered?(cs)
        yield cs, :filter_validation
      end
    end
  rescue *Utility::AUTHORIZATION_ERRORS => e
    log_authorization_error(e)
  rescue StandardError => e
    log_standard_error(e)
  ensure
    if @is_shutting_down
      break
    end
    sleep_for_poll_interval
  end
end