txgh-queue 2.1.0 → 3.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/txgh-queue/application.rb +6 -0
  3. data/lib/txgh-queue/error_handlers/gitlab.rb +39 -0
  4. data/lib/txgh-queue/error_handlers.rb +1 -0
  5. data/lib/txgh-queue/job.rb +20 -3
  6. data/lib/txgh-queue/supervisor.rb +1 -0
  7. data/lib/txgh-queue/version.rb +1 -1
  8. data/lib/txgh-queue/webhooks/gitlab/request_handler.rb +26 -0
  9. data/lib/txgh-queue/webhooks/gitlab.rb +7 -0
  10. data/lib/txgh-queue/webhooks.rb +1 -0
  11. data/spec/application_spec.rb +34 -4
  12. data/spec/backends/sqs/config_spec.rb +4 -6
  13. data/spec/backends/sqs/consumer_spec.rb +3 -6
  14. data/spec/backends/sqs/history_sequence_spec.rb +1 -4
  15. data/spec/backends/sqs/job_spec.rb +21 -24
  16. data/spec/backends/sqs/message_attributes_spec.rb +3 -6
  17. data/spec/backends/sqs/producer_spec.rb +1 -3
  18. data/spec/backends/sqs/queue_spec.rb +1 -3
  19. data/spec/backends/sqs/retry_logic_spec.rb +11 -14
  20. data/spec/backends/sqs_spec.rb +5 -7
  21. data/spec/backends_spec.rb +1 -3
  22. data/spec/error_handlers/github_spec.rb +2 -4
  23. data/spec/error_handlers/gitlab_spec.rb +39 -0
  24. data/spec/error_handlers/network_errors_spec.rb +5 -7
  25. data/spec/error_handlers/server_response_spec.rb +5 -7
  26. data/spec/error_handlers/standard_errors_spec.rb +3 -5
  27. data/spec/error_handlers/transifex_spec.rb +4 -6
  28. data/spec/error_handlers/txgh_errors_spec.rb +1 -3
  29. data/spec/job_spec.rb +6 -8
  30. data/spec/result_spec.rb +3 -5
  31. data/spec/status_spec.rb +1 -3
  32. data/spec/supervisor_spec.rb +6 -8
  33. data/spec/webhooks/github/request_handler_spec.rb +6 -8
  34. data/spec/webhooks/gitlab/request_handler_spec.rb +144 -0
  35. data/spec/webhooks/transifex/request_handler_spec.rb +1 -3
  36. data/txgh-queue.gemspec +2 -3
  37. metadata +15 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 182f92ae726c4dd56d50d53ae0f5cae3bcfae7f44ee675783a5153b2b084f4cf
4
- data.tar.gz: 14bda789ede5a1f337c6c4bd708681b8f5958f279d5b01d71214f52fa737bfea
3
+ metadata.gz: 898748f4ec7487c2ae896e41379a004b090ec31ba2fa0aa974ab07d078a4fe10
4
+ data.tar.gz: 32426a63ef5e8d3f2ab102803576134d76ff17a1c84dff25dd2fd278a5dfb320
5
5
  SHA512:
6
- metadata.gz: 11476fc78f162f70a3c4331aac64d4eec1d80101462cd30a29f1efd4e65af4cbd66be23aaafb80fc018347635789ab4dbc6ab95ba22b656c12769bc4265dcc1d
7
- data.tar.gz: 6ac7cb8a9d890cb72407882fe2265b8abe9e2f61c958d7345c6d94ec1ea8b371545caa0afebec96c2ab19ccdf7c4db2db31d91673ec44b12c9a3fbf3089d8af9
6
+ metadata.gz: 44c5160910ca4c90831ccc14dd9060c8ea0200871f8b85a6c1345886e492bcf60eae1ee43f82ce30b204fad762399f83bef5483cf8c53104f3c8e2113c2c9929
7
+ data.tar.gz: f80f1c7446514a967f93b4a79669cfaadf0905207c8f1552a0b87bba2e2466dda8eea4b9c6e643929aea22ab325beb8d65a826b671244a2ee2d901da85dde343
@@ -31,5 +31,11 @@ module TxghQueue
31
31
  Github::RequestHandler.handle_request(request, settings.logger)
32
32
  )
33
33
  end
34
+
35
+ post '/gitlab/enqueue' do
36
+ respond_with(
37
+ Gitlab::RequestHandler.handle_request(request, settings.logger)
38
+ )
39
+ end
34
40
  end
35
41
  end
@@ -0,0 +1,39 @@
1
+ require 'gitlab'
2
+
3
+ module TxghQueue
4
+ module ErrorHandlers
5
+ class Gitlab
6
+ # https://github.com/NARKOZ/gitlab/blob/master/lib/gitlab/error.rb
7
+ ERROR_CLASSES = {
8
+ ::Gitlab::Error::BadGateway => Status.retry_without_delay,
9
+ ::Gitlab::Error::BadRequest => Status.fail,
10
+ ::Gitlab::Error::Conflict => Status.fail,
11
+ ::Gitlab::Error::Forbidden => Status.fail,
12
+ ::Gitlab::Error::InternalServerError => Status.retry_with_delay,
13
+ ::Gitlab::Error::MethodNotAllowed => Status.fail,
14
+ ::Gitlab::Error::NotAcceptable => Status.fail,
15
+ ::Gitlab::Error::NotFound => Status.fail,
16
+ ::Gitlab::Error::ServiceUnavailable => Status.retry_with_delay,
17
+ ::Gitlab::Error::TooManyRequests => Status.retry_with_delay,
18
+ ::Gitlab::Error::Unauthorized => Status.fail,
19
+ ::Gitlab::Error::Unprocessable => Status.fail
20
+ }
21
+
22
+ class << self
23
+ def can_handle?(error_or_response)
24
+ error_or_response.is_a?(::Gitlab::Error::Error)
25
+ end
26
+
27
+ def status_for(error)
28
+ ERROR_CLASSES.fetch(error.class) { handle_other(error) }
29
+ end
30
+
31
+ private
32
+
33
+ def handle_other(error)
34
+ Status.fail
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,6 +1,7 @@
1
1
  module TxghQueue
2
2
  module ErrorHandlers
3
3
  autoload :Github, 'txgh-queue/error_handlers/github'
4
+ autoload :Gitlab, 'txgh-queue/error_handlers/gitlab'
4
5
  autoload :NetworkErrors, 'txgh-queue/error_handlers/network_errors'
5
6
  autoload :ServerResponse, 'txgh-queue/error_handlers/server_response'
6
7
  autoload :StandardErrors, 'txgh-queue/error_handlers/standard_errors'
@@ -4,6 +4,7 @@ require 'txgh-server'
4
4
  module TxghQueue
5
5
  class Job
6
6
  Github = TxghServer::Webhooks::Github
7
+ Gitlab = TxghServer::Webhooks::Gitlab
7
8
  Transifex = TxghServer::Webhooks::Transifex
8
9
  include TxghServer::ResponseHelpers
9
10
 
@@ -16,7 +17,7 @@ module TxghQueue
16
17
  def process(payload)
17
18
  Supervisor.supervise do
18
19
  case payload.fetch('txgh_event')
19
- when 'github.push', 'github.delete', 'transifex.hook'
20
+ when 'github.push', 'github.delete', 'gitlab.push', 'gitlab.delete', 'transifex.hook'
20
21
  handle_expected(payload)
21
22
  else
22
23
  handle_unexpected
@@ -29,13 +30,17 @@ module TxghQueue
29
30
  def handle_expected(payload)
30
31
  config = config_from(payload)
31
32
  project = config.transifex_project
32
- repo = config.github_repo
33
+ repo = config.git_repo
33
34
 
34
35
  case payload.fetch('txgh_event')
35
36
  when 'github.push'
36
37
  handle_github_push(project, repo, payload)
37
38
  when 'github.delete'
38
39
  handle_github_delete(project, repo, payload)
40
+ when 'gitlab.push'
41
+ handle_gitlab_push(project, repo, payload)
42
+ when 'gitlab.delete'
43
+ handle_gitlab_delete(project, repo, payload)
39
44
  when 'transifex.hook'
40
45
  handle_transifex_hook(project, repo, payload)
41
46
  end
@@ -43,7 +48,7 @@ module TxghQueue
43
48
 
44
49
  def config_from(payload)
45
50
  case payload.fetch('txgh_event')
46
- when 'github.push', 'github.delete'
51
+ when 'github.push', 'github.delete', 'gitlab.push', 'gitlab.delete'
47
52
  Txgh::Config::KeyManager.config_from_repo(payload.fetch('repo_name'))
48
53
  when 'transifex.hook'
49
54
  Txgh::Config::KeyManager.config_from_project(payload.fetch('project'))
@@ -62,6 +67,18 @@ module TxghQueue
62
67
  execute(handler)
63
68
  end
64
69
 
70
+ def handle_gitlab_push(project, repo, payload)
71
+ attributes = TxghServer::Webhooks::Gitlab::PushAttributes.new(payload)
72
+ handler = TxghServer::Webhooks::Gitlab::PushHandler.new(project, repo, logger, attributes)
73
+ execute(handler)
74
+ end
75
+
76
+ def handle_gitlab_delete(project, repo, payload)
77
+ attributes = Gitlab::DeleteAttributes.new(payload)
78
+ handler = Gitlab::DeleteHandler.new(project, repo, logger, attributes)
79
+ execute(handler)
80
+ end
81
+
65
82
  def handle_transifex_hook(project, repo, payload)
66
83
  handler = Transifex::HookHandler.new(
67
84
  project: project,
@@ -11,6 +11,7 @@ module TxghQueue
11
11
  ERROR_HANDLERS = [
12
12
  ErrorHandlers::ServerResponse,
13
13
  ErrorHandlers::Github,
14
+ ErrorHandlers::Gitlab,
14
15
  ErrorHandlers::Transifex,
15
16
  ErrorHandlers::TxghErrors,
16
17
  ErrorHandlers::StandardErrors,
@@ -1,3 +1,3 @@
1
1
  module TxghQueue
2
- VERSION = '2.1.0'
2
+ VERSION = '3.0.0.beta'
3
3
  end
@@ -0,0 +1,26 @@
1
+ require 'txgh-server'
2
+
3
+ module TxghQueue
4
+ module Webhooks
5
+ module Gitlab
6
+ class RequestHandler < ::TxghServer::Webhooks::Gitlab::RequestHandler
7
+ def handle_request
8
+ handle_safely do
9
+ case gitlab_event
10
+ when 'Push Hook'
11
+ txgh_event = delete_event? ? 'gitlab.delete' : 'gitlab.push'
12
+
13
+ result = ::TxghQueue::Config.backend
14
+ .producer_for(txgh_event, logger)
15
+ .enqueue(attributes.to_h.merge(txgh_event: txgh_event))
16
+
17
+ respond_with(202, result.to_json)
18
+ else
19
+ respond_with_error(400, "Event '#{gitlab_event}' cannot be enqueued")
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module TxghQueue
2
+ module Webhooks
3
+ module Gitlab
4
+ autoload :RequestHandler, 'txgh-queue/webhooks/gitlab/request_handler'
5
+ end
6
+ end
7
+ end
@@ -1,6 +1,7 @@
1
1
  module TxghQueue
2
2
  module Webhooks
3
3
  autoload :Github, 'txgh-queue/webhooks/github'
4
+ autoload :Gitlab, 'txgh-queue/webhooks/gitlab'
4
5
  autoload :Transifex, 'txgh-queue/webhooks/transifex'
5
6
  end
6
7
  end
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
  require 'rack/test'
3
3
 
4
4
  require 'helpers/github_payload_builder'
5
+ require 'helpers/gitlab_payload_builder'
5
6
  require 'helpers/standard_txgh_setup'
6
7
 
7
8
  describe TxghQueue::WebhookEndpoints, auto_configure: true do
@@ -14,7 +15,7 @@ describe TxghQueue::WebhookEndpoints, auto_configure: true do
14
15
  end
15
16
 
16
17
  let(:config) do
17
- Txgh::Config::ConfigPair.new(project_config, repo_config)
18
+ Txgh::Config::ConfigPair.new(project_config, github_config)
18
19
  end
19
20
 
20
21
  let(:backend) { TxghQueue::Config.backend }
@@ -75,7 +76,7 @@ describe TxghQueue::WebhookEndpoints, auto_configure: true do
75
76
  header(
76
77
  TxghServer::GithubRequestAuth::GITHUB_HEADER,
77
78
  TxghServer::GithubRequestAuth.compute_signature(
78
- body, config.github_repo.webhook_secret
79
+ body, config.git_repo.webhook_secret
79
80
  )
80
81
  )
81
82
  end
@@ -83,7 +84,7 @@ describe TxghQueue::WebhookEndpoints, auto_configure: true do
83
84
  let(:producer) { backend.producer_for('github.push') }
84
85
 
85
86
  it 'enqueues a new job' do
86
- payload = GithubPayloadBuilder.push_payload(repo_name, ref)
87
+ payload = GithubPayloadBuilder.push_payload(github_repo_name, ref)
87
88
  payload.add_commit
88
89
 
89
90
  sign_with payload.to_json
@@ -99,7 +100,36 @@ describe TxghQueue::WebhookEndpoints, auto_configure: true do
99
100
  expect(job[:payload]).to include(
100
101
  event: 'push',
101
102
  txgh_event: 'github.push',
102
- repo_name: repo_name,
103
+ repo_name: github_repo_name,
104
+ ref: "refs/#{ref}"
105
+ )
106
+ end
107
+ end
108
+
109
+ describe '/gitlab/enqueue' do
110
+ let(:producer) { backend.producer_for('gitlab.push') }
111
+ let(:config) do
112
+ Txgh::Config::ConfigPair.new(project_config, gitlab_config)
113
+ end
114
+
115
+ it 'enqueues a new job' do
116
+ payload = GitlabPayloadBuilder.push_payload(gitlab_repo_name, ref)
117
+ payload.add_commit
118
+
119
+ header 'X-GitLab-Event', 'Push Hook'
120
+ header 'X-Gitlab-Token', config.git_repo.webhook_secret
121
+
122
+ expect { post '/gitlab/enqueue', payload.to_json }.to(
123
+ change { producer.enqueued_jobs.size }.from(0).to(1)
124
+ )
125
+
126
+ expect(last_response).to be_accepted
127
+
128
+ job = producer.enqueued_jobs.first
129
+ expect(job[:payload]).to include(
130
+ event: 'push',
131
+ txgh_event: 'gitlab.push',
132
+ repo_name: gitlab_repo_name.split('/').last,
103
133
  ref: "refs/#{ref}"
104
134
  )
105
135
  end
@@ -1,21 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
- include TxghQueue::Backends
4
-
5
- describe Sqs::Config, auto_configure: true do
3
+ describe TxghQueue::Backends::Sqs::Config, auto_configure: true do
6
4
  let(:queue_config) { sqs_queue_config }
7
5
 
8
6
  describe '.queues' do
9
7
  it 'lists all queues' do
10
8
  queues = described_class.queues
11
- queues.each { |q| expect(q).to be_a(Sqs::Queue) }
9
+ queues.each { |q| expect(q).to be_a(TxghQueue::Backends::Sqs::Queue) }
12
10
  expect(queues.map(&:name).sort).to eq(%w(test-queue test-queue-2))
13
11
  end
14
12
  end
15
13
 
16
14
  describe '.failure_queue' do
17
15
  it 'returns the failure queue' do
18
- expect(described_class.failure_queue).to be_a(Sqs::Queue)
16
+ expect(described_class.failure_queue).to be_a(TxghQueue::Backends::Sqs::Queue)
19
17
  expect(described_class.failure_queue.name).to eq('test-failure-queue')
20
18
  end
21
19
  end
@@ -23,7 +21,7 @@ describe Sqs::Config, auto_configure: true do
23
21
  describe '.get_queue' do
24
22
  it 'pulls out a single queue object' do
25
23
  queue = described_class.get_queue('test-queue')
26
- expect(queue).to be_a(Sqs::Queue)
24
+ expect(queue).to be_a(TxghQueue::Backends::Sqs::Queue)
27
25
  expect(queue.name).to eq('test-queue')
28
26
  end
29
27
  end
@@ -1,12 +1,9 @@
1
1
  require 'spec_helper'
2
2
  require 'helpers/sqs/sqs_test_message'
3
3
 
4
- include TxghQueue
5
- include TxghQueue::Backends
6
-
7
- describe Sqs::Consumer, auto_configure: true do
4
+ describe TxghQueue::Backends::Sqs::Consumer, auto_configure: true do
8
5
  let(:queue_config) { sqs_queue_config }
9
- let(:queues) { Sqs::Config.queues }
6
+ let(:queues) { TxghQueue::Backends::Sqs::Config.queues }
10
7
  let(:logger) { NilLogger.new }
11
8
  let(:message) { SqsTestMessage.new('abc123', '{}') }
12
9
  let(:consumer) { described_class.new(queues, logger) }
@@ -16,7 +13,7 @@ describe Sqs::Consumer, auto_configure: true do
16
13
  job = double(:Job)
17
14
  expect(queue).to receive(:receive_message).and_return(message.to_bundle)
18
15
  expect(job).to receive(:complete)
19
- expect(Sqs::Job).to(
16
+ expect(TxghQueue::Backends::Sqs::Job).to(
20
17
  receive(:new).with(message, queue, logger).and_return(job)
21
18
  )
22
19
  end
@@ -1,10 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'helpers/sqs/sqs_test_message'
3
3
 
4
- include TxghQueue
5
- include TxghQueue::Backends
6
-
7
- describe Sqs::HistorySequence do
4
+ describe TxghQueue::Backends::Sqs::HistorySequence do
8
5
  let(:message) { SqsTestMessage.new('abc123', '{}', attributes_hash) }
9
6
  let(:attributes_hash) do
10
7
  {
@@ -1,13 +1,10 @@
1
1
  require 'spec_helper'
2
2
  require 'helpers/sqs/sqs_test_message'
3
3
 
4
- include TxghQueue
5
- include TxghQueue::Backends
6
-
7
- describe Sqs::Job, auto_configure: true do
4
+ describe TxghQueue::Backends::Sqs::Job, auto_configure: true do
8
5
  let(:queue_config) { sqs_queue_config }
9
- let(:queue) { Sqs::Config.queues.first }
10
- let(:failure_queue) { Sqs::Config.failure_queue }
6
+ let(:queue) { TxghQueue::Backends::Sqs::Config.queues.first }
7
+ let(:failure_queue) { TxghQueue::Backends::Sqs::Config.failure_queue }
11
8
  let(:logger) { NilLogger.new }
12
9
  let(:body) { { 'foo' => 'bar' } }
13
10
  let(:message) { SqsTestMessage.new('123abc', body.to_json) }
@@ -18,12 +15,12 @@ describe Sqs::Job, auto_configure: true do
18
15
  it 'updates the history sequence with failure details for an exception' do
19
16
  error = StandardError.new('foobar')
20
17
  error.set_backtrace('path/to/file.rb:10')
21
- result = Result.new(status, error)
18
+ result = TxghQueue::Result.new(status, error)
22
19
  expect(job).to receive(:process).with(body).and_return(result)
23
20
 
24
21
  # this call to send_message signifies a retry
25
22
  expect(send(queue_sym)).to receive(:send_message) do |body, attributes|
26
- message_attributes = Sqs::MessageAttributes.from_h(attributes[:message_attributes])
23
+ message_attributes = TxghQueue::Backends::Sqs::MessageAttributes.from_h(attributes[:message_attributes])
27
24
  current_retry = message_attributes.history_sequence.current
28
25
  expect(current_retry).to include(
29
26
  response_type: 'error',
@@ -40,12 +37,12 @@ describe Sqs::Job, auto_configure: true do
40
37
 
41
38
  it 'updates the history sequence with failure details for a txgh response' do
42
39
  response = TxghServer::Response.new(502, 'Bad gateway')
43
- result = Result.new(status, response)
40
+ result = TxghQueue::Result.new(status, response)
44
41
  expect(job).to receive(:process).with(body).and_return(result)
45
42
 
46
43
  # this call to send_message signifies a retry
47
44
  expect(send(queue_sym)).to receive(:send_message) do |body, attributes|
48
- message_attributes = Sqs::MessageAttributes.from_h(attributes[:message_attributes])
45
+ message_attributes = TxghQueue::Backends::Sqs::MessageAttributes.from_h(attributes[:message_attributes])
49
46
  current_retry = message_attributes.history_sequence.current
50
47
  expect(current_retry).to include(
51
48
  response_type: 'response',
@@ -62,7 +59,7 @@ describe Sqs::Job, auto_configure: true do
62
59
 
63
60
  describe '#complete' do
64
61
  it 'processes a single job and deletes the message' do
65
- result = Result.new(Status.ok, TxghServer::Response.new(200, 'Ok'))
62
+ result = TxghQueue::Result.new(TxghQueue::Status.ok, TxghServer::Response.new(200, 'Ok'))
66
63
  expect(queue).to receive(:delete_message).with(message.receipt_handle)
67
64
  expect(job).to receive(:process).with(body).and_return(result)
68
65
  job.complete
@@ -70,7 +67,7 @@ describe Sqs::Job, auto_configure: true do
70
67
 
71
68
  context 'error reporting' do
72
69
  let(:error) { StandardError.new('jelly beans') }
73
- let(:result) { Result.new(Status.fail, error) }
70
+ let(:result) { TxghQueue::Result.new(TxghQueue::Status.fail, error) }
74
71
 
75
72
  before(:each) do
76
73
  expect(job).to receive(:process).and_return(result)
@@ -93,7 +90,7 @@ describe Sqs::Job, auto_configure: true do
93
90
  it 'includes error tracking details returned from publishing the event' do
94
91
  expect(Txgh.events).to receive(:publish_error).and_return(foo: 'bar')
95
92
  expect(failure_queue).to receive(:send_message) do |body, attributes|
96
- message_attributes = Sqs::MessageAttributes.from_h(attributes[:message_attributes])
93
+ message_attributes = TxghQueue::Backends::Sqs::MessageAttributes.from_h(attributes[:message_attributes])
97
94
  current_retry = message_attributes.history_sequence.current
98
95
  expect(current_retry).to include(error_tracking: { foo: 'bar' })
99
96
  end
@@ -112,12 +109,12 @@ describe Sqs::Job, auto_configure: true do
112
109
 
113
110
  it 're-enqueues the message if told to retry' do
114
111
  response = TxghServer::Response.new(502, 'Bad gateway')
115
- result = Result.new(Status.retry_without_delay, response)
112
+ result = TxghQueue::Result.new(TxghQueue::Status.retry_without_delay, response)
116
113
  expect(job).to receive(:process).with(body).and_return(result)
117
114
 
118
115
  # this call to send_message signifies a retry
119
116
  expect(queue).to receive(:send_message) do |body, attributes|
120
- message_attributes = Sqs::MessageAttributes.from_h(attributes[:message_attributes])
117
+ message_attributes = TxghQueue::Backends::Sqs::MessageAttributes.from_h(attributes[:message_attributes])
121
118
  history_sequence = message_attributes.history_sequence.sequence.map { |elem| elem[:status] }
122
119
  expect(history_sequence).to eq(%w(retry_without_delay))
123
120
  new_message
@@ -128,17 +125,17 @@ describe Sqs::Job, auto_configure: true do
128
125
 
129
126
  it 're-enqueues with delay if told to do so' do
130
127
  response = TxghServer::Response.new(502, 'Bad gateway')
131
- result = Result.new(Status.retry_with_delay, response)
128
+ result = TxghQueue::Result.new(TxghQueue::Status.retry_with_delay, response)
132
129
  expect(job).to receive(:process).with(body).and_return(result)
133
130
 
134
131
  # this call to send_message signifies a retry
135
132
  expect(queue).to receive(:send_message) do |body, attributes|
136
- message_attributes = Sqs::MessageAttributes.from_h(attributes[:message_attributes])
133
+ message_attributes = TxghQueue::Backends::Sqs::MessageAttributes.from_h(attributes[:message_attributes])
137
134
  history_sequence = message_attributes.history_sequence.sequence.map { |elem| elem[:status] }
138
135
  expect(history_sequence).to eq(%w(retry_with_delay))
139
136
 
140
137
  expect(attributes[:delay_seconds]).to eq(
141
- Sqs::RetryLogic::DELAY_INTERVALS.first
138
+ TxghQueue::Backends::Sqs::RetryLogic::DELAY_INTERVALS.first
142
139
  )
143
140
 
144
141
  new_message
@@ -151,7 +148,7 @@ describe Sqs::Job, auto_configure: true do
151
148
  let(:message) do
152
149
  SqsTestMessage.new('123abc', body.to_json, {
153
150
  'history_sequence' => {
154
- 'string_value' => (Sqs::RetryLogic::OVERALL_MAX_RETRIES - 1).times.map do
151
+ 'string_value' => (TxghQueue::Backends::Sqs::RetryLogic::OVERALL_MAX_RETRIES - 1).times.map do
155
152
  { status: 'retry_without_delay' }
156
153
  end.to_json
157
154
  }
@@ -160,15 +157,15 @@ describe Sqs::Job, auto_configure: true do
160
157
 
161
158
  it 'deletes the message and adds it to the failure queue' do
162
159
  response = TxghServer::Response.new(502, 'Bad gateway')
163
- result = Result.new(Status.retry_with_delay, response)
160
+ result = TxghQueue::Result.new(TxghQueue::Status.retry_with_delay, response)
164
161
  expect(job).to receive(:process).with(body).and_return(result)
165
162
  expect(failure_queue).to receive(:send_message).and_return(new_message)
166
163
  job.complete
167
164
  end
168
165
  end
169
166
 
170
- it_behaves_like "it updates the message's history sequence", Status.retry_without_delay, :queue
171
- it_behaves_like "it updates the message's history sequence", Status.retry_with_delay, :queue
167
+ it_behaves_like "it updates the message's history sequence", TxghQueue::Status.retry_without_delay, :queue
168
+ it_behaves_like "it updates the message's history sequence", TxghQueue::Status.retry_with_delay, :queue
172
169
  end
173
170
 
174
171
  context 'failures' do
@@ -177,13 +174,13 @@ describe Sqs::Job, auto_configure: true do
177
174
  end
178
175
 
179
176
  it 'sends the message to the failure queue' do
180
- result = Result.new(Status.fail, TxghServer::Response.new(500, '💩'))
177
+ result = TxghQueue::Result.new(TxghQueue::Status.fail, TxghServer::Response.new(500, '💩'))
181
178
  expect(failure_queue).to receive(:send_message).with(body.to_json, anything)
182
179
  expect(job).to receive(:process).with(body).and_return(result)
183
180
  job.complete
184
181
  end
185
182
 
186
- it_behaves_like "it updates the message's history sequence", Status.fail, :failure_queue
183
+ it_behaves_like "it updates the message's history sequence", TxghQueue::Status.fail, :failure_queue
187
184
  end
188
185
  end
189
186
  end
@@ -2,10 +2,7 @@ require 'spec_helper'
2
2
  require 'helpers/sqs/sqs_test_message'
3
3
  require 'json'
4
4
 
5
- include TxghQueue
6
- include TxghQueue::Backends
7
-
8
- describe Sqs::MessageAttributes do
5
+ describe TxghQueue::Backends::Sqs::MessageAttributes do
9
6
  let(:message) { SqsTestMessage.new('abc123', '{}', attributes_hash) }
10
7
  let(:attributes_hash) do
11
8
  {
@@ -20,7 +17,7 @@ describe Sqs::MessageAttributes do
20
17
  describe '.from_message' do
21
18
  it 'extracts the history sequence from the message attributes' do
22
19
  attributes = described_class.from_message(message)
23
- expect(attributes.history_sequence).to be_a(Sqs::HistorySequence)
20
+ expect(attributes.history_sequence).to be_a(TxghQueue::Backends::Sqs::HistorySequence)
24
21
  expect(attributes.history_sequence.sequence.first[:status]).to(
25
22
  eq('retry_without_delay')
26
23
  )
@@ -30,7 +27,7 @@ describe Sqs::MessageAttributes do
30
27
  describe '.from_h' do
31
28
  it 'creates the history sequence from the hash elements' do
32
29
  attributes = described_class.from_h(attributes_hash)
33
- expect(attributes.history_sequence).to be_a(Sqs::HistorySequence)
30
+ expect(attributes.history_sequence).to be_a(TxghQueue::Backends::Sqs::HistorySequence)
34
31
  expect(attributes.history_sequence.sequence.first[:status]).to(
35
32
  eq('retry_without_delay')
36
33
  )
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'securerandom'
3
3
 
4
- include TxghQueue::Backends
5
-
6
- describe Sqs::Producer, auto_configure: true do
4
+ describe TxghQueue::Backends::Sqs::Producer, auto_configure: true do
7
5
  let(:queue_config) { sqs_queue_config }
8
6
  let(:logger) { NilLogger.new }
9
7
  let(:queues) { TxghQueue::Backends::Sqs::Config.queues }
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- include TxghQueue::Backends
4
-
5
- describe Sqs::Queue do
3
+ describe TxghQueue::Backends::Sqs::Queue do
6
4
  let(:options) { { name: 'test-queue', region: 'us-east-1', events: %w(a b c) } }
7
5
  let(:queue) { described_class.new(options) }
8
6
 
@@ -1,16 +1,13 @@
1
1
  require 'spec_helper'
2
2
  require 'helpers/sqs/sqs_test_message'
3
3
 
4
- include TxghQueue
5
- include TxghQueue::Backends
6
-
7
- describe Sqs::RetryLogic do
4
+ describe TxghQueue::Backends::Sqs::RetryLogic do
8
5
  context 'with overall retries exceeded' do
9
6
  let(:logic) { described_class.new(message_attributes, current_status) }
10
- let(:current_status) { Status.retry_without_delay }
7
+ let(:current_status) { TxghQueue::Status.retry_without_delay }
11
8
  let(:message) { SqsTestMessage.new('abc123', '{}', message_attributes.to_h) }
12
9
  let(:message_attributes) do
13
- Sqs::MessageAttributes.from_h(
10
+ TxghQueue::Backends::Sqs::MessageAttributes.from_h(
14
11
  history_sequence: {
15
12
  string_value: described_class::OVERALL_MAX_RETRIES.times.map do
16
13
  { status: 'retry_without_delay' }
@@ -33,23 +30,23 @@ describe Sqs::RetryLogic do
33
30
 
34
31
  describe '#next_delay_seconds' do
35
32
  it 'raises an error' do
36
- expect { logic.next_delay_seconds }.to raise_error(Sqs::RetriesExceededError)
33
+ expect { logic.next_delay_seconds }.to raise_error(TxghQueue::Backends::Sqs::RetriesExceededError)
37
34
  end
38
35
  end
39
36
 
40
37
  describe '#sqs_retry_params' do
41
38
  it 'raises an error' do
42
- expect { logic.sqs_retry_params }.to raise_error(Sqs::RetriesExceededError)
39
+ expect { logic.sqs_retry_params }.to raise_error(TxghQueue::Backends::Sqs::RetriesExceededError)
43
40
  end
44
41
  end
45
42
  end
46
43
 
47
44
  context 'with a run of no-delay retries' do
48
45
  let(:logic) { described_class.new(message_attributes, current_status) }
49
- let(:current_status) { Status.retry_without_delay }
46
+ let(:current_status) { TxghQueue::Status.retry_without_delay }
50
47
  let(:message) { SqsTestMessage.new('abc123', '{}', message_attributes.to_h) }
51
48
  let(:message_attributes) do
52
- Sqs::MessageAttributes.from_h(
49
+ TxghQueue::Backends::Sqs::MessageAttributes.from_h(
53
50
  history_sequence: {
54
51
  string_value: [
55
52
  { status: 'retry_without_delay' },
@@ -87,7 +84,7 @@ describe Sqs::RetryLogic do
87
84
  end
88
85
 
89
86
  context 'and a delayed current status' do
90
- let(:current_status) { Status.retry_with_delay }
87
+ let(:current_status) { TxghQueue::Status.retry_with_delay }
91
88
 
92
89
  describe '#next_delay_seconds' do
93
90
  it 'indicates a first-stage delay' do
@@ -101,10 +98,10 @@ describe Sqs::RetryLogic do
101
98
 
102
99
  context 'with a run of delayed retries' do
103
100
  let(:logic) { described_class.new(message_attributes, current_status) }
104
- let(:current_status) { Status.retry_with_delay }
101
+ let(:current_status) { TxghQueue::Status.retry_with_delay }
105
102
  let(:message) { SqsTestMessage.new('abc123', '{}', message_attributes.to_h) }
106
103
  let(:message_attributes) do
107
- Sqs::MessageAttributes.from_h(
104
+ TxghQueue::Backends::Sqs::MessageAttributes.from_h(
108
105
  history_sequence: {
109
106
  string_value: [
110
107
  { status: 'retry_with_delay' },
@@ -145,7 +142,7 @@ describe Sqs::RetryLogic do
145
142
  end
146
143
 
147
144
  context 'and a non-delayed current status' do
148
- let(:current_status) { Status.retry_without_delay }
145
+ let(:current_status) { TxghQueue::Status.retry_without_delay }
149
146
 
150
147
  describe '#next_delay_seconds' do
151
148
  it 'indicates no delay' do
@@ -1,16 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
- include TxghQueue::Backends
4
-
5
- describe Sqs, auto_configure: true do
3
+ describe TxghQueue::Backends::Sqs, auto_configure: true do
6
4
  let(:queue_config) { sqs_queue_config }
7
5
 
8
6
  describe '.producer_for' do
9
7
  it 'looks up the queues for the given event and returns a producer object' do
10
8
  producer = described_class.producer_for('a')
11
- expect(producer).to be_a(Sqs::Producer)
9
+ expect(producer).to be_a(TxghQueue::Backends::Sqs::Producer)
12
10
  expect(producer.queues.size).to eq(1)
13
- expect(producer.queues.first).to be_a(Sqs::Queue)
11
+ expect(producer.queues.first).to be_a(TxghQueue::Backends::Sqs::Queue)
14
12
  expect(producer.queues.first.name).to eq('test-queue')
15
13
  end
16
14
 
@@ -30,9 +28,9 @@ describe Sqs, auto_configure: true do
30
28
  describe '.consumer_for' do
31
29
  it 'looks up the queue for the given event and returns a consumer object' do
32
30
  consumer = described_class.consumer_for('b')
33
- expect(consumer).to be_a(Sqs::Consumer)
31
+ expect(consumer).to be_a(TxghQueue::Backends::Sqs::Consumer)
34
32
  expect(consumer.queues.size).to eq(1)
35
- expect(consumer.queues.first).to be_a(Sqs::Queue)
33
+ expect(consumer.queues.first).to be_a(TxghQueue::Backends::Sqs::Queue)
36
34
  expect(consumer.queues.first.name).to eq('test-queue')
37
35
  end
38
36