Class: Jiggler::Scheduled::Poller

Inherits:
Object
  • Object
show all
Includes:
Jiggler::Support::Helper
Defined in:
lib/jiggler/scheduled/poller.rb

Constant Summary collapse

INITIAL_WAIT =
5

Instance Method Summary collapse

Methods included from Jiggler::Support::Helper

#log_error, #log_error_short, #logger, #safe_async, #scan_all, #tid

Constructor Details

#initialize(config) ⇒ Poller

Returns a new instance of Poller.



12
13
14
15
16
17
18
19
20
21
# File 'lib/jiggler/scheduled/poller.rb', line 12

def initialize(config)
  @config = config
  @enqueuer = Jiggler::Scheduled::Enqueuer.new(config)
  @requeuer = Jiggler::Scheduled::Requeuer.new(config)
  @done = false
  @job = nil
  @count_calls = 0
  @requeuer_condition = Async::Condition.new
  @enqueuer_condition = Async::Condition.new
end

Instance Method Details

#enqueueObject



55
56
57
# File 'lib/jiggler/scheduled/poller.rb', line 55

def enqueue
  @enqueuer.enqueue_jobs
end

#handle_stale_in_process_queuesObject



59
60
61
# File 'lib/jiggler/scheduled/poller.rb', line 59

def handle_stale_in_process_queues
  @requeuer.handle_stale
end

#startObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/jiggler/scheduled/poller.rb', line 35

def start
  @job = Async do
    @tid = tid
    initial_wait
    safe_async('Poller') do
      until @done
        enqueue
        wait(@enqueuer_condition) unless @done
      end
    end
    safe_async('Requeuer') do
      until @done
        handle_stale_in_process_queues
        logger.debug('Executing requeuer')
        wait(@requeuer_condition, in_process_interval) unless @done
      end
    end if @config.at_least_once?
  end
end

#terminateObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jiggler/scheduled/poller.rb', line 23

def terminate
  @done = true
  @enqueuer.terminate
  @requeuer.terminate

  Async do
    @requeuer_condition.signal
    @enqueuer_condition.signal
    @job&.wait
  end
end