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.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -3
  3. data/README.md +13 -0
  4. data/lib/startback/audit/prometheus.rb +87 -0
  5. data/lib/startback/audit/shared.rb +17 -0
  6. data/lib/startback/audit/trailer.rb +129 -0
  7. data/lib/startback/audit.rb +3 -0
  8. data/lib/startback/caching/entity_cache.rb +157 -0
  9. data/lib/startback/caching/no_store.rb +28 -0
  10. data/lib/startback/caching/store.rb +34 -0
  11. data/lib/startback/context/h_factory.rb +43 -0
  12. data/lib/startback/context/middleware.rb +53 -0
  13. data/lib/startback/context.rb +122 -0
  14. data/lib/startback/errors.rb +197 -0
  15. data/lib/startback/event/agent.rb +84 -0
  16. data/lib/startback/event/bus/bunny/async.rb +162 -0
  17. data/lib/startback/event/bus/bunny.rb +1 -0
  18. data/lib/startback/event/bus/memory/async.rb +45 -0
  19. data/lib/startback/event/bus/memory/sync.rb +35 -0
  20. data/lib/startback/event/bus/memory.rb +2 -0
  21. data/lib/startback/event/bus.rb +100 -0
  22. data/lib/startback/event/engine.rb +94 -0
  23. data/lib/startback/event/ext/context.rb +5 -0
  24. data/lib/startback/event/ext/operation.rb +13 -0
  25. data/lib/startback/event.rb +47 -0
  26. data/lib/startback/ext/date_time.rb +9 -0
  27. data/lib/startback/ext/time.rb +9 -0
  28. data/lib/startback/ext.rb +2 -2
  29. data/lib/startback/model.rb +6 -0
  30. data/lib/startback/operation/error_operation.rb +19 -0
  31. data/lib/startback/operation/multi_operation.rb +28 -0
  32. data/lib/startback/operation.rb +78 -0
  33. data/lib/startback/services.rb +11 -0
  34. data/lib/startback/support/data_object.rb +71 -0
  35. data/lib/startback/support/env.rb +41 -0
  36. data/lib/startback/support/fake_logger.rb +18 -0
  37. data/lib/startback/support/hooks.rb +48 -0
  38. data/lib/startback/support/log_formatter.rb +34 -0
  39. data/lib/startback/support/logger.rb +34 -0
  40. data/lib/startback/support/operation_runner.rb +150 -0
  41. data/lib/startback/support/robustness.rb +157 -0
  42. data/lib/startback/support/transaction_manager.rb +25 -0
  43. data/lib/startback/support/transaction_policy.rb +33 -0
  44. data/lib/startback/support/world.rb +54 -0
  45. data/lib/startback/support.rb +26 -0
  46. data/lib/startback/version.rb +8 -0
  47. data/lib/startback/web/api.rb +99 -0
  48. data/lib/startback/web/auto_caching.rb +85 -0
  49. data/lib/startback/web/catch_all.rb +52 -0
  50. data/lib/startback/web/cors_headers.rb +80 -0
  51. data/lib/startback/web/health_check.rb +49 -0
  52. data/lib/startback/web/magic_assets/ng_html_transformer.rb +80 -0
  53. data/lib/startback/web/magic_assets/rake_tasks.rb +64 -0
  54. data/lib/startback/web/magic_assets.rb +98 -0
  55. data/lib/startback/web/middleware.rb +13 -0
  56. data/lib/startback/web/prometheus.rb +16 -0
  57. data/lib/startback/web/shield.rb +58 -0
  58. data/lib/startback.rb +43 -0
  59. data/spec/spec_helper.rb +33 -26
  60. data/spec/unit/audit/test_prometheus.rb +72 -0
  61. data/spec/unit/audit/test_trailer.rb +105 -0
  62. data/spec/unit/caching/test_entity_cache.rb +136 -0
  63. data/spec/unit/context/test_abstraction_factory.rb +64 -0
  64. data/spec/unit/context/test_dup.rb +42 -0
  65. data/spec/unit/context/test_fork.rb +37 -0
  66. data/spec/unit/context/test_h_factory.rb +31 -0
  67. data/spec/unit/context/test_middleware.rb +45 -0
  68. data/spec/unit/context/test_with_world.rb +20 -0
  69. data/spec/unit/context/test_world.rb +17 -0
  70. data/spec/unit/event/bus/memory/test_async.rb +43 -0
  71. data/spec/unit/event/bus/memory/test_sync.rb +43 -0
  72. data/spec/unit/support/hooks/test_after_hook.rb +54 -0
  73. data/spec/unit/support/hooks/test_before_hook.rb +54 -0
  74. data/spec/unit/support/operation_runner/test_around_run.rb +156 -0
  75. data/spec/unit/support/operation_runner/test_before_after_call.rb +48 -0
  76. data/spec/unit/support/test_data_object.rb +156 -0
  77. data/spec/unit/support/test_env.rb +75 -0
  78. data/spec/unit/support/test_robusteness.rb +229 -0
  79. data/spec/unit/support/test_transaction_manager.rb +64 -0
  80. data/spec/unit/support/test_world.rb +72 -0
  81. data/spec/unit/test_event.rb +62 -0
  82. data/spec/unit/test_operation.rb +55 -0
  83. data/spec/unit/test_support.rb +40 -0
  84. data/spec/unit/web/fixtures/assets/app/hello.es6 +4 -0
  85. data/spec/unit/web/fixtures/assets/app/hello.html +1 -0
  86. data/spec/unit/web/fixtures/assets/index.es6 +1 -0
  87. data/spec/unit/web/test_api.rb +82 -0
  88. data/spec/unit/web/test_auto_caching.rb +81 -0
  89. data/spec/unit/web/test_catch_all.rb +77 -0
  90. data/spec/unit/web/test_cors_headers.rb +88 -0
  91. data/spec/unit/web/test_healthcheck.rb +59 -0
  92. data/spec/unit/web/test_magic_assets.rb +82 -0
  93. data/tasks/test.rake +1 -0
  94. metadata +94 -31
  95. data/lib/startback/ext/support/operation_runner.rb +0 -17
  96. data/lib/startback/ext/web/api.rb +0 -12
  97. data/lib/startback/jobs/agent.rb +0 -15
  98. data/lib/startback/jobs/api.rb +0 -12
  99. data/lib/startback/jobs/event/job_created.rb +0 -8
  100. data/lib/startback/jobs/event/job_ran.rb +0 -8
  101. data/lib/startback/jobs/event.rb +0 -8
  102. data/lib/startback/jobs/model/job.rb +0 -35
  103. data/lib/startback/jobs/model.rb +0 -12
  104. data/lib/startback/jobs/operation/create_job.rb +0 -37
  105. data/lib/startback/jobs/operation/run_job.rb +0 -35
  106. data/lib/startback/jobs/operation.rb +0 -8
  107. data/lib/startback/jobs/services.rb +0 -25
  108. data/lib/startback/jobs/support/job_result/embedded.rb +0 -15
  109. data/lib/startback/jobs/support/job_result/not_ready.rb +0 -15
  110. data/lib/startback/jobs/support/job_result/redirect.rb +0 -32
  111. data/lib/startback/jobs/support/job_result.rb +0 -31
  112. data/lib/startback/jobs/support.rb +0 -1
  113. data/lib/startback/jobs.fio +0 -44
  114. data/lib/startback/jobs.rb +0 -23
  115. data/spec/unit/api/test_job_result.rb +0 -121
  116. data/spec/unit/model/test_job.rb +0 -23
  117. data/spec/unit/operation/test_create_job.rb +0 -42
  118. data/spec/unit/operation/test_run_job.rb +0 -37
  119. data/spec/unit/test_finitio_schema.rb +0 -20
@@ -1,121 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Startback
4
- module Jobs
5
- describe Api, "GET /{id}/result/" do
6
- include Rack::Test::Methods
7
-
8
- let(:job_data) do
9
- a_job_data(override)
10
- end
11
-
12
- let(:jobs_relvar) do
13
- Bmg.mutable([job_data])
14
- end
15
-
16
- let(:context) do
17
- Context.new.with_world(startback_jobs: jobs_relvar)
18
- end
19
-
20
- let(:app) do
21
- context = self.context
22
- Rack::Builder.new do
23
- use Context::Middleware, context
24
- run Jobs::Api
25
- end
26
- end
27
-
28
- let(:job_id) do
29
- 'abcdef'
30
- end
31
-
32
- subject do
33
- get "/#{job_id}/result/"
34
- end
35
-
36
- context 'when the job does not exist' do
37
- let(:job_id) do
38
- "no-such-one"
39
- end
40
-
41
- let(:override) do
42
- {}
43
- end
44
-
45
- it 'raises' do
46
- expect{
47
- subject
48
- }.to raise_error(Startback::Errors::NotFoundError)
49
- end
50
- end
51
-
52
- context 'when the job is not ready yet' do
53
- let(:override) do
54
- {
55
- isReady: false,
56
- strategy: 'NotReady',
57
- }
58
- end
59
-
60
- it 'works fine' do
61
- res = subject
62
- expect(res.status).to eql(202)
63
- expect(res.body).to be_empty
64
- end
65
- end
66
-
67
- context 'when the job is ready' do
68
- let(:override) do
69
- {
70
- isReady: true,
71
- opResult: 'Hello!!',
72
- strategy: 'Embedded'
73
- }
74
- end
75
-
76
- it 'works fine' do
77
- res = subject
78
- expect(res.status).to eql(200)
79
- expect(res.body).to eql("Hello!!")
80
- end
81
- end
82
-
83
- context 'when the job is ready and has to redirect' do
84
- let(:override) do
85
- {
86
- isReady: true,
87
- strategy: 'Redirect',
88
- opResult: 'http://google.com',
89
- }
90
- end
91
-
92
- it 'works fine' do
93
- res = subject
94
- expect(res.status).to eql(301)
95
- expect(res['Location']).to eql("http://google.com")
96
- end
97
- end
98
-
99
- context 'when the job is ready and has to redirect with a 302' do
100
- let(:override) do
101
- {
102
- isReady: true,
103
- strategy: 'Redirect',
104
- strategyOptions: {
105
- 'status' => 302,
106
- 'headers' => { 'X-Mine' => 'foo' }
107
- },
108
- opResult: 'http://google.com',
109
- }
110
- end
111
-
112
- it 'works fine' do
113
- res = subject
114
- expect(res.status).to eql(302)
115
- expect(res['X-Mine']).to eql('foo')
116
- expect(res['Location']).to eql("http://google.com")
117
- end
118
- end
119
- end
120
- end
121
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Startback
4
- module Jobs
5
- class Model
6
- describe Job do
7
- it 'makes it easy to create an instance' do
8
- job = Job.new(a_job_data)
9
- expect(job.id).to eql('abcdef')
10
- expect(job[:id]).to eql('abcdef')
11
- expect(job.ready?).to eql(false)
12
- end
13
-
14
- it 'makes it easy to dress an instance' do
15
- job = Job.full(a_job_data)
16
- expect(job.id).to eql('abcdef')
17
- expect(job[:id]).to eql('abcdef')
18
- expect(job.ready?).to eql(false)
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Startback
4
- module Jobs
5
- describe CreateJob do
6
-
7
- let(:request) do
8
- {
9
- isReady: false,
10
- opClass: 'CowSay',
11
- opInput: {},
12
- opContext: {},
13
- createdBy: 'blambeau',
14
- }
15
- end
16
-
17
- let(:jobs_relvar) do
18
- Bmg.mutable([])
19
- end
20
-
21
- let(:context) do
22
- Context.new.with_world(startback_jobs: jobs_relvar)
23
- end
24
-
25
- subject do
26
- CreateJob.new(request).bind({
27
- context: context,
28
- }).call
29
- end
30
-
31
- it 'creates a job' do
32
- expect(subject).to be_a(Model::Job)
33
- expect(subject.id).not_to be_nil
34
- end
35
-
36
- it 'inserts the job in the relvar' do
37
- subject
38
- expect(jobs_relvar.count).to eql(1)
39
- end
40
- end
41
- end
42
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Startback
4
- module Jobs
5
- describe RunJob do
6
-
7
- let(:job_data) do
8
- a_job_data
9
- end
10
-
11
- let(:jobs_relvar) do
12
- Bmg.mutable([job_data])
13
- end
14
-
15
- let(:context) do
16
- Context.new.with_world(startback_jobs: jobs_relvar)
17
- end
18
-
19
- subject do
20
- RunJob.new(id: 'abcdef').bind({
21
- context: context,
22
- }).call
23
- end
24
-
25
- it 'runs the job' do
26
- expect(subject).to eql('Hello !!')
27
- end
28
-
29
- it 'updates the job' do
30
- subject
31
- job_info = jobs_relvar.one
32
- expect(job_info[:opResult]).to eql('Hello !!')
33
- expect(job_info[:isReady]).to eql(true)
34
- end
35
- end
36
- end
37
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Startback
4
- module Jobs
5
- describe 'Finitio schemas' do
6
-
7
- it 'is correctly installed on stdlib' do
8
- system = Finitio.system <<~FIO
9
- @import startback/jobs
10
-
11
- Job.Ref
12
- FIO
13
- expect {
14
- system.dress({ id: "hello" })
15
- }.not_to raise_error
16
- end
17
-
18
- end
19
- end
20
- end