• 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/queue_services/aws_sqs.rb
1
# This queue service is based on aws sqs.
2
# To make this queue service work, one would need the aws sqs gem to be installed.
UNCOV
3
module DispatchRider
×
UNCOV
4
  module QueueServices
×
UNCOV
5
    class AwsSqs < Base
×
UNCOV
6
      require "dispatch-rider/queue_services/aws_sqs/message_body_extractor"
×
UNCOV
7
      require "dispatch-rider/queue_services/aws_sqs/sqs_received_message"
×
8

UNCOV
9
      class AbortExecution < RuntimeError; end
×
UNCOV
10
      class VisibilityTimeoutExceeded < RuntimeError; end
×
11

UNCOV
12
      def assign_storage(attrs)
×
UNCOV
13
        sqs = Aws::SQS::Client.new(logger: nil)
×
UNCOV
14
        if attrs[:name].present?
×
UNCOV
15
          url = sqs.list_queues({queue_name_prefix: attrs[:name]}).queue_urls.first
×
UNCOV
16
          set_visibility_timeout(sqs,url)
×
UNCOV
17
          Aws::SQS::Queue.new(url: url, client: sqs)
×
UNCOV
18
        elsif attrs[:url].present?
×
UNCOV
19
          set_visibility_timeout(sqs,attrs[:url])
×
UNCOV
20
          Aws::SQS::Queue.new(url: attrs[:url], client: sqs)
×
UNCOV
21
        else
×
UNCOV
22
          raise RecordInvalid.new(self, ["Either name or url have to be specified"])
×
UNCOV
23
        end
×
UNCOV
24
      rescue NameError
×
25
        raise AdapterNotFoundError.new(self.class.name, 'aws-sdk')
×
UNCOV
26
      end
×
27

UNCOV
28
      def pop
×
UNCOV
29
        raw_item = queue.receive_messages({max_number_of_messages: 1}).first
×
UNCOV
30
        if raw_item.present?
×
UNCOV
31
          obj = SqsReceivedMessage.new(construct_message_from(raw_item), raw_item, queue, visibility_timeout)
×
32

UNCOV
33
          visibility_timeout_shield(obj) do
×
UNCOV
34
            raise AbortExecution, "false received from handler" unless yield(obj)
×
UNCOV
35
            obj
×
UNCOV
36
          end
×
37

UNCOV
38
          Retriable.retriable(tries: 3) { raw_item.delete }
×
UNCOV
39
        end
×
UNCOV
40
      rescue AbortExecution
×
41
        # ignore, it was already handled, just need to break out if pop
UNCOV
42
      end
×
43

UNCOV
44
      def insert(item)
×
UNCOV
45
        queue.send_message(item)
×
UNCOV
46
      end
×
47

UNCOV
48
      def construct_message_from(item)
×
UNCOV
49
        deserialize(MessageBodyExtractor.new(item).extract)
×
UNCOV
50
      end
×
51

UNCOV
52
      def delete(item)
×
UNCOV
53
        item.delete
×
UNCOV
54
      end
×
55

UNCOV
56
      def size
×
UNCOV
57
        queue.approximate_number_of_messages
×
UNCOV
58
      end
×
59

UNCOV
60
      attr_reader :visibility_timeout
×
61

UNCOV
62
      private
×
63

UNCOV
64
      def set_visibility_timeout(client,url)
×
UNCOV
65
        resp = client.get_queue_attributes(queue_url: url, attribute_names: ["VisibilityTimeout"])
×
UNCOV
66
        @visibility_timeout = resp.attributes["VisibilityTimeout"]
×
UNCOV
67
      end
×
68

UNCOV
69
      def visibility_timeout_shield(message)
×
UNCOV
70
        yield
×
UNCOV
71
      ensure
×
UNCOV
72
        duration = Time.now - message.start_time
×
UNCOV
73
        timeout = message.total_timeout
×
UNCOV
74
        if duration > timeout
×
UNCOV
75
          message = "message: #{message.subject}, #{message.body.inspect} took #{duration} seconds while the timeout was #{timeout}"
×
UNCOV
76
          raise VisibilityTimeoutExceeded, message
×
UNCOV
77
        end
×
UNCOV
78
      end
×
UNCOV
79
    end
×
UNCOV
80
  end
×
UNCOV
81
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