• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Unleash / unleash-client-ruby / 11031869423

25 Sep 2024 11:14AM UTC coverage: 95.57% (-1.7%) from 97.25%
11031869423

Pull #204

github

web-flow
Merge 4cf325450 into d890ae8d3
Pull Request #204: docs: migration guide for v6

73 of 74 new or added lines in 8 files covered. (98.65%)

6 existing lines in 3 files now uncovered.

453 of 474 relevant lines covered (95.57%)

1377.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.12
/lib/unleash/scheduled_executor.rb
1
module Unleash
16✔
2
  class ScheduledExecutor
16✔
3
    attr_accessor :name, :interval, :max_exceptions, :retry_count, :thread, :immediate_execution
16✔
4

5
    def initialize(name, interval, max_exceptions = 5, immediate_execution = false)
16✔
6
      self.name = name || ''
224✔
7
      self.interval = interval
224✔
8
      self.max_exceptions = max_exceptions
224✔
9
      self.retry_count = 0
224✔
10
      self.thread = nil
224✔
11
      self.immediate_execution = immediate_execution
224✔
12
    end
13

14
    def run(&blk)
16✔
15
      self.thread = Thread.new do
224✔
16
        Thread.current[:name] = self.name
217✔
17

18
        run_blk{ blk.call } if self.immediate_execution
217✔
19

20
        Unleash.logger.debug "thread #{name} loop starting"
216✔
21
        loop do
216✔
22
          Unleash.logger.debug "thread #{name} sleeping for #{interval} seconds"
264✔
23
          sleep interval
264✔
24

25
          run_blk{ blk.call }
160✔
26

27
          if exceeded_max_exceptions?
80✔
28
            Unleash.logger.error "thread #{name} retry_count (#{self.retry_count}) exceeded " \
36✔
29
                "max_exceptions (#{self.max_exceptions}). Stopping with retries."
30
            break
32✔
31
          end
32
        end
33
        Unleash.logger.debug "thread #{name} loop ended"
32✔
34
      end
35
    end
36

37
    def running?
16✔
38
      self.thread.is_a?(Thread) && self.thread.alive?
80✔
39
    end
40

41
    def exit
16✔
42
      if self.running?
16✔
43
        Unleash.logger.warn "thread #{name} will exit!"
16✔
44
        self.thread.exit
16✔
45
        self.thread.join if self.running?
16✔
46
      else
47
        Unleash.logger.info "thread #{name} was already stopped!"
×
48
      end
49
    end
50

51
    private
16✔
52

53
    def run_blk(&blk)
16✔
54
      Unleash.logger.debug "thread #{name} starting execution"
80✔
55

56
      yield(blk)
80✔
UNCOV
57
      self.retry_count = 0
×
58
    rescue StandardError => e
59
      self.retry_count += 1
80✔
60
      Unleash.logger.error "thread #{name} threw exception #{e.class} " \
90✔
61
          " (#{self.retry_count}/#{self.max_exceptions}): '#{e}'"
62
      Unleash.logger.debug "stacktrace: #{e.backtrace}"
80✔
63
    end
64

65
    def exceeded_max_exceptions?
16✔
66
      self.retry_count > self.max_exceptions
80✔
67
    end
68
  end
69
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc