kube_queue 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -6
- data/docker/test_worker.rb +4 -5
- data/lib/kube_queue/executor.rb +2 -2
- data/lib/kube_queue/job_configuration.rb +34 -20
- data/lib/kube_queue/version.rb +1 -1
- data/lib/kube_queue/worker.rb +25 -38
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1511d8cfdd1b8fb8375d4162e389750b4372bc19
|
4
|
+
data.tar.gz: 963ace432f1420c863d94d491e81611fa7141279
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92c9790d5954b947e494e408556ba5cf5ddac75c2f5c4dc70b094833f2afdd24d4e565bcb3da86951c070283df1451d73d14dc672b74103cddfea40639b557b9
|
7
|
+
data.tar.gz: 3932e801e465f3d5b7427dfd027af5b0680c8fffc338ab7f8abd151ca86010617386f00b35941a604436c94fc638e0b1aa4192f5f7198758cbe30caae7959170
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
## Features
|
4
4
|
|
5
|
+
- ActiveJob integration
|
5
6
|
- Support multiple kubernetes client configuration.
|
6
7
|
- Support templating and customization for kubernetes job manifest.
|
7
8
|
- Job dosen't returns id. Can not track job details from code.
|
@@ -12,7 +13,7 @@
|
|
12
13
|
Add this line to your application's Gemfile:
|
13
14
|
|
14
15
|
```ruby
|
15
|
-
gem '
|
16
|
+
gem 'kube_queue'
|
16
17
|
```
|
17
18
|
|
18
19
|
And then execute:
|
@@ -21,7 +22,7 @@ And then execute:
|
|
21
22
|
|
22
23
|
Or install it yourself as:
|
23
24
|
|
24
|
-
$ gem install
|
25
|
+
$ gem install kube_queue
|
25
26
|
|
26
27
|
## Getting Started
|
27
28
|
|
@@ -31,11 +32,11 @@ Implement worker:
|
|
31
32
|
class TestWorker
|
32
33
|
include KubeQueue::Worker
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
job_name 'kube-queue-test'
|
36
|
+
image "my-registry/my-image"
|
37
|
+
container_name 'kube-queue-test'
|
37
38
|
|
38
|
-
|
39
|
+
command 'bundle', 'exec', 'kube_queue', 'TestWorker', '-r', './test_worker.rb'
|
39
40
|
|
40
41
|
def perform(payload)
|
41
42
|
puts payload['message']
|
data/docker/test_worker.rb
CHANGED
@@ -3,11 +3,10 @@ require 'kube_queue'
|
|
3
3
|
class TestWorker
|
4
4
|
include KubeQueue::Worker
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
command_as 'bundle', 'exec', 'kube_queue', 'TestWorker', '-r', './test_worker.rb'
|
6
|
+
job_name 'kube-queue-test'
|
7
|
+
image ENV['IMAGE_NAME']
|
8
|
+
container_name 'kube-queue-test'
|
9
|
+
command 'bundle', 'exec', 'kube_queue', 'TestWorker', '-r', './test_worker.rb'
|
11
10
|
|
12
11
|
def perform(payload)
|
13
12
|
puts payload['message']
|
data/lib/kube_queue/executor.rb
CHANGED
@@ -1,38 +1,52 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
|
3
3
|
module KubeQueue
|
4
|
-
class
|
4
|
+
class JobSpecification
|
5
5
|
extend Forwardable
|
6
6
|
|
7
|
-
|
8
|
-
attr_accessor :payload, :id
|
7
|
+
attr_accessor :payload, :id, :name
|
9
8
|
|
10
|
-
|
11
|
-
:job,
|
12
|
-
:command,
|
13
|
-
:job_name,
|
14
|
-
:name,
|
15
|
-
:container_name,
|
16
|
-
:image,
|
17
|
-
:command,
|
18
|
-
:template,
|
19
|
-
:restart_policy,
|
20
|
-
:backoff_limit
|
21
|
-
)
|
9
|
+
attr_writer :image, :job_name, :command, :container_name, :template, :backoff_limit, :restart_policy
|
22
10
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
11
|
+
def configure
|
12
|
+
yield self
|
13
|
+
self
|
26
14
|
end
|
27
15
|
|
28
16
|
def backoff_limit
|
29
|
-
@
|
17
|
+
@backoff_limit || 0
|
30
18
|
end
|
31
19
|
|
32
20
|
def restart_policy
|
33
|
-
@
|
21
|
+
@restart_policy || 'Never'
|
34
22
|
end
|
35
23
|
|
24
|
+
def command
|
25
|
+
@command || ['bundle', 'exec', 'kube_queue', name]
|
26
|
+
end
|
27
|
+
|
28
|
+
def image
|
29
|
+
@image || raise
|
30
|
+
end
|
31
|
+
|
32
|
+
def job_name
|
33
|
+
@job_name || raise
|
34
|
+
end
|
35
|
+
|
36
|
+
def container_name
|
37
|
+
@container_name || raise
|
38
|
+
end
|
39
|
+
|
40
|
+
def template
|
41
|
+
@template || File.read(File.expand_path('../../../template/job.yaml', __FILE__))
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_manifest
|
45
|
+
YAML.safe_load(ERB.new(template, nil, "%").result(binding))
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
36
50
|
def binding
|
37
51
|
super
|
38
52
|
end
|
data/lib/kube_queue/version.rb
CHANGED
data/lib/kube_queue/worker.rb
CHANGED
@@ -11,69 +11,56 @@ module KubeQueue
|
|
11
11
|
end
|
12
12
|
|
13
13
|
module ClassMethods
|
14
|
-
def
|
14
|
+
def job_name(name)
|
15
15
|
@job_name = name
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
@job_name || raise
|
20
|
-
end
|
21
|
-
|
22
|
-
def container_name
|
23
|
-
@container_name || raise
|
24
|
-
end
|
25
|
-
|
26
|
-
def container_name_as(container_name)
|
18
|
+
def container_name(container_name)
|
27
19
|
@container_name = container_name
|
28
20
|
end
|
29
21
|
|
30
|
-
def image
|
31
|
-
@image || raise
|
32
|
-
end
|
33
|
-
|
34
|
-
def image_as(image)
|
22
|
+
def image(image)
|
35
23
|
@image = image
|
36
24
|
end
|
37
25
|
|
38
|
-
def
|
26
|
+
def command(*command)
|
39
27
|
@command = command
|
40
28
|
end
|
41
29
|
|
42
|
-
def
|
43
|
-
@command || ['bundle', 'exec', 'kube_queue', name]
|
44
|
-
end
|
45
|
-
|
46
|
-
def template_as(template)
|
30
|
+
def template(template)
|
47
31
|
@template = template
|
48
32
|
end
|
49
33
|
|
50
|
-
def
|
51
|
-
@
|
52
|
-
end
|
53
|
-
|
54
|
-
def restart_policy
|
55
|
-
@restart_policy || 'Never'
|
34
|
+
def restart_policy(policy)
|
35
|
+
@restart_policy = policy
|
56
36
|
end
|
57
37
|
|
58
|
-
def backoff_limit
|
59
|
-
@backoff_limit
|
38
|
+
def backoff_limit(limit)
|
39
|
+
@backoff_limit = limit
|
60
40
|
end
|
61
41
|
|
62
|
-
def build_manifest(body
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
42
|
+
def build_manifest(body)
|
43
|
+
spec = JobSpecification.new.configure do |s|
|
44
|
+
s.id = SecureRandom.uuid
|
45
|
+
s.image = @image
|
46
|
+
s.name = name
|
47
|
+
s.command = @command
|
48
|
+
s.job_name = @job_name
|
49
|
+
s.container_name = @job_name
|
50
|
+
s.template = @template
|
51
|
+
s.backoff_limit = @backoff_limit
|
52
|
+
s.payload = JSON.generate(body, quirks_mode: true)
|
53
|
+
end
|
54
|
+
|
55
|
+
spec.to_manifest
|
69
56
|
end
|
70
57
|
|
71
58
|
def perform_sync(body)
|
72
59
|
new.perform(body)
|
73
60
|
end
|
74
61
|
|
75
|
-
def perform_async(body
|
76
|
-
KubeQueue.executor.perform_async(self, body
|
62
|
+
def perform_async(body)
|
63
|
+
KubeQueue.executor.perform_async(self, body)
|
77
64
|
end
|
78
65
|
end
|
79
66
|
end
|