postjob 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/postjob.rb +22 -13
  3. data/lib/postjob/cli/events.rb +60 -0
  4. data/lib/postjob/cli/heartbeat.rb +55 -0
  5. data/lib/postjob/cli/hosts.rb +67 -0
  6. data/lib/postjob/cli/ps.rb +1 -13
  7. data/lib/postjob/cli/sessions.rb +83 -0
  8. data/lib/postjob/job.rb +4 -15
  9. data/lib/postjob/migrations/003_postjobs.sql +10 -8
  10. data/lib/postjob/migrations/003b_processing_columns.sql +8 -8
  11. data/lib/postjob/migrations/005_helpers.sql +3 -1
  12. data/lib/postjob/migrations/006_enqueue.sql +3 -0
  13. data/lib/postjob/migrations/006a_processing.sql +6 -26
  14. data/lib/postjob/migrations/007_job_results.sql +32 -13
  15. data/lib/postjob/migrations/008_checkout_runnable.sql +15 -21
  16. data/lib/postjob/migrations/008a_childjobs.sql +13 -0
  17. data/lib/postjob/migrations/010_settings.sql +18 -3
  18. data/lib/postjob/migrations/011_null_uuid.sql +7 -0
  19. data/lib/postjob/migrations/012_hosts.sql +42 -0
  20. data/lib/postjob/migrations/013_worker_sessions.sql +44 -0
  21. data/lib/postjob/migrations/014_postjob_session_id.sql +17 -0
  22. data/lib/postjob/migrations/015_events.sql +76 -0
  23. data/lib/postjob/migrations/016_sessions_functions.sql +16 -0
  24. data/lib/postjob/migrations/017_zombie_check.sql +58 -0
  25. data/lib/postjob/migrations/018_heartbeat.sql +28 -0
  26. data/lib/postjob/migrations/019_heartbeat_indices.sql +5 -0
  27. data/lib/postjob/queue.rb +41 -27
  28. data/lib/postjob/queue/notifications.rb +5 -4
  29. data/lib/postjob/queue/search.rb +2 -0
  30. data/lib/postjob/queue/settings.rb +11 -1
  31. data/lib/postjob/record.rb +17 -0
  32. data/lib/postjob/runner.rb +9 -2
  33. data/lib/postjob/worker_session.rb +76 -0
  34. data/lib/postjob/workflow.rb +0 -4
  35. data/lib/tools/atomic_store.rb +17 -0
  36. data/lib/tools/heartbeat.rb +151 -0
  37. data/lib/tools/history.rb +25 -0
  38. data/spec/postjob/events/heartbeat_event_spec.rb +85 -0
  39. data/spec/postjob/events/job_event_spec.rb +80 -0
  40. data/spec/postjob/job_control/max_attempts_spec.rb +0 -2
  41. data/spec/postjob/queue/search_spec.rb +0 -14
  42. data/spec/postjob/worker_session_spec.rb +41 -0
  43. data/spec/spec_helper.rb +9 -0
  44. data/spec/support/test_helper.rb +11 -1
  45. metadata +43 -3
  46. data/spec/postjob/job_control/workflow_status_spec.rb +0 -52
@@ -10,9 +10,7 @@ module MaxAttemptWorkflow
10
10
  end
11
11
 
12
12
  def self.run(max_attempts)
13
- set_workflow_status "starting up"
14
13
  await async ChildWorker, max_attempts: max_attempts
15
- set_workflow_status "starting finished"
16
14
  end
17
15
 
18
16
  Postjob.register_workflow self
@@ -2,16 +2,11 @@ require "spec_helper"
2
2
 
3
3
  module SearchWorkflow
4
4
  def self.run
5
- set_workflow_status "starting-up"
6
-
7
5
  job = async :manual, timeout: 10
8
- set_workflow_status "created-manual"
9
6
 
10
7
  _token = workflow_token job
11
- set_workflow_status "created-manual-token"
12
8
 
13
9
  manual_result = await job
14
- set_workflow_status "got-manual-token"
15
10
 
16
11
  "manual-result:#{manual_result}"
17
12
  end
@@ -39,7 +34,6 @@ describe "Postjob::Queue.search" do
39
34
  :id,
40
35
  :full_id,
41
36
  :job,
42
- :workflow_status,
43
37
  :status,
44
38
  :error,
45
39
  :result,
@@ -74,14 +68,6 @@ describe "Postjob::Queue.search" do
74
68
  result = Simple::SQL.all(scope, into: OpenStruct)
75
69
  expect(result.length).to eq(2)
76
70
  end
77
-
78
- it "sorts by id" do
79
- scope = Postjob::Queue.search
80
- result = Simple::SQL.all(scope, into: OpenStruct)
81
-
82
- # Note that the second job has a id larger than the original job's id.
83
- expect(result.first.id).to eq(id)
84
- end
85
71
  end
86
72
 
87
73
  describe "filtering" do
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ describe "Postjob::WorkerSession.start!" do
4
+ let(:store_path) { ".postjob.host_id" }
5
+
6
+ def session_count
7
+ Simple::SQL.ask "SELECT count(*) from postjob.worker_sessions"
8
+ end
9
+
10
+ let(:workflows_with_versions) { %w(Foo Foo@0) }
11
+
12
+ it "creates a new session" do
13
+ expect do
14
+ session = Postjob::WorkerSession.start!(workflows_with_versions)
15
+ expect(session.id).to match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i)
16
+ end.to change { session_count }.by(1)
17
+ end
18
+
19
+ it "stores and reuses the host_id" do
20
+ FileUtils.rm_rf store_path
21
+
22
+ session = Postjob::WorkerSession.start!(workflows_with_versions)
23
+ expect(File.read(store_path)).to match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i)
24
+
25
+ session2 = Postjob::WorkerSession.start!(workflows_with_versions)
26
+ expect(session2.host_id).to eq(session.host_id)
27
+ end
28
+
29
+ context "when passing in an invalid host id" do
30
+ it "raises an argument error" do
31
+ invalid_uuid = "foo"
32
+ File.open store_path, "w" do |io|
33
+ io.write invalid_uuid
34
+ end
35
+
36
+ expect do
37
+ Postjob::WorkerSession.start!(workflows_with_versions)
38
+ end.to raise_error(ArgumentError)
39
+ end
40
+ end
41
+ end
@@ -24,6 +24,11 @@ Simple::SQL.logger = Postjob.logger = logger
24
24
  require "./spec/support/configure_database"
25
25
  require "./spec/support/test_helper"
26
26
 
27
+ if ENV["VERBOSE"]
28
+ logger = Logger.new(STDERR)
29
+ Simple::SQL.logger = Postjob.logger = logger
30
+ end
31
+
27
32
  RSpec.configure do |config|
28
33
  config.run_all_when_everything_filtered = true
29
34
  config.filter_run focus: (ENV["CI"] != "true")
@@ -33,4 +38,8 @@ RSpec.configure do |config|
33
38
 
34
39
  config.before(:all) {}
35
40
  config.after {}
41
+
42
+ config.before(:all) do
43
+ FileUtils.rm_rf ::Postjob::WorkerSession::HOST_ID_STORE
44
+ end
36
45
  end
@@ -24,10 +24,20 @@ module TestHelper
24
24
  Simple::SQL.ask "SELECT token FROM tokens WHERE postjob_id=$1", job.id
25
25
  end
26
26
 
27
+ def resolve_all
28
+ query = "SELECT id FROM postjob.postjobs WHERE status NOT IN ('ok', 'failed', 'timeout')"
29
+
30
+ loop do
31
+ break unless Simple::SQL.ask(query)
32
+ Postjob.process_all
33
+ sleep 0.05
34
+ end
35
+ end
36
+
27
37
  def print_sql(sql, *args)
28
38
  require "table_print"
29
39
 
30
- records = Simple::SQL.all(sql, *args)
40
+ records = Simple::SQL.all(sql, *args, into: Hash)
31
41
  tp records
32
42
  end
33
43
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postjob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-16 00:00:00.000000000 Z
11
+ date: 2018-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -194,6 +194,26 @@ dependencies:
194
194
  - - ">="
195
195
  - !ruby/object:Gem::Version
196
196
  version: 1.1.1
197
+ - !ruby/object:Gem::Dependency
198
+ name: vmstat
199
+ requirement: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - "~>"
202
+ - !ruby/object:Gem::Version
203
+ version: '2.3'
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: 2.3.0
207
+ type: :runtime
208
+ prerelease: false
209
+ version_requirements: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - "~>"
212
+ - !ruby/object:Gem::Version
213
+ version: '2.3'
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: 2.3.0
197
217
  description: restartable, asynchronous, and distributed processes
198
218
  email:
199
219
  - radiospiel@open-lab.org
@@ -207,9 +227,13 @@ files:
207
227
  - lib/postjob.rb
208
228
  - lib/postjob/cli.rb
209
229
  - lib/postjob/cli/db.rb
230
+ - lib/postjob/cli/events.rb
231
+ - lib/postjob/cli/heartbeat.rb
232
+ - lib/postjob/cli/hosts.rb
210
233
  - lib/postjob/cli/job.rb
211
234
  - lib/postjob/cli/ps.rb
212
235
  - lib/postjob/cli/run.rb
236
+ - lib/postjob/cli/sessions.rb
213
237
  - lib/postjob/cli/version.rb
214
238
  - lib/postjob/error.rb
215
239
  - lib/postjob/job.rb
@@ -227,26 +251,42 @@ files:
227
251
  - lib/postjob/migrations/008a_childjobs.sql
228
252
  - lib/postjob/migrations/009_tokens.sql
229
253
  - lib/postjob/migrations/010_settings.sql
254
+ - lib/postjob/migrations/011_null_uuid.sql
255
+ - lib/postjob/migrations/012_hosts.sql
256
+ - lib/postjob/migrations/013_worker_sessions.sql
257
+ - lib/postjob/migrations/014_postjob_session_id.sql
258
+ - lib/postjob/migrations/015_events.sql
259
+ - lib/postjob/migrations/016_sessions_functions.sql
260
+ - lib/postjob/migrations/017_zombie_check.sql
261
+ - lib/postjob/migrations/018_heartbeat.sql
262
+ - lib/postjob/migrations/019_heartbeat_indices.sql
230
263
  - lib/postjob/queue.rb
231
264
  - lib/postjob/queue/encoder.rb
232
265
  - lib/postjob/queue/notifications.rb
233
266
  - lib/postjob/queue/search.rb
234
267
  - lib/postjob/queue/settings.rb
268
+ - lib/postjob/record.rb
235
269
  - lib/postjob/registry.rb
236
270
  - lib/postjob/runner.rb
271
+ - lib/postjob/worker_session.rb
237
272
  - lib/postjob/workflow.rb
273
+ - lib/tools/atomic_store.rb
274
+ - lib/tools/heartbeat.rb
275
+ - lib/tools/history.rb
238
276
  - spec/postjob/enqueue_spec.rb
277
+ - spec/postjob/events/heartbeat_event_spec.rb
278
+ - spec/postjob/events/job_event_spec.rb
239
279
  - spec/postjob/full_workflow_spec.rb
240
280
  - spec/postjob/job_control/error_status_spec.rb
241
281
  - spec/postjob/job_control/manual_spec.rb
242
282
  - spec/postjob/job_control/max_attempts_spec.rb
243
283
  - spec/postjob/job_control/timeout_spec.rb
244
- - spec/postjob/job_control/workflow_status_spec.rb
245
284
  - spec/postjob/process_job_spec.rb
246
285
  - spec/postjob/queue/encoder_spec.rb
247
286
  - spec/postjob/queue/search_spec.rb
248
287
  - spec/postjob/run_spec.rb
249
288
  - spec/postjob/step_spec.rb
289
+ - spec/postjob/worker_session_spec.rb
250
290
  - spec/postjob/workflows/child_workflow_spec.rb
251
291
  - spec/spec_helper.rb
252
292
  - spec/support/configure_active_record.rb
@@ -1,52 +0,0 @@
1
- require "spec_helper"
2
-
3
- module WorkflowStatusWorkflow
4
- def self.run
5
- set_workflow_status "starting-up"
6
-
7
- job = async :manual, timeout: 10
8
- set_workflow_status "created-manual"
9
-
10
- _token = workflow_token job
11
- set_workflow_status "created-manual-token"
12
-
13
- manual_result = await job
14
- set_workflow_status "got-manual-token"
15
-
16
- "manual-result:#{manual_result}"
17
- end
18
-
19
- Postjob.register_workflow self
20
- end
21
-
22
- describe "workflow_status" do
23
- let!(:id) { Postjob.enqueue! "WorkflowStatusWorkflow" }
24
-
25
- include TestHelper
26
-
27
- before do
28
- Postjob.process_all
29
- end
30
-
31
- def load_child_job
32
- TestHelper.load_job "SELECT * FROM postjobs WHERE parent_id=$1", id
33
- end
34
-
35
- def token
36
- load_token(load_child_job)
37
- end
38
-
39
- it "creates a token" do
40
- expect! token => /[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[a-fA-F0-9]{4}-[A-F0-9]{12}/i
41
- end
42
-
43
- it "the token can be used to resolve the load_child_job" do
44
- Postjob.resolve token: token, result: "foobar"
45
- expect(load_child_job.status).to eq("ok")
46
- expect(load_job(id).workflow_status).to eq("created-manual-token")
47
-
48
- Postjob.process_all
49
- expect(load_job(id).status).to eq("ok")
50
- expect(load_job(id).workflow_status).to eq("got-manual-token")
51
- end
52
- end