startback-jobs 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -3
- data/README.md +13 -0
- data/lib/startback/audit/prometheus.rb +87 -0
- data/lib/startback/audit/shared.rb +17 -0
- data/lib/startback/audit/trailer.rb +129 -0
- data/lib/startback/audit.rb +3 -0
- data/lib/startback/caching/entity_cache.rb +157 -0
- data/lib/startback/caching/no_store.rb +28 -0
- data/lib/startback/caching/store.rb +34 -0
- data/lib/startback/context/h_factory.rb +43 -0
- data/lib/startback/context/middleware.rb +53 -0
- data/lib/startback/context.rb +122 -0
- data/lib/startback/errors.rb +197 -0
- data/lib/startback/event/agent.rb +84 -0
- data/lib/startback/event/bus/bunny/async.rb +162 -0
- data/lib/startback/event/bus/bunny.rb +1 -0
- data/lib/startback/event/bus/memory/async.rb +45 -0
- data/lib/startback/event/bus/memory/sync.rb +35 -0
- data/lib/startback/event/bus/memory.rb +2 -0
- data/lib/startback/event/bus.rb +100 -0
- data/lib/startback/event/engine.rb +94 -0
- data/lib/startback/event/ext/context.rb +5 -0
- data/lib/startback/event/ext/operation.rb +13 -0
- data/lib/startback/event.rb +47 -0
- data/lib/startback/ext/date_time.rb +9 -0
- data/lib/startback/ext/time.rb +9 -0
- data/lib/startback/ext.rb +2 -2
- data/lib/startback/model.rb +6 -0
- data/lib/startback/operation/error_operation.rb +19 -0
- data/lib/startback/operation/multi_operation.rb +28 -0
- data/lib/startback/operation.rb +78 -0
- data/lib/startback/services.rb +11 -0
- data/lib/startback/support/data_object.rb +71 -0
- data/lib/startback/support/env.rb +41 -0
- data/lib/startback/support/fake_logger.rb +18 -0
- data/lib/startback/support/hooks.rb +48 -0
- data/lib/startback/support/log_formatter.rb +34 -0
- data/lib/startback/support/logger.rb +34 -0
- data/lib/startback/support/operation_runner.rb +150 -0
- data/lib/startback/support/robustness.rb +157 -0
- data/lib/startback/support/transaction_manager.rb +25 -0
- data/lib/startback/support/transaction_policy.rb +33 -0
- data/lib/startback/support/world.rb +54 -0
- data/lib/startback/support.rb +26 -0
- data/lib/startback/version.rb +8 -0
- data/lib/startback/web/api.rb +99 -0
- data/lib/startback/web/auto_caching.rb +85 -0
- data/lib/startback/web/catch_all.rb +52 -0
- data/lib/startback/web/cors_headers.rb +80 -0
- data/lib/startback/web/health_check.rb +49 -0
- data/lib/startback/web/magic_assets/ng_html_transformer.rb +80 -0
- data/lib/startback/web/magic_assets/rake_tasks.rb +64 -0
- data/lib/startback/web/magic_assets.rb +98 -0
- data/lib/startback/web/middleware.rb +13 -0
- data/lib/startback/web/prometheus.rb +16 -0
- data/lib/startback/web/shield.rb +58 -0
- data/lib/startback.rb +43 -0
- data/spec/spec_helper.rb +33 -26
- data/spec/unit/audit/test_prometheus.rb +72 -0
- data/spec/unit/audit/test_trailer.rb +105 -0
- data/spec/unit/caching/test_entity_cache.rb +136 -0
- data/spec/unit/context/test_abstraction_factory.rb +64 -0
- data/spec/unit/context/test_dup.rb +42 -0
- data/spec/unit/context/test_fork.rb +37 -0
- data/spec/unit/context/test_h_factory.rb +31 -0
- data/spec/unit/context/test_middleware.rb +45 -0
- data/spec/unit/context/test_with_world.rb +20 -0
- data/spec/unit/context/test_world.rb +17 -0
- data/spec/unit/event/bus/memory/test_async.rb +43 -0
- data/spec/unit/event/bus/memory/test_sync.rb +43 -0
- data/spec/unit/support/hooks/test_after_hook.rb +54 -0
- data/spec/unit/support/hooks/test_before_hook.rb +54 -0
- data/spec/unit/support/operation_runner/test_around_run.rb +156 -0
- data/spec/unit/support/operation_runner/test_before_after_call.rb +48 -0
- data/spec/unit/support/test_data_object.rb +156 -0
- data/spec/unit/support/test_env.rb +75 -0
- data/spec/unit/support/test_robusteness.rb +229 -0
- data/spec/unit/support/test_transaction_manager.rb +64 -0
- data/spec/unit/support/test_world.rb +72 -0
- data/spec/unit/test_event.rb +62 -0
- data/spec/unit/test_operation.rb +55 -0
- data/spec/unit/test_support.rb +40 -0
- data/spec/unit/web/fixtures/assets/app/hello.es6 +4 -0
- data/spec/unit/web/fixtures/assets/app/hello.html +1 -0
- data/spec/unit/web/fixtures/assets/index.es6 +1 -0
- data/spec/unit/web/test_api.rb +82 -0
- data/spec/unit/web/test_auto_caching.rb +81 -0
- data/spec/unit/web/test_catch_all.rb +77 -0
- data/spec/unit/web/test_cors_headers.rb +88 -0
- data/spec/unit/web/test_healthcheck.rb +59 -0
- data/spec/unit/web/test_magic_assets.rb +82 -0
- data/tasks/test.rake +1 -0
- metadata +94 -31
- data/lib/startback/ext/support/operation_runner.rb +0 -17
- data/lib/startback/ext/web/api.rb +0 -12
- data/lib/startback/jobs/agent.rb +0 -15
- data/lib/startback/jobs/api.rb +0 -12
- data/lib/startback/jobs/event/job_created.rb +0 -8
- data/lib/startback/jobs/event/job_ran.rb +0 -8
- data/lib/startback/jobs/event.rb +0 -8
- data/lib/startback/jobs/model/job.rb +0 -35
- data/lib/startback/jobs/model.rb +0 -12
- data/lib/startback/jobs/operation/create_job.rb +0 -37
- data/lib/startback/jobs/operation/run_job.rb +0 -35
- data/lib/startback/jobs/operation.rb +0 -8
- data/lib/startback/jobs/services.rb +0 -25
- data/lib/startback/jobs/support/job_result/embedded.rb +0 -15
- data/lib/startback/jobs/support/job_result/not_ready.rb +0 -15
- data/lib/startback/jobs/support/job_result/redirect.rb +0 -32
- data/lib/startback/jobs/support/job_result.rb +0 -31
- data/lib/startback/jobs/support.rb +0 -1
- data/lib/startback/jobs.fio +0 -44
- data/lib/startback/jobs.rb +0 -23
- data/spec/unit/api/test_job_result.rb +0 -121
- data/spec/unit/model/test_job.rb +0 -23
- data/spec/unit/operation/test_create_job.rb +0 -42
- data/spec/unit/operation/test_run_job.rb +0 -37
- data/spec/unit/test_finitio_schema.rb +0 -20
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'startback/web/magic_assets'
|
3
|
+
require 'startback/web/magic_assets/ng_html_transformer'
|
4
|
+
|
5
|
+
module Startback
|
6
|
+
module Web
|
7
|
+
describe MagicAssets do
|
8
|
+
include Rack::Test::Methods
|
9
|
+
|
10
|
+
context 'when used as an app' do
|
11
|
+
let(:app){
|
12
|
+
MagicAssets.new({
|
13
|
+
folder: Path.dir/"fixtures/assets"
|
14
|
+
})
|
15
|
+
}
|
16
|
+
|
17
|
+
it 'works as expected' do
|
18
|
+
get "/index.js"
|
19
|
+
expect(last_response.status).to eql(200)
|
20
|
+
expect(last_response.body).to match(/function test/)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'delegates a [] call to sprockets' do
|
24
|
+
result = app['index.js']
|
25
|
+
expect(result.to_s).to match(/function test/)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns a 404 on unknown' do
|
29
|
+
get '/nosuchone.js'
|
30
|
+
expect(last_response.status).to eql(404)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when used as a middleware' do
|
35
|
+
let(:app){
|
36
|
+
Rack::Builder.new do
|
37
|
+
use MagicAssets, {
|
38
|
+
folder: Path.dir/"fixtures/assets",
|
39
|
+
path: "/my-assets"
|
40
|
+
}
|
41
|
+
run ->(t){
|
42
|
+
[200, {}, ["Hello world"]]
|
43
|
+
}
|
44
|
+
end
|
45
|
+
}
|
46
|
+
|
47
|
+
it 'lets unrelated things pass' do
|
48
|
+
get "/hello"
|
49
|
+
expect(last_response.status).to eql(200)
|
50
|
+
expect(last_response.body).to eql("Hello world")
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'serves the assets under the chosen path' do
|
54
|
+
get "/my-assets/index.js"
|
55
|
+
expect(last_response.status).to eql(200)
|
56
|
+
expect(last_response.body).to match(/function test/)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when registering the NgHtmlTransformer' do
|
61
|
+
let(:app){
|
62
|
+
plugin = MagicAssets::NgHtmlTransformer.new({
|
63
|
+
ng_module: "test.templates"
|
64
|
+
})
|
65
|
+
MagicAssets.new({
|
66
|
+
folder: Path.dir/"fixtures/assets",
|
67
|
+
plugins: [plugin]
|
68
|
+
})
|
69
|
+
}
|
70
|
+
|
71
|
+
it 'works as expected' do
|
72
|
+
get "/index.js"
|
73
|
+
expect(last_response.status).to eql(200)
|
74
|
+
expect(last_response.body).to match(/function test/)
|
75
|
+
expect(last_response.body).to match(/Hello \{\{who\}\}/)
|
76
|
+
expect(last_response.body).to match(/angular.module\("test.templates"\)/)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/tasks/test.rake
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: startback-jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -118,14 +118,14 @@ dependencies:
|
|
118
118
|
requirements:
|
119
119
|
- - '='
|
120
120
|
- !ruby/object:Gem::Version
|
121
|
-
version: 0.
|
121
|
+
version: 0.14.0
|
122
122
|
type: :runtime
|
123
123
|
prerelease: false
|
124
124
|
version_requirements: !ruby/object:Gem::Requirement
|
125
125
|
requirements:
|
126
126
|
- - '='
|
127
127
|
- !ruby/object:Gem::Version
|
128
|
-
version: 0.
|
128
|
+
version: 0.14.0
|
129
129
|
description: Asynchronous jobs on top of the Startback framework
|
130
130
|
email: blambeau@gmail.com
|
131
131
|
executables: []
|
@@ -133,36 +133,99 @@ extensions: []
|
|
133
133
|
extra_rdoc_files: []
|
134
134
|
files:
|
135
135
|
- Gemfile
|
136
|
+
- README.md
|
136
137
|
- Rakefile
|
138
|
+
- lib/startback.rb
|
139
|
+
- lib/startback/audit.rb
|
140
|
+
- lib/startback/audit/prometheus.rb
|
141
|
+
- lib/startback/audit/shared.rb
|
142
|
+
- lib/startback/audit/trailer.rb
|
143
|
+
- lib/startback/caching/entity_cache.rb
|
144
|
+
- lib/startback/caching/no_store.rb
|
145
|
+
- lib/startback/caching/store.rb
|
146
|
+
- lib/startback/context.rb
|
147
|
+
- lib/startback/context/h_factory.rb
|
148
|
+
- lib/startback/context/middleware.rb
|
149
|
+
- lib/startback/errors.rb
|
150
|
+
- lib/startback/event.rb
|
151
|
+
- lib/startback/event/agent.rb
|
152
|
+
- lib/startback/event/bus.rb
|
153
|
+
- lib/startback/event/bus/bunny.rb
|
154
|
+
- lib/startback/event/bus/bunny/async.rb
|
155
|
+
- lib/startback/event/bus/memory.rb
|
156
|
+
- lib/startback/event/bus/memory/async.rb
|
157
|
+
- lib/startback/event/bus/memory/sync.rb
|
158
|
+
- lib/startback/event/engine.rb
|
159
|
+
- lib/startback/event/ext/context.rb
|
160
|
+
- lib/startback/event/ext/operation.rb
|
137
161
|
- lib/startback/ext.rb
|
138
|
-
- lib/startback/ext/
|
139
|
-
- lib/startback/ext/
|
140
|
-
- lib/startback/
|
141
|
-
- lib/startback/
|
142
|
-
- lib/startback/
|
143
|
-
- lib/startback/
|
144
|
-
- lib/startback/
|
145
|
-
- lib/startback/
|
146
|
-
- lib/startback/
|
147
|
-
- lib/startback/
|
148
|
-
- lib/startback/
|
149
|
-
- lib/startback/
|
150
|
-
- lib/startback/
|
151
|
-
- lib/startback/
|
152
|
-
- lib/startback/
|
153
|
-
- lib/startback/
|
154
|
-
- lib/startback/
|
155
|
-
- lib/startback/
|
156
|
-
- lib/startback/
|
157
|
-
- lib/startback/
|
162
|
+
- lib/startback/ext/date_time.rb
|
163
|
+
- lib/startback/ext/time.rb
|
164
|
+
- lib/startback/model.rb
|
165
|
+
- lib/startback/operation.rb
|
166
|
+
- lib/startback/operation/error_operation.rb
|
167
|
+
- lib/startback/operation/multi_operation.rb
|
168
|
+
- lib/startback/services.rb
|
169
|
+
- lib/startback/support.rb
|
170
|
+
- lib/startback/support/data_object.rb
|
171
|
+
- lib/startback/support/env.rb
|
172
|
+
- lib/startback/support/fake_logger.rb
|
173
|
+
- lib/startback/support/hooks.rb
|
174
|
+
- lib/startback/support/log_formatter.rb
|
175
|
+
- lib/startback/support/logger.rb
|
176
|
+
- lib/startback/support/operation_runner.rb
|
177
|
+
- lib/startback/support/robustness.rb
|
178
|
+
- lib/startback/support/transaction_manager.rb
|
179
|
+
- lib/startback/support/transaction_policy.rb
|
180
|
+
- lib/startback/support/world.rb
|
181
|
+
- lib/startback/version.rb
|
182
|
+
- lib/startback/web/api.rb
|
183
|
+
- lib/startback/web/auto_caching.rb
|
184
|
+
- lib/startback/web/catch_all.rb
|
185
|
+
- lib/startback/web/cors_headers.rb
|
186
|
+
- lib/startback/web/health_check.rb
|
187
|
+
- lib/startback/web/magic_assets.rb
|
188
|
+
- lib/startback/web/magic_assets/ng_html_transformer.rb
|
189
|
+
- lib/startback/web/magic_assets/rake_tasks.rb
|
190
|
+
- lib/startback/web/middleware.rb
|
191
|
+
- lib/startback/web/prometheus.rb
|
192
|
+
- lib/startback/web/shield.rb
|
158
193
|
- spec/spec_helper.rb
|
159
|
-
- spec/unit/
|
160
|
-
- spec/unit/
|
161
|
-
- spec/unit/
|
162
|
-
- spec/unit/
|
163
|
-
- spec/unit/
|
194
|
+
- spec/unit/audit/test_prometheus.rb
|
195
|
+
- spec/unit/audit/test_trailer.rb
|
196
|
+
- spec/unit/caching/test_entity_cache.rb
|
197
|
+
- spec/unit/context/test_abstraction_factory.rb
|
198
|
+
- spec/unit/context/test_dup.rb
|
199
|
+
- spec/unit/context/test_fork.rb
|
200
|
+
- spec/unit/context/test_h_factory.rb
|
201
|
+
- spec/unit/context/test_middleware.rb
|
202
|
+
- spec/unit/context/test_with_world.rb
|
203
|
+
- spec/unit/context/test_world.rb
|
204
|
+
- spec/unit/event/bus/memory/test_async.rb
|
205
|
+
- spec/unit/event/bus/memory/test_sync.rb
|
206
|
+
- spec/unit/support/hooks/test_after_hook.rb
|
207
|
+
- spec/unit/support/hooks/test_before_hook.rb
|
208
|
+
- spec/unit/support/operation_runner/test_around_run.rb
|
209
|
+
- spec/unit/support/operation_runner/test_before_after_call.rb
|
210
|
+
- spec/unit/support/test_data_object.rb
|
211
|
+
- spec/unit/support/test_env.rb
|
212
|
+
- spec/unit/support/test_robusteness.rb
|
213
|
+
- spec/unit/support/test_transaction_manager.rb
|
214
|
+
- spec/unit/support/test_world.rb
|
215
|
+
- spec/unit/test_event.rb
|
216
|
+
- spec/unit/test_operation.rb
|
217
|
+
- spec/unit/test_support.rb
|
218
|
+
- spec/unit/web/fixtures/assets/app/hello.es6
|
219
|
+
- spec/unit/web/fixtures/assets/app/hello.html
|
220
|
+
- spec/unit/web/fixtures/assets/index.es6
|
221
|
+
- spec/unit/web/test_api.rb
|
222
|
+
- spec/unit/web/test_auto_caching.rb
|
223
|
+
- spec/unit/web/test_catch_all.rb
|
224
|
+
- spec/unit/web/test_cors_headers.rb
|
225
|
+
- spec/unit/web/test_healthcheck.rb
|
226
|
+
- spec/unit/web/test_magic_assets.rb
|
164
227
|
- tasks/test.rake
|
165
|
-
homepage:
|
228
|
+
homepage: https://www.enspirit.be
|
166
229
|
licenses:
|
167
230
|
- MIT
|
168
231
|
metadata: {}
|
@@ -181,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
244
|
- !ruby/object:Gem::Version
|
182
245
|
version: '0'
|
183
246
|
requirements: []
|
184
|
-
rubygems_version: 3.
|
247
|
+
rubygems_version: 3.1.2
|
185
248
|
signing_key:
|
186
249
|
specification_version: 4
|
187
250
|
summary: Asynchronous jobs on top of Startback
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Support
|
3
|
-
module OperationRunner
|
4
|
-
|
5
|
-
def run_as_job(op)
|
6
|
-
run Startback::Jobs::CreateJob.new({
|
7
|
-
isReady: false,
|
8
|
-
opClass: op.class.name,
|
9
|
-
opInput: op.input,
|
10
|
-
opContext: context.to_h,
|
11
|
-
createdBy: '',
|
12
|
-
})
|
13
|
-
end
|
14
|
-
|
15
|
-
end # module OperationRunner
|
16
|
-
end # module Support
|
17
|
-
end # module Startback
|
data/lib/startback/jobs/agent.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Jobs
|
3
|
-
class Agent < Startback::Event::Agent
|
4
|
-
|
5
|
-
def install_listeners
|
6
|
-
async Event::JobCreated, 'job-runner'
|
7
|
-
end
|
8
|
-
|
9
|
-
def call(event)
|
10
|
-
run RunJob.new(event.data.to_h)
|
11
|
-
end
|
12
|
-
|
13
|
-
end # class Agent
|
14
|
-
end # module Jobs
|
15
|
-
end # module Startback
|
data/lib/startback/jobs/api.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Jobs
|
3
|
-
class Api < Startback::Web::Api
|
4
|
-
|
5
|
-
get %r{/([^\/]+)/result/?} do |id|
|
6
|
-
job = context.factor(Services).get_job!(id: id)
|
7
|
-
Support::JobResult.for(job).api_serve(self)
|
8
|
-
end
|
9
|
-
|
10
|
-
end # class Api
|
11
|
-
end # module Jobs
|
12
|
-
end # module Startback
|
data/lib/startback/jobs/event.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Jobs
|
3
|
-
class Model
|
4
|
-
class Job < Model
|
5
|
-
def self.ref(data)
|
6
|
-
dress(data, 'Job.Ref')
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.full(data)
|
10
|
-
dress(data, 'Job.Full')
|
11
|
-
end
|
12
|
-
|
13
|
-
def ready?
|
14
|
-
self.isReady
|
15
|
-
end
|
16
|
-
|
17
|
-
def not_ready?
|
18
|
-
!ready?
|
19
|
-
end
|
20
|
-
|
21
|
-
def expired?
|
22
|
-
self.expiredAt && self.expiredAt < Time.now
|
23
|
-
end
|
24
|
-
|
25
|
-
def fully_consumed?
|
26
|
-
self.consumedMax && (self.consumedCount || 0 >= self.consumedMax)
|
27
|
-
end
|
28
|
-
|
29
|
-
def result
|
30
|
-
Support::JobResult.for(self)
|
31
|
-
end
|
32
|
-
end # class Job
|
33
|
-
end # class Model
|
34
|
-
end # module Jobs
|
35
|
-
end # module Startback
|
data/lib/startback/jobs/model.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Jobs
|
3
|
-
class CreateJob < Operation
|
4
|
-
|
5
|
-
def initialize(input)
|
6
|
-
super(System['Job.CreationRequest'].dress(input))
|
7
|
-
end
|
8
|
-
|
9
|
-
def call
|
10
|
-
@job = Model::Job.full({
|
11
|
-
id: SecureRandom.urlsafe_base64(16),
|
12
|
-
opInput: {},
|
13
|
-
opContext: {},
|
14
|
-
opResult: nil,
|
15
|
-
strategy: 'NotReady',
|
16
|
-
strategyOptions: {},
|
17
|
-
expiresAt: nil,
|
18
|
-
refreshFreq: nil,
|
19
|
-
refreshedAt: nil,
|
20
|
-
consumeMax: nil,
|
21
|
-
consumeCount: 0,
|
22
|
-
createdAt: Time.now,
|
23
|
-
createdBy: nil,
|
24
|
-
}.merge(input))
|
25
|
-
|
26
|
-
context.world.startback_jobs.insert(@job.to_data)
|
27
|
-
|
28
|
-
@job
|
29
|
-
end
|
30
|
-
|
31
|
-
emits(Event::JobCreated) do
|
32
|
-
{ id: @job.id }
|
33
|
-
end
|
34
|
-
|
35
|
-
end # class CreateJob
|
36
|
-
end # module Jobs
|
37
|
-
end # module Startback
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Jobs
|
3
|
-
class RunJob < Operation
|
4
|
-
|
5
|
-
def initialize(input)
|
6
|
-
super(System['Job.Ref'].dress(input))
|
7
|
-
end
|
8
|
-
|
9
|
-
def call
|
10
|
-
services = context.factor(Services)
|
11
|
-
@job = services.get_job!(input)
|
12
|
-
|
13
|
-
job_context = context.fork(@job.op_context)
|
14
|
-
job_class = ::Kernel.const_get(@job.op_class)
|
15
|
-
job_input = @job.op_input
|
16
|
-
|
17
|
-
op_result = with_context(job_context) do
|
18
|
-
run job_class.new(job_input)
|
19
|
-
end
|
20
|
-
|
21
|
-
services.update_job!(input, {
|
22
|
-
opResult: op_result,
|
23
|
-
isReady: true,
|
24
|
-
})
|
25
|
-
|
26
|
-
op_result
|
27
|
-
end
|
28
|
-
|
29
|
-
emits(Event::JobRan) do
|
30
|
-
{ id: @job.id }
|
31
|
-
end
|
32
|
-
|
33
|
-
end # class RunJob
|
34
|
-
end # module Jobs
|
35
|
-
end # module Startback
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Jobs
|
3
|
-
class Services < Startback::Services
|
4
|
-
|
5
|
-
def get_job!(ref)
|
6
|
-
job_relvar = startback_jobs.restrict(ref)
|
7
|
-
Model::Job.full(job_relvar.one)
|
8
|
-
rescue Bmg::OneError
|
9
|
-
not_found_error!("Job #{ref[:id]}")
|
10
|
-
end
|
11
|
-
|
12
|
-
def update_job!(ref, update)
|
13
|
-
job_relvar = startback_jobs.restrict(ref)
|
14
|
-
job_relvar.update(update)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def startback_jobs
|
20
|
-
context.world.startback_jobs
|
21
|
-
end
|
22
|
-
|
23
|
-
end # class Services
|
24
|
-
end # module Jobs
|
25
|
-
end # module Startback
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Jobs
|
3
|
-
module Support
|
4
|
-
class JobResult
|
5
|
-
class Embedded < JobResult
|
6
|
-
|
7
|
-
def api_serve(api)
|
8
|
-
[200, {}, [job.opResult]]
|
9
|
-
end
|
10
|
-
|
11
|
-
end # class Embedded
|
12
|
-
end # class JobResult
|
13
|
-
end # module Support
|
14
|
-
end # module Jobs
|
15
|
-
end # module Startback
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Jobs
|
3
|
-
module Support
|
4
|
-
class JobResult
|
5
|
-
class NotReady < JobResult
|
6
|
-
|
7
|
-
def api_serve(api)
|
8
|
-
[202, {}, []]
|
9
|
-
end
|
10
|
-
|
11
|
-
end # class NotReady
|
12
|
-
end # class JobResult
|
13
|
-
end # module Support
|
14
|
-
end # module Jobs
|
15
|
-
end # module Startback
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Jobs
|
3
|
-
module Support
|
4
|
-
class JobResult
|
5
|
-
class Redirect < JobResult
|
6
|
-
|
7
|
-
DEFAULT_REDIRECT_OPTIONS = {
|
8
|
-
status: 301,
|
9
|
-
headers: {}
|
10
|
-
}.freeze
|
11
|
-
|
12
|
-
def api_serve(api)
|
13
|
-
options = redirect_options
|
14
|
-
[
|
15
|
-
options.status || 301,
|
16
|
-
options.headers.merge("Location" => job.opResult),
|
17
|
-
[]
|
18
|
-
]
|
19
|
-
end
|
20
|
-
|
21
|
-
def redirect_options
|
22
|
-
opts = DEFAULT_REDIRECT_OPTIONS.merge(
|
23
|
-
job.strategy_options
|
24
|
-
)
|
25
|
-
Startback::Model.new(opts)
|
26
|
-
end
|
27
|
-
|
28
|
-
end # class Embedded
|
29
|
-
end # class JobResult
|
30
|
-
end # module Support
|
31
|
-
end # module Jobs
|
32
|
-
end # module Startback
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Jobs
|
3
|
-
module Support
|
4
|
-
class JobResult
|
5
|
-
|
6
|
-
def initialize(job)
|
7
|
-
@job = job
|
8
|
-
end
|
9
|
-
private :initialize
|
10
|
-
|
11
|
-
attr_reader :job
|
12
|
-
|
13
|
-
def self.for(job)
|
14
|
-
unless job.is_ready?
|
15
|
-
JobResult::NotReady.new(job)
|
16
|
-
else
|
17
|
-
JobResult.const_get(job.strategy).new(job)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def api_serve(api)
|
22
|
-
raise NotImplementedError
|
23
|
-
end
|
24
|
-
|
25
|
-
end # class JobResult
|
26
|
-
end # module Support
|
27
|
-
end # module Jobs
|
28
|
-
end # module Startback
|
29
|
-
require_relative 'job_result/not_ready'
|
30
|
-
require_relative 'job_result/embedded'
|
31
|
-
require_relative 'job_result/redirect'
|
@@ -1 +0,0 @@
|
|
1
|
-
require_relative 'support/job_result'
|
data/lib/startback/jobs.fio
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
@import finitio/data
|
2
|
-
|
3
|
-
ClassName = String
|
4
|
-
|
5
|
-
DumpableHash = { ...: .Object }
|
6
|
-
|
7
|
-
Job.Ref = {
|
8
|
-
id : String
|
9
|
-
}
|
10
|
-
|
11
|
-
Job.Strategy = String(s | %w{Embedded NotReady Redirect}.include? s )
|
12
|
-
|
13
|
-
Job.Full = {
|
14
|
-
id : String
|
15
|
-
opClass : ClassName
|
16
|
-
opInput : DumpableHash
|
17
|
-
opContext : DumpableHash
|
18
|
-
opResult : .
|
19
|
-
isReady : Boolean
|
20
|
-
strategy : Job.Strategy
|
21
|
-
strategyOptions : DumpableHash
|
22
|
-
expiresAt : DateTime|Time|Nil
|
23
|
-
refreshFreq : String|Nil
|
24
|
-
refreshedAt : DateTime|Time|Nil
|
25
|
-
consumeMax : Integer|Nil
|
26
|
-
consumeCount : Integer|Nil
|
27
|
-
createdAt : DateTime|Time|Nil
|
28
|
-
createdBy : String|Nil
|
29
|
-
}
|
30
|
-
|
31
|
-
Job.CreationRequest = {
|
32
|
-
opClass : ClassName
|
33
|
-
opInput : DumpableHash
|
34
|
-
opContext : DumpableHash
|
35
|
-
createdBy : String
|
36
|
-
|
37
|
-
isReady : Boolean
|
38
|
-
strategy :? Job.Strategy
|
39
|
-
strategyOptions :? DumpableHash
|
40
|
-
|
41
|
-
expiresAt :? DateTime|Time
|
42
|
-
refreshFreq :? String
|
43
|
-
consumeMax :? Integer
|
44
|
-
}
|
data/lib/startback/jobs.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'path'
|
2
|
-
require 'finitio'
|
3
|
-
require 'startback'
|
4
|
-
require 'startback/event'
|
5
|
-
require 'startback/web/api'
|
6
|
-
|
7
|
-
module Startback
|
8
|
-
module Jobs
|
9
|
-
require_relative 'jobs/support'
|
10
|
-
require_relative 'jobs/model'
|
11
|
-
require_relative 'jobs/event'
|
12
|
-
require_relative 'jobs/operation'
|
13
|
-
require_relative 'jobs/services'
|
14
|
-
require_relative 'jobs/api'
|
15
|
-
require_relative 'jobs/agent'
|
16
|
-
|
17
|
-
require_relative './ext'
|
18
|
-
|
19
|
-
Finitio.stdlib_path(Path.dir.parent)
|
20
|
-
|
21
|
-
System = Finitio.system(Path.dir/'jobs.fio')
|
22
|
-
end
|
23
|
-
end
|