asyncapi-server 1.1.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +5 -5
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +39 -2
  4. data/app/controllers/asyncapi/server/v1/jobs_controller.rb +2 -1
  5. data/app/serializers/asyncapi/server/job_serializer.rb +1 -1
  6. data/app/workers/asyncapi/server/job_status_notifier_worker.rb +51 -0
  7. data/app/workers/asyncapi/server/job_worker.rb +16 -18
  8. data/db/migrate/20141112034324_create_asyncapi_server_jobs.rb +1 -1
  9. data/db/migrate/20141212064931_add_secret_to_asyncapi_server_job.rb +1 -1
  10. data/db/migrate/20150130062520_add_expired_at_to_asyncapi_server_job.rb +1 -1
  11. data/db/migrate/20150201231018_drop_expired_at_from_asyncapi_server_jobs.rb +1 -1
  12. data/lib/asyncapi/server.rb +3 -0
  13. data/lib/asyncapi/server/rails_ext/controller.rb +3 -1
  14. data/lib/asyncapi/server/rspec.rb +20 -7
  15. data/lib/asyncapi/server/version.rb +1 -1
  16. data/spec/controllers/asyncapi/server/v1/jobs_controller_spec.rb +4 -4
  17. data/spec/dummy/db/development.sqlite3 +0 -0
  18. data/spec/dummy/db/schema.rb +2 -2
  19. data/spec/dummy/db/test.sqlite3 +0 -0
  20. data/spec/dummy/log/development.log +81 -0
  21. data/spec/dummy/log/test.log +2011 -0
  22. data/spec/models/job_spec.rb +1 -1
  23. data/spec/requests/enqueueing_jobs_spec.rb +10 -19
  24. data/spec/serializers/job_serializer_spec.rb +1 -0
  25. data/spec/spec_helper.rb +5 -4
  26. data/spec/workers/job_status_notifier_worker_spec.rb +115 -0
  27. data/spec/workers/job_worker_spec.rb +9 -30
  28. metadata +91 -47
  29. data/spec/dummy/db/migrate/20141212065005_create_asyncapi_server_jobs.asyncapi_server.rb +0 -11
  30. data/spec/dummy/db/migrate/20141212065006_add_secret_to_asyncapi_server_job.asyncapi_server.rb +0 -6
  31. data/spec/dummy/db/migrate/20150130062901_add_expired_at_to_asyncapi_server_job.asyncapi_server.rb +0 -12
  32. data/spec/dummy/db/migrate/20150201231329_drop_expired_at_from_asyncapi_server_jobs.asyncapi_server.rb +0 -10
@@ -20,7 +20,7 @@ module Asyncapi
20
20
  its(:status) { is_expected.to eq "queued" }
21
21
  its(:callback_url) { is_expected.to eq "http://callback_url.com" }
22
22
  its(:class_name) { is_expected.to eq "CreateStorageFacility" }
23
- its(:params) { is_expected.to eq({param: "values"}.to_json) }
23
+ its(:params) { is_expected.to eq("{\"param\"=>\"values\"}") }
24
24
 
25
25
  context "status" do
26
26
  it "can also be assigned other values" do
@@ -4,29 +4,20 @@ describe "Enqueueing jobs", type: :request do
4
4
 
5
5
  let(:job) { build_stubbed(:asyncapi_server_job, secret: "secret") }
6
6
 
7
- before do
8
- allow(Asyncapi::Server::Job).to receive(:create).with(
9
- class_name: "Runner",
10
- callback_url: "callback_url",
11
- params: {client: "params"}.to_json,
12
- secret: "secret",
13
- ).and_return(job)
14
-
15
- allow(job).to receive(:url).and_return("server_job_url")
16
- end
17
-
18
- it "allows asynchronous handing of http requests and cleans up old jobs" do
19
- expect(Asyncapi::Server::JobWorker).to receive(:perform_async).with(job.id)
20
-
21
- post("tests", job: {
22
- callback_url: "callback_url",
23
- params: {client: "params"}.to_json,
24
- secret: "secret",
7
+ it "allows asynchronous handling of http requests and cleans up old jobs", cleaning_strategy: :truncation do
8
+ post("/tests", params: {
9
+ job: {
10
+ callback_url: "callback_url",
11
+ params: {client: "params"}.to_json,
12
+ secret: "secret",
13
+ }
25
14
  })
26
15
 
27
16
  expect(response).to be_successful
28
17
  parsed_response = indifferent_hash(response.body)[:job]
29
- expect(parsed_response[:url]).to eq "server_job_url"
18
+ expect(Asyncapi::Server::JobWorker).
19
+ to have_enqueued_job(parsed_response[:id])
20
+ expect(parsed_response[:url]).to be_present
30
21
  expect(parsed_response[:secret]).to eq "secret"
31
22
  end
32
23
 
@@ -8,6 +8,7 @@ module Asyncapi::Server
8
8
  subject(:serialized_hash) { serializer.attributes }
9
9
 
10
10
  its([:id]) { is_expected.to eq job.id }
11
+ its([:status]) { is_expected.to eq job.status }
11
12
 
12
13
  it "has a url" do
13
14
  allow(job).to receive(:url).and_return("url")
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,7 @@ require "factory_girl_rails"
9
9
  require "pry"
10
10
  require "database_cleaner"
11
11
  require "timecop"
12
+ require 'rspec-sidekiq'
12
13
 
13
14
  Rails.backtrace_cleaner.remove_silencers!
14
15
 
@@ -21,7 +22,6 @@ Dir[
21
22
 
22
23
  RSpec.configure do |config|
23
24
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
24
- config.use_transactional_fixtures = false
25
25
  config.infer_base_class_for_anonymous_controllers = false
26
26
  config.order = "random"
27
27
 
@@ -29,12 +29,13 @@ RSpec.configure do |config|
29
29
  DatabaseCleaner.clean_with :truncation
30
30
  end
31
31
 
32
- config.before do
33
- DatabaseCleaner.strategy = :transaction
32
+ config.before do |example|
33
+ DatabaseCleaner.strategy = example.metadata[:cleaning_strategy] ||
34
+ :transaction
34
35
  DatabaseCleaner.start
35
36
  end
36
37
 
37
- config.after do
38
+ config.append_after(:each) do
38
39
  DatabaseCleaner.clean
39
40
  end
40
41
  end
@@ -0,0 +1,115 @@
1
+ require "spec_helper"
2
+
3
+ module Asyncapi
4
+ module Server
5
+ describe JobStatusNotifierWorker do
6
+
7
+ it "does not retry" do
8
+ expect(described_class.sidekiq_options_hash['retry']).to be false
9
+ end
10
+
11
+ describe "#perform" do
12
+ let(:message) { nil }
13
+ let(:code) { 200 }
14
+ let(:body) do
15
+ {
16
+ id: 12345,
17
+ server_job_url: "server_job_url",
18
+ status: "success",
19
+ }
20
+ end
21
+ let(:response) do
22
+ double(:response_double,
23
+ code: code,
24
+ body: body,
25
+ )
26
+ end
27
+ let(:job) do
28
+ create(:asyncapi_server_job, {
29
+ class_name: "Runner",
30
+ callback_url: "client_job_url",
31
+ status: :success,
32
+ secret: "secret",
33
+ })
34
+ end
35
+
36
+ it "notifies a job's callback_url with the job status" do
37
+ expect(Typhoeus).to receive(:put).with(
38
+ job.callback_url,
39
+ body: {
40
+ job: {
41
+ status: job.status,
42
+ message: message,
43
+ secret: job.secret,
44
+ }
45
+ }.to_json,
46
+ headers: {
47
+ "Content-Type" => "application/json",
48
+ Accept: "application/json"
49
+ }
50
+ ).and_return(response)
51
+
52
+ described_class.new.perform(job.id, message)
53
+ end
54
+
55
+ context "when an error occurred while notifying callback_url" do
56
+ let(:code) { 404 }
57
+ let(:body) do
58
+ {
59
+ error: "404",
60
+ status: "Not Found",
61
+ }
62
+ end
63
+ let(:jid) { "abcde12345" }
64
+
65
+ before do
66
+ expect(Typhoeus).to receive(:put).with(
67
+ job.callback_url,
68
+ body: {
69
+ job: {
70
+ status: job.status,
71
+ message: message,
72
+ secret: job.secret,
73
+ }
74
+ }.to_json,
75
+ headers: {
76
+ "Content-Type" => "application/json",
77
+ Accept: "application/json"
78
+ }
79
+ ).and_return(response)
80
+ end
81
+
82
+ context "when initial attempt fails" do
83
+ let(:retries) { 1 }
84
+
85
+ it "raises attempt failure and retries" do
86
+ expect(JobStatusNotifierWorker).to(
87
+ receive(:perform_async).with(job.id, message, retries+1).and_return(jid)
88
+ )
89
+
90
+ expect { described_class.new.perform(job.id, message, retries) }.not_to raise_error
91
+ end
92
+ end
93
+
94
+ context "when final attempt still fails" do
95
+ let(:expected_error_message) do
96
+ [
97
+ "Something went wrong while poking #{job.callback_url}",
98
+ "JobID: #{job.id}",
99
+ "Next Attempt: ",
100
+ "HTTP Status: #{response.code}",
101
+ "HTTP Response: #{response.inspect}",
102
+ ].join("\n")
103
+ end
104
+
105
+ it "raises error if no progress is made after MAX_RETRIES attempts" do
106
+ expect { described_class.new.perform(job.id, message, 3) }.to(
107
+ raise_error expected_error_message
108
+ )
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -19,20 +19,7 @@ module Asyncapi
19
19
 
20
20
  expect(Runner).to receive(:call).
21
21
  with(job.params) { "message" }
22
- expect(Typhoeus).to receive(:put).with(
23
- "client_job_url",
24
- body: {
25
- job: {
26
- status: :success,
27
- message: "message",
28
- secret: "sekret",
29
- }
30
- }.to_json,
31
- headers: {
32
- "Content-Type" => "application/json",
33
- Accept: "application/json"
34
- }
35
- )
22
+ expect(JobStatusNotifierWorker).to receive(:perform_async).with(job.id, "message")
36
23
 
37
24
  described_class.new.perform(job.id)
38
25
  job.reload
@@ -52,21 +39,7 @@ module Asyncapi
52
39
 
53
40
  allow(Runner).to receive(:call).
54
41
  and_raise(error)
55
-
56
- expect(Typhoeus).to receive(:put).with(
57
- "client_job_url",
58
- body: {
59
- job: {
60
- status: :error,
61
- message: ["my error", "back", "trace"].join("\n"),
62
- secret: "sekret",
63
- }
64
- }.to_json,
65
- headers: {
66
- "Content-Type" => "application/json",
67
- Accept: "application/json"
68
- }
69
- )
42
+ expect(JobStatusNotifierWorker).to receive(:perform_async).with(job.id, ["my error", "back", "trace"].join("\n"))
70
43
 
71
44
  expect { described_class.new.perform(job.id) }.
72
45
  to raise_error(error)
@@ -74,8 +47,14 @@ module Asyncapi
74
47
  expect(job.status).to eq "error"
75
48
  end
76
49
  end
77
- end
78
50
 
51
+ context "job is nil" do
52
+ it "retries JobWorker" do
53
+ expect(JobWorker).to receive(:perform_async).with("999", 1).and_return true
54
+ expect { described_class.new.perform("999") }.to raise_error
55
+ end
56
+ end
57
+ end
79
58
  end
80
59
  end
81
60
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asyncapi-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - G5
8
8
  - Marc Ignacio
9
9
  - Ramon Tayag
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-03-21 00:00:00.000000000 Z
13
+ date: 2021-04-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: kaminari
@@ -42,6 +42,34 @@ dependencies:
42
42
  version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rails
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '4'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '4'
57
+ - !ruby/object:Gem::Dependency
58
+ name: active_model_serializers
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: 0.9.0
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: 0.9.0
71
+ - !ruby/object:Gem::Dependency
72
+ name: typhoeus
45
73
  requirement: !ruby/object:Gem::Requirement
46
74
  requirements:
47
75
  - - ">="
@@ -55,7 +83,7 @@ dependencies:
55
83
  - !ruby/object:Gem::Version
56
84
  version: '0'
57
85
  - !ruby/object:Gem::Dependency
58
- name: active_model_serializers
86
+ name: sidekiq
59
87
  requirement: !ruby/object:Gem::Requirement
60
88
  requirements:
61
89
  - - ">="
@@ -69,7 +97,7 @@ dependencies:
69
97
  - !ruby/object:Gem::Version
70
98
  version: '0'
71
99
  - !ruby/object:Gem::Dependency
72
- name: typhoeus
100
+ name: responders
73
101
  requirement: !ruby/object:Gem::Requirement
74
102
  requirements:
75
103
  - - ">="
@@ -83,7 +111,7 @@ dependencies:
83
111
  - !ruby/object:Gem::Version
84
112
  version: '0'
85
113
  - !ruby/object:Gem::Dependency
86
- name: sidekiq
114
+ name: ar_after_transaction
87
115
  requirement: !ruby/object:Gem::Requirement
88
116
  requirements:
89
117
  - - ">="
@@ -116,14 +144,14 @@ dependencies:
116
144
  requirements:
117
145
  - - "~>"
118
146
  - !ruby/object:Gem::Version
119
- version: 3.1.0
147
+ version: 3.5.0
120
148
  type: :development
121
149
  prerelease: false
122
150
  version_requirements: !ruby/object:Gem::Requirement
123
151
  requirements:
124
152
  - - "~>"
125
153
  - !ruby/object:Gem::Version
126
- version: 3.1.0
154
+ version: 3.5.0
127
155
  - !ruby/object:Gem::Dependency
128
156
  name: rspec-its
129
157
  requirement: !ruby/object:Gem::Requirement
@@ -138,6 +166,20 @@ dependencies:
138
166
  - - "~>"
139
167
  - !ruby/object:Gem::Version
140
168
  version: 1.1.0
169
+ - !ruby/object:Gem::Dependency
170
+ name: rspec-sidekiq
171
+ requirement: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ type: :development
177
+ prerelease: false
178
+ version_requirements: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
141
183
  - !ruby/object:Gem::Dependency
142
184
  name: pry
143
185
  requirement: !ruby/object:Gem::Requirement
@@ -209,6 +251,7 @@ files:
209
251
  - app/controllers/asyncapi/server/v1/jobs_controller.rb
210
252
  - app/models/asyncapi/server/job.rb
211
253
  - app/serializers/asyncapi/server/job_serializer.rb
254
+ - app/workers/asyncapi/server/job_status_notifier_worker.rb
212
255
  - app/workers/asyncapi/server/job_worker.rb
213
256
  - config/database.yml
214
257
  - config/routes.rb
@@ -257,11 +300,11 @@ files:
257
300
  - spec/dummy/config/locales/en.yml
258
301
  - spec/dummy/config/routes.rb
259
302
  - spec/dummy/config/secrets.yml
260
- - spec/dummy/db/migrate/20141212065005_create_asyncapi_server_jobs.asyncapi_server.rb
261
- - spec/dummy/db/migrate/20141212065006_add_secret_to_asyncapi_server_job.asyncapi_server.rb
262
- - spec/dummy/db/migrate/20150130062901_add_expired_at_to_asyncapi_server_job.asyncapi_server.rb
263
- - spec/dummy/db/migrate/20150201231329_drop_expired_at_from_asyncapi_server_jobs.asyncapi_server.rb
303
+ - spec/dummy/db/development.sqlite3
264
304
  - spec/dummy/db/schema.rb
305
+ - spec/dummy/db/test.sqlite3
306
+ - spec/dummy/log/development.log
307
+ - spec/dummy/log/test.log
265
308
  - spec/dummy/public/404.html
266
309
  - spec/dummy/public/422.html
267
310
  - spec/dummy/public/500.html
@@ -275,12 +318,13 @@ files:
275
318
  - spec/spec_helper.rb
276
319
  - spec/support/factory_girl.rb
277
320
  - spec/support/indifferent_hash.rb
321
+ - spec/workers/job_status_notifier_worker_spec.rb
278
322
  - spec/workers/job_worker_spec.rb
279
323
  homepage: https://github.com/G5/asyncapi-server
280
324
  licenses:
281
325
  - MIT
282
326
  metadata: {}
283
- post_install_message:
327
+ post_install_message:
284
328
  rdoc_options: []
285
329
  require_paths:
286
330
  - lib
@@ -295,60 +339,60 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
339
  - !ruby/object:Gem::Version
296
340
  version: '0'
297
341
  requirements: []
298
- rubyforge_project:
299
- rubygems_version: 2.4.3
300
- signing_key:
342
+ rubygems_version: 3.0.9
343
+ signing_key:
301
344
  specification_version: 4
302
345
  summary: Asynchronous API communication - Server
303
346
  test_files:
304
- - spec/controllers/asyncapi/server/v1/jobs_controller_spec.rb
305
- - spec/dummy/app/assets/javascripts/application.js
306
- - spec/dummy/app/assets/stylesheets/application.css
347
+ - spec/spec_helper.rb
307
348
  - spec/dummy/app/controllers/application_controller.rb
308
349
  - spec/dummy/app/controllers/tests_controller.rb
309
- - spec/dummy/app/helpers/application_helper.rb
310
350
  - spec/dummy/app/views/layouts/application.html.erb
351
+ - spec/dummy/app/assets/javascripts/application.js
352
+ - spec/dummy/app/assets/stylesheets/application.css
353
+ - spec/dummy/app/helpers/application_helper.rb
354
+ - spec/dummy/bin/rake
311
355
  - spec/dummy/bin/bundle
312
356
  - spec/dummy/bin/rails
313
- - spec/dummy/bin/rake
314
- - spec/dummy/config/application.rb
315
- - spec/dummy/config/boot.rb
316
- - spec/dummy/config/database.yml
317
- - spec/dummy/config/environment.rb
318
- - spec/dummy/config/environments/development.rb
357
+ - spec/dummy/config/secrets.yml
358
+ - spec/dummy/config/routes.rb
359
+ - spec/dummy/config/locales/en.yml
319
360
  - spec/dummy/config/environments/production.rb
361
+ - spec/dummy/config/environments/development.rb
320
362
  - spec/dummy/config/environments/test.rb
321
- - spec/dummy/config/initializers/assets.rb
363
+ - spec/dummy/config/environment.rb
364
+ - spec/dummy/config/application.rb
365
+ - spec/dummy/config/database.yml
366
+ - spec/dummy/config/boot.rb
322
367
  - spec/dummy/config/initializers/backtrace_silencers.rb
323
- - spec/dummy/config/initializers/cookies_serializer.rb
324
- - spec/dummy/config/initializers/default_url_options.rb
325
- - spec/dummy/config/initializers/filter_parameter_logging.rb
326
- - spec/dummy/config/initializers/inflections.rb
327
368
  - spec/dummy/config/initializers/mime_types.rb
369
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
328
370
  - spec/dummy/config/initializers/session_store.rb
329
371
  - spec/dummy/config/initializers/wrap_parameters.rb
330
- - spec/dummy/config/locales/en.yml
331
- - spec/dummy/config/routes.rb
332
- - spec/dummy/config/secrets.yml
372
+ - spec/dummy/config/initializers/assets.rb
373
+ - spec/dummy/config/initializers/default_url_options.rb
374
+ - spec/dummy/config/initializers/cookies_serializer.rb
375
+ - spec/dummy/config/initializers/inflections.rb
333
376
  - spec/dummy/config.ru
334
- - spec/dummy/db/migrate/20141212065005_create_asyncapi_server_jobs.asyncapi_server.rb
335
- - spec/dummy/db/migrate/20141212065006_add_secret_to_asyncapi_server_job.asyncapi_server.rb
336
- - spec/dummy/db/migrate/20150130062901_add_expired_at_to_asyncapi_server_job.asyncapi_server.rb
337
- - spec/dummy/db/migrate/20150201231329_drop_expired_at_from_asyncapi_server_jobs.asyncapi_server.rb
338
- - spec/dummy/db/schema.rb
339
- - spec/dummy/public/404.html
377
+ - spec/dummy/Rakefile
378
+ - spec/dummy/public/favicon.ico
340
379
  - spec/dummy/public/422.html
341
380
  - spec/dummy/public/500.html
342
- - spec/dummy/public/favicon.ico
343
- - spec/dummy/Rakefile
381
+ - spec/dummy/public/404.html
382
+ - spec/dummy/db/schema.rb
383
+ - spec/dummy/db/test.sqlite3
384
+ - spec/dummy/db/development.sqlite3
385
+ - spec/dummy/log/test.log
386
+ - spec/dummy/log/development.log
344
387
  - spec/dummy/README.rdoc
345
- - spec/factories/job.rb
346
- - spec/fixtures/runner.rb
388
+ - spec/server_spec.rb
347
389
  - spec/models/job_spec.rb
348
390
  - spec/requests/enqueueing_jobs_spec.rb
349
391
  - spec/serializers/job_serializer_spec.rb
350
- - spec/server_spec.rb
351
- - spec/spec_helper.rb
352
- - spec/support/factory_girl.rb
353
392
  - spec/support/indifferent_hash.rb
393
+ - spec/support/factory_girl.rb
394
+ - spec/factories/job.rb
395
+ - spec/fixtures/runner.rb
354
396
  - spec/workers/job_worker_spec.rb
397
+ - spec/workers/job_status_notifier_worker_spec.rb
398
+ - spec/controllers/asyncapi/server/v1/jobs_controller_spec.rb