asyncapi-server 1.1.3 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/app/assets/config/manifest.js +3 -0
- data/app/controllers/asyncapi/server/v1/jobs_controller.rb +3 -1
- data/app/controllers/concerns/active_model_serializers_fix.rb +10 -0
- data/app/serializers/asyncapi/server/job_serializer.rb +1 -1
- data/app/workers/asyncapi/server/job_status_notifier_worker.rb +53 -0
- data/app/workers/asyncapi/server/job_worker.rb +2 -16
- data/db/migrate/20141112034324_create_asyncapi_server_jobs.rb +1 -1
- data/db/migrate/20141212064931_add_secret_to_asyncapi_server_job.rb +1 -1
- data/db/migrate/20150130062520_add_expired_at_to_asyncapi_server_job.rb +1 -1
- data/db/migrate/20150201231018_drop_expired_at_from_asyncapi_server_jobs.rb +1 -1
- data/lib/asyncapi/server/rails_ext/controller.rb +1 -1
- data/lib/asyncapi/server/rspec.rb +20 -7
- data/lib/asyncapi/server/version.rb +1 -1
- data/spec/controllers/asyncapi/server/v1/jobs_controller_spec.rb +4 -4
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/controllers/tests_controller.rb +1 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +10 -11
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +75 -39
- data/spec/dummy/log/test.log +709 -3771
- data/spec/models/job_spec.rb +1 -1
- data/spec/requests/enqueueing_jobs_spec.rb +6 -4
- data/spec/serializers/job_serializer_spec.rb +1 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/workers/job_status_notifier_worker_spec.rb +119 -0
- data/spec/workers/job_worker_spec.rb +2 -29
- metadata +69 -63
data/spec/models/job_spec.rb
CHANGED
@@ -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
|
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
|
@@ -5,10 +5,12 @@ describe "Enqueueing jobs", type: :request do
|
|
5
5
|
let(:job) { build_stubbed(:asyncapi_server_job, secret: "secret") }
|
6
6
|
|
7
7
|
it "allows asynchronous handling of http requests and cleans up old jobs", cleaning_strategy: :truncation do
|
8
|
-
post("/tests",
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
post("/tests", params: {
|
9
|
+
job: {
|
10
|
+
callback_url: "callback_url",
|
11
|
+
params: {client: "params"}.to_json,
|
12
|
+
secret: "secret",
|
13
|
+
}
|
12
14
|
})
|
13
15
|
|
14
16
|
expect(response).to be_successful
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,119 @@
|
|
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
|
+
timeout: 60,
|
40
|
+
connecttimeout: 60,
|
41
|
+
body: {
|
42
|
+
job: {
|
43
|
+
status: job.status,
|
44
|
+
message: message,
|
45
|
+
secret: job.secret,
|
46
|
+
}
|
47
|
+
}.to_json,
|
48
|
+
headers: {
|
49
|
+
"Content-Type" => "application/json",
|
50
|
+
Accept: "application/json"
|
51
|
+
}
|
52
|
+
).and_return(response)
|
53
|
+
|
54
|
+
described_class.new.perform(job.id, message)
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when an error occurred while notifying callback_url" do
|
58
|
+
let(:code) { 404 }
|
59
|
+
let(:body) do
|
60
|
+
{
|
61
|
+
error: "404",
|
62
|
+
status: "Not Found",
|
63
|
+
}
|
64
|
+
end
|
65
|
+
let(:jid) { "abcde12345" }
|
66
|
+
|
67
|
+
before do
|
68
|
+
expect(Typhoeus).to receive(:put).with(
|
69
|
+
job.callback_url,
|
70
|
+
timeout: 60,
|
71
|
+
connecttimeout: 60,
|
72
|
+
body: {
|
73
|
+
job: {
|
74
|
+
status: job.status,
|
75
|
+
message: message,
|
76
|
+
secret: job.secret,
|
77
|
+
}
|
78
|
+
}.to_json,
|
79
|
+
headers: {
|
80
|
+
"Content-Type" => "application/json",
|
81
|
+
Accept: "application/json"
|
82
|
+
}
|
83
|
+
).and_return(response)
|
84
|
+
end
|
85
|
+
|
86
|
+
context "when initial attempt fails" do
|
87
|
+
let(:retries) { 1 }
|
88
|
+
|
89
|
+
it "raises attempt failure and retries" do
|
90
|
+
expect(JobStatusNotifierWorker).to(
|
91
|
+
receive(:perform_async).with(job.id, message, retries+1).and_return(jid)
|
92
|
+
)
|
93
|
+
|
94
|
+
expect { described_class.new.perform(job.id, message, retries) }.not_to raise_error
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "when final attempt still fails" do
|
99
|
+
let(:expected_error_message) do
|
100
|
+
[
|
101
|
+
"Something went wrong while poking #{job.callback_url}",
|
102
|
+
"JobID: #{job.id}",
|
103
|
+
"Next Attempt: ",
|
104
|
+
"HTTP Status: #{response.code}",
|
105
|
+
"HTTP Response: #{response.inspect}",
|
106
|
+
].join("\n")
|
107
|
+
end
|
108
|
+
|
109
|
+
it "raises error if no progress is made after MAX_RETRIES attempts" do
|
110
|
+
expect { described_class.new.perform(job.id, message, 3) }.to(
|
111
|
+
raise_error expected_error_message
|
112
|
+
)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -19,20 +19,7 @@ module Asyncapi
|
|
19
19
|
|
20
20
|
expect(Runner).to receive(:call).
|
21
21
|
with(job.params) { "message" }
|
22
|
-
expect(
|
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)
|
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.
|
4
|
+
version: 1.3.2
|
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:
|
13
|
+
date: 2022-03-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: kaminari
|
@@ -44,30 +44,30 @@ dependencies:
|
|
44
44
|
name: rails
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - "
|
47
|
+
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '4
|
49
|
+
version: '4'
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - "
|
54
|
+
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '4
|
56
|
+
version: '4'
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: active_model_serializers
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: 0.9.
|
63
|
+
version: 0.9.7
|
64
64
|
type: :runtime
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
68
|
- - "~>"
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version: 0.9.
|
70
|
+
version: 0.9.7
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: typhoeus
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,44 +128,44 @@ dependencies:
|
|
128
128
|
name: sqlite3
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
|
-
- - "
|
131
|
+
- - ">="
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: 1.
|
133
|
+
version: '1.4'
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
|
-
- - "
|
138
|
+
- - ">="
|
139
139
|
- !ruby/object:Gem::Version
|
140
|
-
version: 1.
|
140
|
+
version: '1.4'
|
141
141
|
- !ruby/object:Gem::Dependency
|
142
142
|
name: rspec-rails
|
143
143
|
requirement: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
|
-
- - "
|
145
|
+
- - ">="
|
146
146
|
- !ruby/object:Gem::Version
|
147
|
-
version:
|
147
|
+
version: '0'
|
148
148
|
type: :development
|
149
149
|
prerelease: false
|
150
150
|
version_requirements: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
|
-
- - "
|
152
|
+
- - ">="
|
153
153
|
- !ruby/object:Gem::Version
|
154
|
-
version:
|
154
|
+
version: '0'
|
155
155
|
- !ruby/object:Gem::Dependency
|
156
156
|
name: rspec-its
|
157
157
|
requirement: !ruby/object:Gem::Requirement
|
158
158
|
requirements:
|
159
|
-
- - "
|
159
|
+
- - ">="
|
160
160
|
- !ruby/object:Gem::Version
|
161
|
-
version:
|
161
|
+
version: '0'
|
162
162
|
type: :development
|
163
163
|
prerelease: false
|
164
164
|
version_requirements: !ruby/object:Gem::Requirement
|
165
165
|
requirements:
|
166
|
-
- - "
|
166
|
+
- - ">="
|
167
167
|
- !ruby/object:Gem::Version
|
168
|
-
version:
|
168
|
+
version: '0'
|
169
169
|
- !ruby/object:Gem::Dependency
|
170
170
|
name: rspec-sidekiq
|
171
171
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,16 +184,16 @@ dependencies:
|
|
184
184
|
name: pry
|
185
185
|
requirement: !ruby/object:Gem::Requirement
|
186
186
|
requirements:
|
187
|
-
- - "
|
187
|
+
- - ">="
|
188
188
|
- !ruby/object:Gem::Version
|
189
|
-
version: 0
|
189
|
+
version: '0'
|
190
190
|
type: :development
|
191
191
|
prerelease: false
|
192
192
|
version_requirements: !ruby/object:Gem::Requirement
|
193
193
|
requirements:
|
194
|
-
- - "
|
194
|
+
- - ">="
|
195
195
|
- !ruby/object:Gem::Version
|
196
|
-
version: 0
|
196
|
+
version: '0'
|
197
197
|
- !ruby/object:Gem::Dependency
|
198
198
|
name: factory_girl_rails
|
199
199
|
requirement: !ruby/object:Gem::Requirement
|
@@ -212,16 +212,16 @@ dependencies:
|
|
212
212
|
name: database_cleaner
|
213
213
|
requirement: !ruby/object:Gem::Requirement
|
214
214
|
requirements:
|
215
|
-
- - "
|
215
|
+
- - ">="
|
216
216
|
- !ruby/object:Gem::Version
|
217
|
-
version:
|
217
|
+
version: '0'
|
218
218
|
type: :development
|
219
219
|
prerelease: false
|
220
220
|
version_requirements: !ruby/object:Gem::Requirement
|
221
221
|
requirements:
|
222
|
-
- - "
|
222
|
+
- - ">="
|
223
223
|
- !ruby/object:Gem::Version
|
224
|
-
version:
|
224
|
+
version: '0'
|
225
225
|
- !ruby/object:Gem::Dependency
|
226
226
|
name: timecop
|
227
227
|
requirement: !ruby/object:Gem::Requirement
|
@@ -248,9 +248,12 @@ files:
|
|
248
248
|
- MIT-LICENSE
|
249
249
|
- README.md
|
250
250
|
- Rakefile
|
251
|
+
- app/assets/config/manifest.js
|
251
252
|
- app/controllers/asyncapi/server/v1/jobs_controller.rb
|
253
|
+
- app/controllers/concerns/active_model_serializers_fix.rb
|
252
254
|
- app/models/asyncapi/server/job.rb
|
253
255
|
- app/serializers/asyncapi/server/job_serializer.rb
|
256
|
+
- app/workers/asyncapi/server/job_status_notifier_worker.rb
|
254
257
|
- app/workers/asyncapi/server/job_worker.rb
|
255
258
|
- config/database.yml
|
256
259
|
- config/routes.rb
|
@@ -270,6 +273,7 @@ files:
|
|
270
273
|
- spec/controllers/asyncapi/server/v1/jobs_controller_spec.rb
|
271
274
|
- spec/dummy/README.rdoc
|
272
275
|
- spec/dummy/Rakefile
|
276
|
+
- spec/dummy/app/assets/config/manifest.js
|
273
277
|
- spec/dummy/app/assets/javascripts/application.js
|
274
278
|
- spec/dummy/app/assets/stylesheets/application.css
|
275
279
|
- spec/dummy/app/controllers/application_controller.rb
|
@@ -317,12 +321,13 @@ files:
|
|
317
321
|
- spec/spec_helper.rb
|
318
322
|
- spec/support/factory_girl.rb
|
319
323
|
- spec/support/indifferent_hash.rb
|
324
|
+
- spec/workers/job_status_notifier_worker_spec.rb
|
320
325
|
- spec/workers/job_worker_spec.rb
|
321
326
|
homepage: https://github.com/G5/asyncapi-server
|
322
327
|
licenses:
|
323
328
|
- MIT
|
324
329
|
metadata: {}
|
325
|
-
post_install_message:
|
330
|
+
post_install_message:
|
326
331
|
rdoc_options: []
|
327
332
|
require_paths:
|
328
333
|
- lib
|
@@ -337,60 +342,61 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
337
342
|
- !ruby/object:Gem::Version
|
338
343
|
version: '0'
|
339
344
|
requirements: []
|
340
|
-
|
341
|
-
|
342
|
-
signing_key:
|
345
|
+
rubygems_version: 3.2.31
|
346
|
+
signing_key:
|
343
347
|
specification_version: 4
|
344
348
|
summary: Asynchronous API communication - Server
|
345
349
|
test_files:
|
346
|
-
- spec/
|
347
|
-
- spec/dummy/app/assets/javascripts/application.js
|
348
|
-
- spec/dummy/app/assets/stylesheets/application.css
|
350
|
+
- spec/spec_helper.rb
|
349
351
|
- spec/dummy/app/controllers/application_controller.rb
|
350
352
|
- spec/dummy/app/controllers/tests_controller.rb
|
351
|
-
- spec/dummy/app/helpers/application_helper.rb
|
352
353
|
- spec/dummy/app/views/layouts/application.html.erb
|
354
|
+
- spec/dummy/app/assets/config/manifest.js
|
355
|
+
- spec/dummy/app/assets/javascripts/application.js
|
356
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
357
|
+
- spec/dummy/app/helpers/application_helper.rb
|
358
|
+
- spec/dummy/bin/rake
|
353
359
|
- spec/dummy/bin/bundle
|
354
360
|
- spec/dummy/bin/rails
|
355
|
-
- spec/dummy/
|
356
|
-
- spec/dummy/config/
|
357
|
-
- spec/dummy/config/
|
358
|
-
- spec/dummy/config/database.yml
|
359
|
-
- spec/dummy/config/environment.rb
|
360
|
-
- spec/dummy/config/environments/development.rb
|
361
|
+
- spec/dummy/config/secrets.yml
|
362
|
+
- spec/dummy/config/routes.rb
|
363
|
+
- spec/dummy/config/locales/en.yml
|
361
364
|
- spec/dummy/config/environments/production.rb
|
365
|
+
- spec/dummy/config/environments/development.rb
|
362
366
|
- spec/dummy/config/environments/test.rb
|
363
|
-
- spec/dummy/config/
|
367
|
+
- spec/dummy/config/environment.rb
|
368
|
+
- spec/dummy/config/application.rb
|
369
|
+
- spec/dummy/config/database.yml
|
370
|
+
- spec/dummy/config/boot.rb
|
364
371
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
365
|
-
- spec/dummy/config/initializers/cookies_serializer.rb
|
366
|
-
- spec/dummy/config/initializers/default_url_options.rb
|
367
|
-
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
368
|
-
- spec/dummy/config/initializers/inflections.rb
|
369
372
|
- spec/dummy/config/initializers/mime_types.rb
|
373
|
+
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
370
374
|
- spec/dummy/config/initializers/session_store.rb
|
371
375
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
372
|
-
- spec/dummy/config/
|
373
|
-
- spec/dummy/config/
|
374
|
-
- spec/dummy/config/
|
376
|
+
- spec/dummy/config/initializers/assets.rb
|
377
|
+
- spec/dummy/config/initializers/default_url_options.rb
|
378
|
+
- spec/dummy/config/initializers/cookies_serializer.rb
|
379
|
+
- spec/dummy/config/initializers/inflections.rb
|
375
380
|
- spec/dummy/config.ru
|
376
|
-
- spec/dummy/
|
381
|
+
- spec/dummy/Rakefile
|
382
|
+
- spec/dummy/public/favicon.ico
|
383
|
+
- spec/dummy/public/422.html
|
384
|
+
- spec/dummy/public/500.html
|
385
|
+
- spec/dummy/public/404.html
|
377
386
|
- spec/dummy/db/schema.rb
|
378
387
|
- spec/dummy/db/test.sqlite3
|
379
|
-
- spec/dummy/
|
388
|
+
- spec/dummy/db/development.sqlite3
|
380
389
|
- spec/dummy/log/test.log
|
381
|
-
- spec/dummy/
|
382
|
-
- spec/dummy/public/422.html
|
383
|
-
- spec/dummy/public/500.html
|
384
|
-
- spec/dummy/public/favicon.ico
|
385
|
-
- spec/dummy/Rakefile
|
390
|
+
- spec/dummy/log/development.log
|
386
391
|
- spec/dummy/README.rdoc
|
387
|
-
- spec/
|
388
|
-
- spec/fixtures/runner.rb
|
392
|
+
- spec/server_spec.rb
|
389
393
|
- spec/models/job_spec.rb
|
390
394
|
- spec/requests/enqueueing_jobs_spec.rb
|
391
395
|
- spec/serializers/job_serializer_spec.rb
|
392
|
-
- spec/server_spec.rb
|
393
|
-
- spec/spec_helper.rb
|
394
|
-
- spec/support/factory_girl.rb
|
395
396
|
- spec/support/indifferent_hash.rb
|
397
|
+
- spec/support/factory_girl.rb
|
398
|
+
- spec/factories/job.rb
|
399
|
+
- spec/fixtures/runner.rb
|
396
400
|
- spec/workers/job_worker_spec.rb
|
401
|
+
- spec/workers/job_status_notifier_worker_spec.rb
|
402
|
+
- spec/controllers/asyncapi/server/v1/jobs_controller_spec.rb
|