Class: PollingProcessor
- Defined in:
- lib/ff/ruby/server/sdk/api/polling_processor.rb
Instance Method Summary collapse
- #close ⇒ Object
- #init(connector, repository, poll_interval_in_sec, callback, logger = nil) ⇒ Object
- #is_ready ⇒ Object
- #retrieve_flags ⇒ Object
- #retrieve_segments ⇒ Object
- #start ⇒ Object
- #start_async ⇒ Object
- #stop ⇒ Object
- #stop_async ⇒ Object
Instance Method Details
#close ⇒ Object
153 154 155 156 157 |
# File 'lib/ff/ruby/server/sdk/api/polling_processor.rb', line 153 def close stop @logger.info "Closing PollingProcessor" end |
#init(connector, repository, poll_interval_in_sec, callback, logger = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ff/ruby/server/sdk/api/polling_processor.rb', line 5 def init( connector, repository, poll_interval_in_sec, callback, logger = nil ) @callback = callback @connector = connector @repository = repository @poll_interval_in_sec = poll_interval_in_sec if logger != nil @logger = logger else @logger = Logger.new(STDOUT) end end |
#is_ready ⇒ Object
159 160 161 162 |
# File 'lib/ff/ruby/server/sdk/api/polling_processor.rb', line 159 def is_ready @ready && @initialized end |
#retrieve_flags ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ff/ruby/server/sdk/api/polling_processor.rb', line 28 def retrieve_flags flags = [] @logger.debug "Fetching flags started" result = @connector.get_flags if result != nil @logger.debug "Flags are fetched" result.each { |fc| if fc != nil @repository.set_flag(fc.feature, fc) flags.push(fc) end } end @logger.debug "Fetching flags finished" flags end |
#retrieve_segments ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ff/ruby/server/sdk/api/polling_processor.rb', line 55 def retrieve_segments segments = [] @logger.debug "Fetching segments started" result = @connector.get_segments if result != nil @logger.debug "Segments are fetched" result.each { |s| if s != nil @repository.set_segment(s.identifier, s) segments.push(s) end } end @logger.debug "Fetching segments finished" segments end |
#start ⇒ Object
138 139 140 141 142 |
# File 'lib/ff/ruby/server/sdk/api/polling_processor.rb', line 138 def start @logger.debug "Starting PollingProcessor with request interval: " + @poll_interval_in_sec.to_s start_async end |
#start_async ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/ff/ruby/server/sdk/api/polling_processor.rb', line 82 def start_async @logger.debug "Async starting: " + self.to_s @ready = true @thread = Thread.new do @logger.debug "Async started: " + self.to_s while @ready do @logger.debug "Async poll iteration" if @callback != nil @callback.on_poller_iteration(self) end begin retrieve_flags retrieve_segments unless @initialized @initialized = true SdkCodes::info_poll_started(@logger, @poll_interval_in_sec) if @callback != nil @callback.on_poller_ready(self) end end rescue OpenapiClient::ApiError => e if @callback != nil @callback.on_poller_error(e) end end sleep(@poll_interval_in_sec) end end @thread.run end |
#stop ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/ff/ruby/server/sdk/api/polling_processor.rb', line 144 def stop @logger.debug "Stopping PollingProcessor" stop_async unless @ready SdkCodes::info_polling_stopped @logger end end |
#stop_async ⇒ Object
132 133 134 135 136 |
# File 'lib/ff/ruby/server/sdk/api/polling_processor.rb', line 132 def stop_async @ready = false @initialized = false end |