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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc54ffb5ae4c0848fcb06fc0c798acb4ad06c573
4
- data.tar.gz: f0da267787777b8874bd9549640ffc3ab4458bed
3
+ metadata.gz: 1511d8cfdd1b8fb8375d4162e389750b4372bc19
4
+ data.tar.gz: 963ace432f1420c863d94d491e81611fa7141279
5
5
  SHA512:
6
- metadata.gz: b2e4166dc211c96a5b71364492554b544bfd3bc123d34f0a314930a5cf9b2cc735246f1a9e76df1a51e51b31ab5ce1d49bde4f77e86993c3b3acbd1f8b01c528
7
- data.tar.gz: c0543d7d6ec5829cffb2c37de5cbd4db62947ee80b7637f800c018f6f0c98464c85d31d434be519cd45ce52cc1e72a105d94c0dd86426f0b53f58b0d4f4ce4c0
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 'kube-queue'
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 kube-queue
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
- job_name_as 'kube-queue-test'
35
- image_as "my-registry/my-image"
36
- container_name_as 'kube-queue-test'
35
+ job_name 'kube-queue-test'
36
+ image "my-registry/my-image"
37
+ container_name 'kube-queue-test'
37
38
 
38
- command_as 'bundle', 'exec', 'kube_queue', 'TestWorker', '-r', './test_worker.rb'
39
+ command 'bundle', 'exec', 'kube_queue', 'TestWorker', '-r', './test_worker.rb'
39
40
 
40
41
  def perform(payload)
41
42
  puts payload['message']
@@ -3,11 +3,10 @@ require 'kube_queue'
3
3
  class TestWorker
4
4
  include KubeQueue::Worker
5
5
 
6
- job_name_as 'kube-queue-test'
7
- image_as ENV['IMAGE_NAME']
8
- container_name_as 'kube-queue-test'
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']
@@ -3,8 +3,8 @@ require 'json'
3
3
 
4
4
  module KubeQueue
5
5
  class Executor
6
- def perform_async(job, body, options)
7
- manifest = job.build_manifest(body, options)
6
+ def perform_async(job, body)
7
+ manifest = job.build_manifest(body)
8
8
  KubeQueue.client.create_job(manifest)
9
9
  end
10
10
  end
@@ -1,38 +1,52 @@
1
1
  require 'forwardable'
2
2
 
3
3
  module KubeQueue
4
- class JobConfiguration
4
+ class JobSpecification
5
5
  extend Forwardable
6
6
 
7
- attr_reader :job
8
- attr_accessor :payload, :id
7
+ attr_accessor :payload, :id, :name
9
8
 
10
- def_delegators(
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 initialize(job, options)
24
- @job = job
25
- @options = options
11
+ def configure
12
+ yield self
13
+ self
26
14
  end
27
15
 
28
16
  def backoff_limit
29
- @options[:backoff_limit] || job.backoff_limit
17
+ @backoff_limit || 0
30
18
  end
31
19
 
32
20
  def restart_policy
33
- @options[:restart_policy] || job.restart_policy
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
@@ -1,3 +1,3 @@
1
1
  module KubeQueue
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
@@ -11,69 +11,56 @@ module KubeQueue
11
11
  end
12
12
 
13
13
  module ClassMethods
14
- def job_name_as(name)
14
+ def job_name(name)
15
15
  @job_name = name
16
16
  end
17
17
 
18
- def job_name
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 command_as(*command)
26
+ def command(*command)
39
27
  @command = command
40
28
  end
41
29
 
42
- def command
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 template
51
- @template || File.read(File.expand_path('../../../template/job.yaml', __FILE__))
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 || 0
38
+ def backoff_limit(limit)
39
+ @backoff_limit = limit
60
40
  end
61
41
 
62
- def build_manifest(body, options)
63
- config = JobConfiguration.new(self, options)
64
-
65
- config.id = SecureRandom.uuid
66
- config.payload = JSON.generate(body, quirks_mode: true)
67
-
68
- YAML.safe_load(ERB.new(template, nil, "%").result(config.binding))
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, options = {})
76
- KubeQueue.executor.perform_async(self, body, options)
62
+ def perform_async(body)
63
+ KubeQueue.executor.perform_async(self, body)
77
64
  end
78
65
  end
79
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kube_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yuemori