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

payrollhero / dispatch-rider / #3015

02 Sep 2022 11:22PM UTC coverage: 0.409% (-84.7%) from 85.154%
#3015

push

web-flow
Layout/SpaceInsideStringInterpolation-20220901233630 (#89)

* :police_car: regenerate rubocop todo

* :police_car: Layout/SpaceInsideStringInterpolation

* :police_car: regenerate rubocop todo

Co-authored-by: Rubocop Challenger <rubocop@payrollhero.com>

0 of 1 new or added line in 1 file covered. (0.0%)

1529 existing lines in 63 files now uncovered.

7 of 1711 relevant lines covered (0.41%)

0.0 hits per line

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

0.0
/lib/dispatch-rider/demultiplexer.rb
1
# The demultiplexer in the reactor pattern is implemented in this class.
2
# The object needs to be initiated with a queue and a dispatcher.
3
# Demultiplexer#start defines an event loop which pops items from the queue
4
# and passes it on to the dispatcher for dispatching to the appropriate message handler.
5
# The demultiplexer can be stopped by calling the Demultiplexer#stop method.
UNCOV
6
module DispatchRider
×
UNCOV
7
  class Demultiplexer
×
UNCOV
8
    attr_reader :queue, :dispatcher, :error_handler
×
9

UNCOV
10
    def initialize(queue, dispatcher, error_handler)
×
UNCOV
11
      @queue = queue
×
UNCOV
12
      @dispatcher = dispatcher
×
UNCOV
13
      @error_handler = error_handler
×
UNCOV
14
      @continue = true
×
UNCOV
15
      @current_message = nil
×
UNCOV
16
    end
×
17

UNCOV
18
    def start
×
UNCOV
19
      do_loop do
×
UNCOV
20
        begin
×
UNCOV
21
          sleep 1
×
UNCOV
22
          handle_next_queue_item
×
UNCOV
23
        rescue => exception
×
UNCOV
24
          error_handler.call(Message.new(subject: "TopLevelError", body: {}), exception)
×
UNCOV
25
          throw :done
×
UNCOV
26
        end
×
UNCOV
27
      end
×
UNCOV
28
      self
×
UNCOV
29
    end
×
30

UNCOV
31
    def stop(reason: nil)
×
UNCOV
32
      @continue = false
×
UNCOV
33
      Logging::LifecycleLogger.log_got_stop reason, @current_message if @current_message
×
UNCOV
34
    end
×
35

UNCOV
36
    private
×
37

UNCOV
38
    def with_current_message(message)
×
UNCOV
39
      begin
×
UNCOV
40
        @current_message = message
×
UNCOV
41
        yield
×
UNCOV
42
      ensure
×
UNCOV
43
        @current_message = nil
×
UNCOV
44
      end
×
UNCOV
45
    end
×
46

47
    # This needs to return true/false based on the success of the jobs!
UNCOV
48
    def dispatch_message(message)
×
UNCOV
49
      with_current_message(message) do
×
UNCOV
50
        dispatcher.dispatch(message)
×
UNCOV
51
      end
×
UNCOV
52
    rescue => exception
×
UNCOV
53
      handle_message_error message, exception
×
UNCOV
54
      false
×
UNCOV
55
    end
×
56

UNCOV
57
    def do_loop
×
UNCOV
58
      catch(:done) do
×
UNCOV
59
        while keep_going?
×
UNCOV
60
          throw :done unless @continue
×
UNCOV
61
          yield
×
UNCOV
62
        end
×
UNCOV
63
      end
×
UNCOV
64
    end
×
65

UNCOV
66
    def keep_going?
×
UNCOV
67
      true
×
UNCOV
68
    end
×
69

UNCOV
70
    def handle_next_queue_item
×
UNCOV
71
      queue.pop do |message|
×
UNCOV
72
        dispatch_message(message)
×
UNCOV
73
      end
×
UNCOV
74
    end
×
75

UNCOV
76
    def handle_message_error(message, exception)
×
UNCOV
77
      begin
×
UNCOV
78
        error_handler.call(message, exception)
×
UNCOV
79
      rescue => error_handler_exception # the error handler crashed
×
80
        Logging::LifecycleLogger.log_error_handler_fail message, error_handler_exception
×
81
        raise error_handler_exception
×
UNCOV
82
      end
×
UNCOV
83
    end
×
84

UNCOV
85
    def logger
×
86
      DispatchRider.config.logger
×
UNCOV
87
    end
×
UNCOV
88
  end
×
UNCOV
89
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