postjob 0.5.7 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/postjob/host.rb +12 -1
- data/spec/postjob/host_spec.rb +37 -0
- data/spec/spec_helper.rb +4 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e96734197915c9658e20b670186347fa9112a95a
|
4
|
+
data.tar.gz: a607352a5f6675c9bb6ae80fd0f289f7142692d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1b8e20e7893ef1fcd3a1d53466714bcf5c106e1dec67a0745f25f29db04185c92bb7ac6e9cdf83dce299bea3f6f20cd3f6aac27c1c36551862157d902d4b1ba
|
7
|
+
data.tar.gz: 0c0fe39302fa99ff9fd8fe03f70a2c81a950276cc0e6b4d86c95b96657e917da3289f176d71273d71736e2c47932aa265e9616a5b37e1df2a87d03d6fffe699d
|
data/lib/postjob/host.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require_relative "./record"
|
2
|
+
require "tempfile"
|
2
3
|
|
3
4
|
class Postjob::Host < Postjob::Record
|
4
5
|
class << self
|
5
6
|
def clear_storage
|
7
|
+
@host_id = nil
|
8
|
+
|
6
9
|
File.unlink(storage_path) if File.exist?(storage_path)
|
7
10
|
end
|
8
11
|
|
@@ -12,13 +15,21 @@ class Postjob::Host < Postjob::Record
|
|
12
15
|
|
13
16
|
private
|
14
17
|
|
18
|
+
# This method returns the path to a file which will hold the host_id. Two runners
|
19
|
+
# with the same host_id should have access to the same part of the file system.
|
20
|
+
# Therefore different system users need to have different host ids.
|
21
|
+
#
|
22
|
+
# In addition the path returned from the method must be readable and writable by
|
23
|
+
# the current user. We choose a tmp location for that reason. (A /var location
|
24
|
+
# would be even better - however, our systems do not have a user-writable /var).
|
15
25
|
def storage_path
|
16
26
|
env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
17
|
-
"
|
27
|
+
File.join Dir.tmpdir, "postjob.#{env}.#{Process.uid}.host_id"
|
18
28
|
end
|
19
29
|
|
20
30
|
def atomic_set_and_get(path)
|
21
31
|
value = nil
|
32
|
+
|
22
33
|
File.open(path, File::RDWR | File::CREAT, 0644) do |f|
|
23
34
|
f.flock(File::LOCK_EX)
|
24
35
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Postjob::Host do
|
4
|
+
describe ".host_id" do
|
5
|
+
UUID_REGEXP = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i
|
6
|
+
|
7
|
+
it "returns a host id UUID string" do
|
8
|
+
expect(Postjob::Host.host_id).to match(UUID_REGEXP)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Storage" do
|
13
|
+
let(:test_file_path) { ".postjob.test.host_id" }
|
14
|
+
|
15
|
+
before do
|
16
|
+
allow(Postjob::Host).to receive(:storage_path).and_return(test_file_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".clear_storage" do
|
20
|
+
it "removes the host id file" do
|
21
|
+
Postjob::Host.clear_storage
|
22
|
+
|
23
|
+
expect(File).not_to exist(test_file_path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ".host_id" do
|
28
|
+
UUID_REGEXP = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i
|
29
|
+
|
30
|
+
it "writes a file to the tmp directory" do
|
31
|
+
Postjob::Host.host_id
|
32
|
+
|
33
|
+
expect(File).to exist(test_file_path)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -29,6 +29,9 @@ if ENV["VERBOSE"]
|
|
29
29
|
Simple::SQL.logger = Postjob.logger = logger
|
30
30
|
end
|
31
31
|
|
32
|
+
# Ensure there is a tmp directory for testing host id file ...
|
33
|
+
Dir.mkdir("tmp") unless File.exist?("tmp")
|
34
|
+
|
32
35
|
RSpec.configure do |config|
|
33
36
|
config.run_all_when_everything_filtered = true
|
34
37
|
config.filter_run focus: (ENV["CI"] != "true")
|
@@ -39,7 +42,7 @@ RSpec.configure do |config|
|
|
39
42
|
config.before(:all) {}
|
40
43
|
config.after {}
|
41
44
|
|
42
|
-
config.before(:
|
45
|
+
config.before(:each) do
|
43
46
|
::Postjob::Host.clear_storage
|
44
47
|
end
|
45
48
|
end
|
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.5.
|
4
|
+
version: 0.5.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -285,6 +285,7 @@ files:
|
|
285
285
|
- spec/postjob/events/job_event_spec.rb
|
286
286
|
- spec/postjob/events/zombie_event_spec.rb
|
287
287
|
- spec/postjob/full_workflow_spec.rb
|
288
|
+
- spec/postjob/host_spec.rb
|
288
289
|
- spec/postjob/job_control/error_status_spec.rb
|
289
290
|
- spec/postjob/job_control/manual_spec.rb
|
290
291
|
- spec/postjob/job_control/max_attempts_spec.rb
|