dispatch-rider 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +21 -0
- data/.rubocop_todo.yml +17 -300
- data/Rakefile +2 -1
- data/dispatch-rider.gemspec +2 -2
- data/lib/dispatch-rider/callbacks/access.rb +2 -0
- data/lib/dispatch-rider/callbacks/storage.rb +7 -5
- data/lib/dispatch-rider/callbacks/support.rb +2 -0
- data/lib/dispatch-rider/callbacks.rb +2 -0
- data/lib/dispatch-rider/command.rb +3 -3
- data/lib/dispatch-rider/configuration.rb +3 -1
- data/lib/dispatch-rider/debug.rb +3 -1
- data/lib/dispatch-rider/demultiplexer.rb +17 -19
- data/lib/dispatch-rider/dispatcher.rb +2 -0
- data/lib/dispatch-rider/error_handlers.rb +3 -1
- data/lib/dispatch-rider/errors.rb +2 -0
- data/lib/dispatch-rider/handlers/base.rb +12 -10
- data/lib/dispatch-rider/handlers/inheritance_tracking.rb +2 -0
- data/lib/dispatch-rider/handlers/named_process.rb +2 -0
- data/lib/dispatch-rider/handlers.rb +2 -0
- data/lib/dispatch-rider/integrations/appsignal.rb +3 -1
- data/lib/dispatch-rider/logging/json_formatter.rb +2 -0
- data/lib/dispatch-rider/logging/lifecycle_logger.rb +2 -0
- data/lib/dispatch-rider/logging/text_formatter.rb +2 -0
- data/lib/dispatch-rider/logging/translator/base_translator.rb +2 -0
- data/lib/dispatch-rider/logging/translator/complete_translator.rb +2 -0
- data/lib/dispatch-rider/logging/translator/error_handler_fail_translator.rb +2 -0
- data/lib/dispatch-rider/logging/translator/fail_translator.rb +2 -0
- data/lib/dispatch-rider/logging/translator/start_translator.rb +2 -0
- data/lib/dispatch-rider/logging/translator/stop_translator.rb +2 -0
- data/lib/dispatch-rider/logging/translator/success_translator.rb +2 -0
- data/lib/dispatch-rider/logging/translator.rb +2 -0
- data/lib/dispatch-rider/logging.rb +2 -0
- data/lib/dispatch-rider/message.rb +3 -0
- data/lib/dispatch-rider/notification_services/aws_sns.rb +5 -3
- data/lib/dispatch-rider/notification_services/base.rb +2 -0
- data/lib/dispatch-rider/notification_services/file_system/channel.rb +2 -0
- data/lib/dispatch-rider/notification_services/file_system/notifier.rb +2 -0
- data/lib/dispatch-rider/notification_services/file_system.rb +3 -1
- data/lib/dispatch-rider/notification_services.rb +2 -0
- data/lib/dispatch-rider/publisher/base.rb +2 -0
- data/lib/dispatch-rider/publisher/configuration/destination.rb +6 -4
- data/lib/dispatch-rider/publisher/configuration/notification_service.rb +4 -2
- data/lib/dispatch-rider/publisher/configuration.rb +2 -0
- data/lib/dispatch-rider/publisher/configuration_reader.rb +2 -0
- data/lib/dispatch-rider/publisher/configuration_support.rb +3 -1
- data/lib/dispatch-rider/publisher.rb +3 -2
- data/lib/dispatch-rider/queue_services/aws_sqs/message_body_extractor.rb +2 -0
- data/lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb +6 -4
- data/lib/dispatch-rider/queue_services/aws_sqs.rb +5 -2
- data/lib/dispatch-rider/queue_services/base.rb +5 -4
- data/lib/dispatch-rider/queue_services/file_system/fs_received_message.rb +5 -3
- data/lib/dispatch-rider/queue_services/file_system/queue.rb +5 -4
- data/lib/dispatch-rider/queue_services/file_system.rb +7 -11
- data/lib/dispatch-rider/queue_services/received_message.rb +3 -1
- data/lib/dispatch-rider/queue_services/simple.rb +5 -7
- data/lib/dispatch-rider/queue_services.rb +2 -0
- data/lib/dispatch-rider/registrars/base.rb +5 -5
- data/lib/dispatch-rider/registrars/file_system_channel.rb +3 -1
- data/lib/dispatch-rider/registrars/handler.rb +3 -1
- data/lib/dispatch-rider/registrars/notification_service.rb +2 -0
- data/lib/dispatch-rider/registrars/publishing_destination.rb +3 -1
- data/lib/dispatch-rider/registrars/queue_service.rb +2 -0
- data/lib/dispatch-rider/registrars/sns_channel.rb +3 -1
- data/lib/dispatch-rider/registrars.rb +2 -0
- data/lib/dispatch-rider/runner.rb +2 -0
- data/lib/dispatch-rider/scheduled_job/migration.rb +2 -0
- data/lib/dispatch-rider/scheduled_job.rb +3 -3
- data/lib/dispatch-rider/subscriber.rb +2 -0
- data/lib/dispatch-rider/version.rb +3 -1
- data/lib/dispatch-rider.rb +3 -1
- data/lib/generators/dispatch_rider/install/install_generator.rb +2 -0
- data/lib/generators/dispatch_rider/install/templates/script/dispatch_rider +1 -0
- data/lib/generators/dispatch_rider/job/dispatch_job_generator.rb +2 -0
- data/spec/factories/messages.rb +4 -1
- data/spec/fixtures/handlers/another_test_handler.rb +2 -0
- data/spec/fixtures/handlers/test_handler.rb +2 -0
- data/spec/integration/logging_spec.rb +2 -0
- data/spec/lib/dispatch-rider/airbrake_error_handler_spec.rb +3 -1
- data/spec/lib/dispatch-rider/callbacks/access_spec.rb +2 -0
- data/spec/lib/dispatch-rider/callbacks/storage_spec.rb +2 -0
- data/spec/lib/dispatch-rider/configuration_spec.rb +3 -1
- data/spec/lib/dispatch-rider/default_error_handler_spec.rb +2 -0
- data/spec/lib/dispatch-rider/demultiplexer_spec.rb +4 -2
- data/spec/lib/dispatch-rider/dispatcher_spec.rb +12 -9
- data/spec/lib/dispatch-rider/handlers/base_spec.rb +2 -0
- data/spec/lib/dispatch-rider/handlers/inheritance_tracking_spec.rb +2 -0
- data/spec/lib/dispatch-rider/logging/json_formatter_spec.rb +2 -0
- data/spec/lib/dispatch-rider/logging/lifecycle_logger_spec.rb +3 -1
- data/spec/lib/dispatch-rider/logging/text_formatter_spec.rb +2 -0
- data/spec/lib/dispatch-rider/logging/translator_spec.rb +2 -0
- data/spec/lib/dispatch-rider/message_spec.rb +7 -5
- data/spec/lib/dispatch-rider/notification_services/aws_sns_spec.rb +2 -0
- data/spec/lib/dispatch-rider/notification_services/base_spec.rb +6 -4
- data/spec/lib/dispatch-rider/notification_services/file_system/channel_spec.rb +2 -0
- data/spec/lib/dispatch-rider/notification_services/file_system/notifier_spec.rb +2 -0
- data/spec/lib/dispatch-rider/notification_services/file_system_spec.rb +2 -0
- data/spec/lib/dispatch-rider/notification_services_spec.rb +2 -0
- data/spec/lib/dispatch-rider/publisher/base_spec.rb +2 -0
- data/spec/lib/dispatch-rider/publisher/configuration/destination_spec.rb +2 -0
- data/spec/lib/dispatch-rider/publisher/configuration/notification_service_spec.rb +2 -0
- data/spec/lib/dispatch-rider/publisher/configuration_reader_spec.rb +3 -1
- data/spec/lib/dispatch-rider/publisher/configuration_spec.rb +3 -1
- data/spec/lib/dispatch-rider/publisher/configuration_support_spec.rb +4 -2
- data/spec/lib/dispatch-rider/publisher_spec.rb +11 -9
- data/spec/lib/dispatch-rider/queue_services/aws_sqs_spec.rb +11 -4
- data/spec/lib/dispatch-rider/queue_services/base_spec.rb +10 -8
- data/spec/lib/dispatch-rider/queue_services/file_system_spec.rb +7 -5
- data/spec/lib/dispatch-rider/queue_services/received_message_spec.rb +2 -0
- data/spec/lib/dispatch-rider/queue_services/simple_spec.rb +6 -4
- data/spec/lib/dispatch-rider/registrars/base_spec.rb +4 -2
- data/spec/lib/dispatch-rider/registrars/file_system_channel_spec.rb +2 -0
- data/spec/lib/dispatch-rider/registrars/handler_spec.rb +2 -0
- data/spec/lib/dispatch-rider/registrars/notification_service_spec.rb +2 -0
- data/spec/lib/dispatch-rider/registrars/publishing_destination_spec.rb +2 -0
- data/spec/lib/dispatch-rider/registrars/queue_service_spec.rb +2 -0
- data/spec/lib/dispatch-rider/registrars/sns_channel_spec.rb +2 -0
- data/spec/lib/dispatch-rider/registrars_spec.rb +2 -0
- data/spec/lib/dispatch-rider/runner_spec.rb +3 -1
- data/spec/lib/dispatch-rider/scheduled_job_spec.rb +2 -0
- data/spec/lib/dispatch-rider/subscriber_spec.rb +6 -3
- data/spec/lib/dispatch-rider_spec.rb +2 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/crashing_handler.rb +2 -0
- data/spec/support/integration_support.rb +2 -0
- data/spec/support/null_logger.rb +2 -0
- data/spec/support/sample_handler.rb +2 -0
- metadata +29 -29
@@ -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(
|
27
|
+
@logger = Logger.new($stderr)
|
26
28
|
@debug = false
|
27
29
|
|
28
30
|
@callbacks.around(:dispatch_message) do |job, message|
|
data/lib/dispatch-rider/debug.rb
CHANGED
@@ -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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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,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(
|
7
|
+
def self.call(_message, exception)
|
6
8
|
raise exception
|
7
9
|
end
|
8
10
|
end
|
@@ -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
|
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
|
-
|
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
|
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
|
# 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 =
|
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 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(
|
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
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
12
|
-
|
13
|
+
name == other.name &&
|
14
|
+
options == other.options
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -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
|
-
|
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
|
|
@@ -78,13 +80,12 @@ module DispatchRider
|
|
78
80
|
end
|
79
81
|
|
80
82
|
def services_and_channels_map(destinations)
|
81
|
-
destinations.
|
83
|
+
destinations.each_with_object({}) do |destination, result|
|
82
84
|
if result.has_key?(destination.service)
|
83
85
|
result[destination.service] << destination.channel
|
84
86
|
else
|
85
87
|
result[destination.service] = [destination.channel]
|
86
88
|
end
|
87
|
-
result
|
88
89
|
end
|
89
90
|
end
|
90
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
|
@@ -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.
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This is the base class that provides the template for all queue services.
|
2
4
|
# The child classes must implement the following methods to become a concrete class :
|
3
5
|
# assign_storage, insert, raw_head, construct_message_from, delete and size.
|
@@ -27,12 +29,11 @@ module DispatchRider
|
|
27
29
|
raise NotImplementedError
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
32
|
#If you pass a block into pop it will wrap the deletion of the message with it's handling
|
32
|
-
def pop
|
33
|
+
def pop
|
33
34
|
received = head
|
34
35
|
if received
|
35
|
-
|
36
|
+
yield(received) && delete(received.item)
|
36
37
|
received
|
37
38
|
end
|
38
39
|
end
|
@@ -41,7 +42,7 @@ module DispatchRider
|
|
41
42
|
raw_item = raw_head
|
42
43
|
raw_item && received_message_for(raw_item)
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
def received_message_for(raw_item)
|
46
47
|
QueueServices::ReceivedMessage.new(construct_message_from(raw_item), raw_item)
|
47
48
|
end
|
@@ -1,18 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DispatchRider
|
2
4
|
module QueueServices
|
3
5
|
class FileSystem < Base
|
4
6
|
class FsReceivedMessage < ReceivedMessage
|
5
7
|
attr_reader :queue
|
6
|
-
|
8
|
+
|
7
9
|
def initialize(message, item, queue)
|
8
10
|
@queue = queue
|
9
11
|
super(message, item)
|
10
12
|
end
|
11
|
-
|
13
|
+
|
12
14
|
def extend_timeout(timeout)
|
13
15
|
#file system doesn't support timeouts on items, so we ignore this.
|
14
16
|
end
|
15
|
-
|
17
|
+
|
16
18
|
def return_to_queue
|
17
19
|
queue.put_back(item)
|
18
20
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This is a queue implementation for the queue service based on file systems
|
2
4
|
module DispatchRider
|
3
5
|
module QueueServices
|
@@ -10,13 +12,14 @@ module DispatchRider
|
|
10
12
|
|
11
13
|
def add(item)
|
12
14
|
name_base = "#{@path}/#{Time.now.to_f}"
|
13
|
-
File.
|
15
|
+
File.write("#{name_base}.inprogress", item)
|
14
16
|
FileUtils.mv("#{name_base}.inprogress", "#{name_base}.ready")
|
15
17
|
end
|
16
18
|
|
17
19
|
def pop
|
18
20
|
file_path = next_item(10)
|
19
21
|
return nil unless file_path
|
22
|
+
|
20
23
|
file_path_inflight = file_path.gsub(/\.ready$/, '.inflight')
|
21
24
|
FileUtils.mv(file_path, file_path_inflight)
|
22
25
|
File.new(file_path_inflight)
|
@@ -32,9 +35,7 @@ module DispatchRider
|
|
32
35
|
File.unlink(item.path)
|
33
36
|
end
|
34
37
|
|
35
|
-
|
36
|
-
file_paths.size
|
37
|
-
end
|
38
|
+
delegate :size, to: :file_paths
|
38
39
|
|
39
40
|
private
|
40
41
|
|