dispatch-rider 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +5 -4
  3. data/.rubocop.yml +21 -0
  4. data/.rubocop_todo.yml +17 -300
  5. data/CHANGELOG.md +7 -0
  6. data/Rakefile +2 -1
  7. data/dispatch-rider.gemspec +3 -3
  8. data/lib/dispatch-rider/callbacks/access.rb +2 -0
  9. data/lib/dispatch-rider/callbacks/storage.rb +7 -5
  10. data/lib/dispatch-rider/callbacks/support.rb +2 -0
  11. data/lib/dispatch-rider/callbacks.rb +2 -0
  12. data/lib/dispatch-rider/command.rb +3 -3
  13. data/lib/dispatch-rider/configuration.rb +3 -1
  14. data/lib/dispatch-rider/debug.rb +3 -1
  15. data/lib/dispatch-rider/demultiplexer.rb +17 -19
  16. data/lib/dispatch-rider/dispatcher.rb +2 -0
  17. data/lib/dispatch-rider/error_handlers.rb +3 -1
  18. data/lib/dispatch-rider/errors.rb +2 -0
  19. data/lib/dispatch-rider/handlers/base.rb +12 -10
  20. data/lib/dispatch-rider/handlers/inheritance_tracking.rb +2 -0
  21. data/lib/dispatch-rider/handlers/named_process.rb +2 -0
  22. data/lib/dispatch-rider/handlers.rb +2 -0
  23. data/lib/dispatch-rider/integrations/appsignal.rb +3 -1
  24. data/lib/dispatch-rider/logging/json_formatter.rb +2 -0
  25. data/lib/dispatch-rider/logging/lifecycle_logger.rb +3 -1
  26. data/lib/dispatch-rider/logging/text_formatter.rb +2 -0
  27. data/lib/dispatch-rider/logging/translator/base_translator.rb +3 -1
  28. data/lib/dispatch-rider/logging/translator/complete_translator.rb +2 -0
  29. data/lib/dispatch-rider/logging/translator/error_handler_fail_translator.rb +2 -0
  30. data/lib/dispatch-rider/logging/translator/fail_translator.rb +2 -0
  31. data/lib/dispatch-rider/logging/translator/start_translator.rb +2 -0
  32. data/lib/dispatch-rider/logging/translator/stop_translator.rb +2 -0
  33. data/lib/dispatch-rider/logging/translator/success_translator.rb +2 -0
  34. data/lib/dispatch-rider/logging/translator.rb +2 -0
  35. data/lib/dispatch-rider/logging.rb +2 -0
  36. data/lib/dispatch-rider/message.rb +3 -0
  37. data/lib/dispatch-rider/notification_services/aws_sns.rb +5 -3
  38. data/lib/dispatch-rider/notification_services/base.rb +2 -0
  39. data/lib/dispatch-rider/notification_services/file_system/channel.rb +2 -0
  40. data/lib/dispatch-rider/notification_services/file_system/notifier.rb +2 -0
  41. data/lib/dispatch-rider/notification_services/file_system.rb +3 -1
  42. data/lib/dispatch-rider/notification_services.rb +2 -0
  43. data/lib/dispatch-rider/publisher/base.rb +2 -0
  44. data/lib/dispatch-rider/publisher/configuration/destination.rb +6 -4
  45. data/lib/dispatch-rider/publisher/configuration/notification_service.rb +4 -2
  46. data/lib/dispatch-rider/publisher/configuration.rb +2 -0
  47. data/lib/dispatch-rider/publisher/configuration_reader.rb +3 -1
  48. data/lib/dispatch-rider/publisher/configuration_support.rb +3 -1
  49. data/lib/dispatch-rider/publisher.rb +7 -12
  50. data/lib/dispatch-rider/queue_services/aws_sqs/message_body_extractor.rb +2 -0
  51. data/lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb +6 -4
  52. data/lib/dispatch-rider/queue_services/aws_sqs.rb +5 -2
  53. data/lib/dispatch-rider/queue_services/base.rb +5 -4
  54. data/lib/dispatch-rider/queue_services/file_system/fs_received_message.rb +5 -3
  55. data/lib/dispatch-rider/queue_services/file_system/queue.rb +5 -4
  56. data/lib/dispatch-rider/queue_services/file_system.rb +7 -11
  57. data/lib/dispatch-rider/queue_services/received_message.rb +3 -1
  58. data/lib/dispatch-rider/queue_services/simple.rb +5 -7
  59. data/lib/dispatch-rider/queue_services.rb +2 -0
  60. data/lib/dispatch-rider/registrars/base.rb +5 -5
  61. data/lib/dispatch-rider/registrars/file_system_channel.rb +3 -1
  62. data/lib/dispatch-rider/registrars/handler.rb +3 -1
  63. data/lib/dispatch-rider/registrars/notification_service.rb +2 -0
  64. data/lib/dispatch-rider/registrars/publishing_destination.rb +3 -1
  65. data/lib/dispatch-rider/registrars/queue_service.rb +2 -0
  66. data/lib/dispatch-rider/registrars/sns_channel.rb +3 -1
  67. data/lib/dispatch-rider/registrars.rb +2 -0
  68. data/lib/dispatch-rider/runner.rb +2 -0
  69. data/lib/dispatch-rider/scheduled_job/migration.rb +2 -0
  70. data/lib/dispatch-rider/scheduled_job.rb +3 -3
  71. data/lib/dispatch-rider/subscriber.rb +2 -0
  72. data/lib/dispatch-rider/version.rb +3 -1
  73. data/lib/dispatch-rider.rb +3 -1
  74. data/lib/generators/dispatch_rider/install/install_generator.rb +2 -0
  75. data/lib/generators/dispatch_rider/install/templates/script/dispatch_rider +1 -0
  76. data/lib/generators/dispatch_rider/job/dispatch_job_generator.rb +2 -0
  77. data/spec/factories/messages.rb +4 -1
  78. data/spec/fixtures/handlers/another_test_handler.rb +2 -0
  79. data/spec/fixtures/handlers/test_handler.rb +2 -0
  80. data/spec/integration/logging_spec.rb +2 -0
  81. data/spec/lib/dispatch-rider/airbrake_error_handler_spec.rb +3 -1
  82. data/spec/lib/dispatch-rider/callbacks/access_spec.rb +2 -0
  83. data/spec/lib/dispatch-rider/callbacks/storage_spec.rb +2 -0
  84. data/spec/lib/dispatch-rider/configuration_spec.rb +3 -1
  85. data/spec/lib/dispatch-rider/default_error_handler_spec.rb +2 -0
  86. data/spec/lib/dispatch-rider/demultiplexer_spec.rb +4 -2
  87. data/spec/lib/dispatch-rider/dispatcher_spec.rb +12 -9
  88. data/spec/lib/dispatch-rider/handlers/base_spec.rb +2 -0
  89. data/spec/lib/dispatch-rider/handlers/inheritance_tracking_spec.rb +2 -0
  90. data/spec/lib/dispatch-rider/logging/json_formatter_spec.rb +2 -0
  91. data/spec/lib/dispatch-rider/logging/lifecycle_logger_spec.rb +3 -1
  92. data/spec/lib/dispatch-rider/logging/text_formatter_spec.rb +2 -0
  93. data/spec/lib/dispatch-rider/logging/translator_spec.rb +2 -0
  94. data/spec/lib/dispatch-rider/message_spec.rb +7 -5
  95. data/spec/lib/dispatch-rider/notification_services/aws_sns_spec.rb +2 -0
  96. data/spec/lib/dispatch-rider/notification_services/base_spec.rb +6 -4
  97. data/spec/lib/dispatch-rider/notification_services/file_system/channel_spec.rb +2 -0
  98. data/spec/lib/dispatch-rider/notification_services/file_system/notifier_spec.rb +2 -0
  99. data/spec/lib/dispatch-rider/notification_services/file_system_spec.rb +2 -0
  100. data/spec/lib/dispatch-rider/notification_services_spec.rb +2 -0
  101. data/spec/lib/dispatch-rider/publisher/base_spec.rb +2 -0
  102. data/spec/lib/dispatch-rider/publisher/configuration/destination_spec.rb +2 -0
  103. data/spec/lib/dispatch-rider/publisher/configuration/notification_service_spec.rb +2 -0
  104. data/spec/lib/dispatch-rider/publisher/configuration_reader_spec.rb +15 -4
  105. data/spec/lib/dispatch-rider/publisher/configuration_spec.rb +3 -1
  106. data/spec/lib/dispatch-rider/publisher/configuration_support_spec.rb +4 -2
  107. data/spec/lib/dispatch-rider/publisher_spec.rb +15 -22
  108. data/spec/lib/dispatch-rider/queue_services/aws_sqs_spec.rb +11 -4
  109. data/spec/lib/dispatch-rider/queue_services/base_spec.rb +10 -8
  110. data/spec/lib/dispatch-rider/queue_services/file_system_spec.rb +7 -5
  111. data/spec/lib/dispatch-rider/queue_services/received_message_spec.rb +2 -0
  112. data/spec/lib/dispatch-rider/queue_services/simple_spec.rb +6 -4
  113. data/spec/lib/dispatch-rider/registrars/base_spec.rb +4 -2
  114. data/spec/lib/dispatch-rider/registrars/file_system_channel_spec.rb +2 -0
  115. data/spec/lib/dispatch-rider/registrars/handler_spec.rb +2 -0
  116. data/spec/lib/dispatch-rider/registrars/notification_service_spec.rb +2 -0
  117. data/spec/lib/dispatch-rider/registrars/publishing_destination_spec.rb +2 -0
  118. data/spec/lib/dispatch-rider/registrars/queue_service_spec.rb +2 -0
  119. data/spec/lib/dispatch-rider/registrars/sns_channel_spec.rb +2 -0
  120. data/spec/lib/dispatch-rider/registrars_spec.rb +2 -0
  121. data/spec/lib/dispatch-rider/runner_spec.rb +3 -1
  122. data/spec/lib/dispatch-rider/scheduled_job_spec.rb +2 -0
  123. data/spec/lib/dispatch-rider/subscriber_spec.rb +6 -3
  124. data/spec/lib/dispatch-rider_spec.rb +2 -0
  125. data/spec/spec_helper.rb +2 -1
  126. data/spec/support/crashing_handler.rb +2 -0
  127. data/spec/support/integration_support.rb +2 -0
  128. data/spec/support/null_logger.rb +2 -0
  129. data/spec/support/sample_handler.rb +2 -0
  130. metadata +30 -30
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Callbacks
3
5
  # Storage for callbacks.
@@ -21,11 +23,11 @@ module DispatchRider
21
23
  # @param [Proc] &block
22
24
  def after(event, block_param = nil, &block)
23
25
  around(event) do |job, *args|
24
- begin
25
- job.call
26
- ensure
27
- (block_param || block).call(*args)
28
- end
26
+
27
+ job.call
28
+ ensure
29
+ (block_param || block).call(*args)
30
+
29
31
  end
30
32
  end
31
33
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Callbacks
3
5
  # Adds callback support to an object.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Callbacks
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'daemons'
2
4
  require 'pathname'
3
5
  require 'optparse'
@@ -23,9 +25,7 @@ module DispatchRider
23
25
  process_name = "dispatch_rider.#{@options[:identifier]}"
24
26
  Daemons.run_proc(process_name, @options) do
25
27
  $0 = File.join(@options[:prefix], process_name) if @options[:prefix]
26
- Dir.chdir(@app_home.to_s) do
27
- block.call
28
- end
28
+ Dir.chdir(@app_home.to_s, &block)
29
29
  end
30
30
  end
31
31
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  class Configuration
3
5
  attr_accessor(
@@ -22,7 +24,7 @@ module DispatchRider
22
24
  @subscriber = DispatchRider::Subscriber
23
25
  @log_formatter = DispatchRider::Logging::TextFormatter.new
24
26
  @additional_info_injector = -> (data) { data }
25
- @logger = Logger.new(STDERR)
27
+ @logger = Logger.new($stderr)
26
28
  @debug = false
27
29
 
28
30
  @callbacks.around(:dispatch_message) do |job, message|
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Debug
3
- PUBLISHER_MESSAGE_GUID = 'test-mode-not-random-guid'.freeze
5
+ PUBLISHER_MESSAGE_GUID = 'test-mode-not-random-guid'
4
6
  end
5
7
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The demultiplexer in the reactor pattern is implemented in this class.
2
4
  # The object needs to be initiated with a queue and a dispatcher.
3
5
  # Demultiplexer#start defines an event loop which pops items from the queue
@@ -17,13 +19,13 @@ module DispatchRider
17
19
 
18
20
  def start
19
21
  do_loop do
20
- begin
21
- sleep 1
22
- handle_next_queue_item
23
- rescue => exception
24
- error_handler.call(Message.new(subject: "TopLevelError", body: {}), exception)
25
- throw :done
26
- end
22
+
23
+ sleep 1
24
+ handle_next_queue_item
25
+ rescue => exception
26
+ error_handler.call(Message.new(subject: "TopLevelError", body: {}), exception)
27
+ throw :done
28
+
27
29
  end
28
30
  self
29
31
  end
@@ -36,12 +38,10 @@ module DispatchRider
36
38
  private
37
39
 
38
40
  def with_current_message(message)
39
- begin
40
- @current_message = message
41
- yield
42
- ensure
43
- @current_message = nil
44
- end
41
+ @current_message = message
42
+ yield
43
+ ensure
44
+ @current_message = nil
45
45
  end
46
46
 
47
47
  # This needs to return true/false based on the success of the jobs!
@@ -74,12 +74,10 @@ module DispatchRider
74
74
  end
75
75
 
76
76
  def handle_message_error(message, exception)
77
- begin
78
- error_handler.call(message, exception)
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
82
- end
77
+ error_handler.call(message, exception)
78
+ rescue => error_handler_exception # the error handler crashed
79
+ Logging::LifecycleLogger.log_error_handler_fail message, error_handler_exception
80
+ raise error_handler_exception
83
81
  end
84
82
 
85
83
  def logger
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This class is responsible for dispatching the messages to the appropriate handler.
2
4
  # The handlers must be registered with the dispatcher.
3
5
  # Tha handlers need to be modules that implement the process method.
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  # This is the default error handler for dispatch rider.
3
5
  # It simply re-raises the exception.
4
6
  module DefaultErrorHandler
5
- def self.call(message, exception)
7
+ def self.call(_message, exception)
6
8
  raise exception
7
9
  end
8
10
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file contains all the error classes for this gem.
2
4
  module DispatchRider
3
5
  # The base error class of the gem
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Handlers
3
5
  class Base
4
6
  include NamedProcess
5
7
  extend InheritanceTracking
6
-
8
+
7
9
  class << self
8
- def set_default_retry( amount )
10
+ def set_default_retry( amount )
9
11
  define_method(:retry_timeout) do
10
12
  amount
11
13
  end
12
14
  end
13
15
  end
14
-
16
+
15
17
  attr_reader :raw_message
16
18
 
17
19
  def do_process(raw_message)
@@ -20,24 +22,24 @@ module DispatchRider
20
22
  process(raw_message.body)
21
23
  end
22
24
  rescue Exception => e
23
- self.retry if self.retry_on_failure?
25
+ self.retry if retry_on_failure?
24
26
  raise e
25
27
  end
26
28
 
27
29
  def process(message)
28
30
  raise NotImplementedError, "Method 'process' not overridden in subclass!"
29
31
  end
30
-
32
+
31
33
  protected
32
-
34
+
33
35
  def extend_timeout(timeout)
34
36
  raw_message.extend_timeout(timeout)
35
37
  end
36
-
38
+
37
39
  def return_to_queue
38
40
  raw_message.return_to_queue
39
41
  end
40
-
42
+
41
43
  def retry
42
44
  timeout = retry_timeout
43
45
  case timeout
@@ -47,9 +49,9 @@ module DispatchRider
47
49
  extend_timeout(timeout)
48
50
  end
49
51
  end
50
-
52
+
51
53
  def retry_on_failure?
52
- self.respond_to? :retry_timeout
54
+ respond_to? :retry_timeout
53
55
  end
54
56
  end
55
57
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This module tracks which classes inherit from the class that includes
2
4
  # the module, and provides an accessor to it.
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Handlers
3
5
  module NamedProcess
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Handlers
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if defined? Appsignal
2
4
  ::Appsignal.logger.info('Loading Dispatch Rider integration')
3
5
 
@@ -13,7 +15,7 @@ if defined? Appsignal
13
15
  method: 'handle',
14
16
  attempts: message.receive_count,
15
17
  queue: message.queue_name,
16
- queue_time: (Time.now.to_f - message.sent_at.to_f) * 1000,
18
+ queue_time: (Time.now.to_f - message.sent_at.to_f) * 1000
17
19
  ) do
18
20
  job.call
19
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
 
3
5
  # JSON Log Formatter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Logging
3
5
  class LifecycleLogger
@@ -72,7 +74,7 @@ module DispatchRider
72
74
  end
73
75
 
74
76
  def translated_message
75
- translator.translate(message, kind, options)
77
+ translator.translate(message, kind, **options)
76
78
  end
77
79
 
78
80
  def interjected_message
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Text Log Formatter
2
4
  module DispatchRider
3
5
  module Logging
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Logging
3
5
  class Translator
4
6
  class BaseTranslator
5
- def initialize(message, **)
7
+ def initialize(message)
6
8
  @message = message
7
9
  end
8
10
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Logging
3
5
  class Translator
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Logging
3
5
  class Translator
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Logging
3
5
  class Translator
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Logging
3
5
  class Translator
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Logging
3
5
  class Translator
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Logging
3
5
  class Translator
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Logging
3
5
  # Translates a message into a loggable hash based on its result.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module Logging
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This class represents a message. All other objects dela with passing around instances of this class.
2
4
  # A message must have a subject and a body. The subject represents the handlers name and the body represents
3
5
  # the payload of the process method in the handler.
@@ -27,6 +29,7 @@ module DispatchRider
27
29
 
28
30
  def ==(other)
29
31
  return false unless other.respond_to? :attributes
32
+
30
33
  attributes == other.attributes
31
34
  end
32
35
  end
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aws-sdk-sns'
4
+
1
5
  # This is a basic implementation of the Notification service using Amazon SNS.
2
6
  # The expected usage is as follows :
3
7
  # notification_service = DispatchRider::NotificationServices::AwsSns.new
@@ -7,8 +11,6 @@ module DispatchRider
7
11
  class AwsSns < Base
8
12
  def notifier_builder
9
13
  Aws::SNS::Client
10
- rescue NameError
11
- raise AdapterNotFoundError.new(self.class.name, 'aws-sdk')
12
14
  end
13
15
 
14
16
  def channel_registrar_builder
@@ -22,7 +24,7 @@ module DispatchRider
22
24
  # not really happy with this, but the notification service registrar system is way too rigid to do this cleaner
23
25
  # since you only can have one notifier for the whole service, but you need to create a new one for each region
24
26
  def channel(name)
25
- arn = self.fetch(name)
27
+ arn = fetch(name)
26
28
  # in v1, the Topic object was fetched from API, in v3 it's basically just an arn wrapper
27
29
  Aws::SNS::Topic.new(arn)
28
30
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This base class provides an interface that we can implement
2
4
  # to generate a wrapper around a notification service.
3
5
  # The expected usage is as follows :
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # this represents a FileSystem queue channel (or basically a folder)
2
4
 
3
5
  module DispatchRider
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This is abstraction around a notifier service for FileSystem based queue services
2
4
 
3
5
  module DispatchRider
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # this is a basic notification service which uses a filesystem folder to handle notifications
2
4
 
3
5
  module DispatchRider
@@ -12,7 +14,7 @@ module DispatchRider
12
14
  end
13
15
 
14
16
  def channel(name)
15
- notifier.channel(self.fetch(name))
17
+ notifier.channel(fetch(name))
16
18
  end
17
19
  end
18
20
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The namespace that holds the notification services services
2
4
  module DispatchRider
3
5
  module NotificationServices
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'securerandom'
2
4
 
3
5
  module DispatchRider
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  class Publisher::Configuration::Destination
3
5
  def initialize(name, attributes={})
@@ -12,10 +14,10 @@ module DispatchRider
12
14
  attr_reader :name, :service, :channel, :options
13
15
 
14
16
  def ==(other)
15
- self.name == other.name &&
16
- self.service == other.service &&
17
- self.channel == other.channel &&
18
- self.options == other.options
17
+ name == other.name &&
18
+ service == other.service &&
19
+ channel == other.channel &&
20
+ options == other.options
19
21
  end
20
22
  end
21
23
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  class Publisher::Configuration::NotificationService
3
5
  def initialize(name, options)
@@ -8,8 +10,8 @@ module DispatchRider
8
10
  attr_reader :name, :options
9
11
 
10
12
  def ==(other)
11
- self.name == other.name &&
12
- self.options == other.options
13
+ name == other.name &&
14
+ options == other.options
13
15
  end
14
16
  end
15
17
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  class Publisher::Configuration
3
5
  def initialize(configuration_hash = {})
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  class Publisher
3
5
  module ConfigurationReader
@@ -11,7 +13,7 @@ module DispatchRider
11
13
 
12
14
  def configure_notification_services(notification_services, publisher)
13
15
  notification_services.each do |service|
14
- publisher.register_notification_service(service.name, service.options)
16
+ publisher.register_notification_service(service.name, **service.options)
15
17
  end
16
18
  end
17
19
 
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  class Publisher
3
5
  module ConfigurationSupport
4
6
  def configuration
5
7
  @configuration ||= Configuration.new
6
8
  end
7
- alias_method :config, :configuration
9
+ alias config configuration
8
10
 
9
11
  def configure(configuration_hash = {})
10
12
  if block_given?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/hash/indifferent_access"
2
4
  require_relative "publisher/configuration_support"
3
5
 
@@ -35,23 +37,17 @@ module DispatchRider
35
37
  self
36
38
  end
37
39
 
38
- # @param [Hash] original_options should contain `:destinations` and `:message` keys
39
- def publish(original_options = {})
40
- options = build_publish_options(original_options)
41
-
42
- callbacks.invoke(:publish, options) do
40
+ def publish(message:, destinations:)
41
+ options = { message: build_message(message), destinations: destinations }
42
+ callbacks.invoke(:publish, **options) do
43
43
  service_channel_mapper.map(options.delete(:destinations)).each do |(service, channels)|
44
- notification_service_registrar.fetch(service).publish(options.merge to: channels)
44
+ notification_service_registrar.fetch(service).publish(**(options.merge to: channels))
45
45
  end
46
46
  end
47
47
  end
48
48
 
49
49
  private
50
50
 
51
- def build_publish_options(message:, destinations:)
52
- { message: build_message(message), destinations: destinations }
53
- end
54
-
55
51
  def build_message(attributes)
56
52
  DispatchRider::Message.new(attributes).tap do |message|
57
53
  message.body[:guid] ||= generate_new_message_id
@@ -84,13 +80,12 @@ module DispatchRider
84
80
  end
85
81
 
86
82
  def services_and_channels_map(destinations)
87
- destinations.reduce({}) do |result, destination|
83
+ destinations.each_with_object({}) do |destination, result|
88
84
  if result.has_key?(destination.service)
89
85
  result[destination.service] << destination.channel
90
86
  else
91
87
  result[destination.service] = [destination.channel]
92
88
  end
93
- result
94
89
  end
95
90
  end
96
91
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module QueueServices
3
5
  class AwsSqs < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module QueueServices
3
5
  class AwsSqs < Base
@@ -14,10 +16,10 @@ module DispatchRider
14
16
  # NOTE: Setting the visibility timeout resets the timeout to NOW and makes it visibility timeout this time
15
17
  # Essentially resetting the timer on this message
16
18
  def extend_timeout(timeout)
17
- item.visibility_timeout = timeout
18
- if timeout > 0
19
- @total_timeout = timeout + (Time.now - start_time).to_i
20
- end
19
+ item.change_visibility({
20
+ visibility_timeout: timeout # required
21
+ })
22
+ @total_timeout = timeout + (Time.now - start_time).to_i if timeout > 0
21
23
  end
22
24
 
23
25
  # We effectively return the item to the queue by setting
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aws-sdk-sqs'
4
+
1
5
  # This queue service is based on aws sqs.
2
6
  # To make this queue service work, one would need the aws sqs gem to be installed.
3
7
  module DispatchRider
@@ -21,8 +25,6 @@ module DispatchRider
21
25
  else
22
26
  raise RecordInvalid.new(self, ["Either name or url have to be specified"])
23
27
  end
24
- rescue NameError
25
- raise AdapterNotFoundError.new(self.class.name, 'aws-sdk')
26
28
  end
27
29
 
28
30
  def pop
@@ -32,6 +34,7 @@ module DispatchRider
32
34
 
33
35
  visibility_timeout_shield(obj) do
34
36
  raise AbortExecution, "false received from handler" unless yield(obj)
37
+
35
38
  obj
36
39
  end
37
40