Module: KubeQueue::Worker::ClassMethods

Includes:
DSL
Defined in:
lib/kube_queue/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL

#active_deadline_seconds, #backoff_limit, #command, #concurrent_policy, #container_name, #cpu_limit, #cpu_request, #env, #env_from_config_map, #env_from_secret, #image, #job_spec, #labels, #memory_limit, #memory_request, #namespace, #restart_policy, #starting_deadline_seconds, #worker_name

Instance Attribute Details

#templateObject



17
18
19
# File 'lib/kube_queue/worker.rb', line 17

def template
  @template ||= File.expand_path('../../../template/job.yaml', __FILE__)
end

Instance Method Details

#active_job?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/kube_queue/worker.rb', line 21

def active_job?
  defined?(ActiveJob) && ancestors.include?(ActiveJob::Base)
end

#enqueue(*args) ⇒ Object Also known as: perform_async



51
52
53
54
55
# File 'lib/kube_queue/worker.rb', line 51

def enqueue(*args)
  job = new(*args)
  KubeQueue.executor.enqueue(job)
  job
end

#enqueue_at(*args) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/kube_queue/worker.rb', line 58

def enqueue_at(*args)
  args = args.dup
  timestamp = args.pop
  job = new(*args)
  job.scheduled_at = timestamp
  KubeQueue.executor.enqueue(job)
  job
end

#find(job_id) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kube_queue/worker.rb', line 36

def find(job_id)
  namespace = job_spec.namespace

  name = job_spec.job_name(job_id)

  res = KubeQueue.client.get_job(namespace, name)
  worker = KubeQueue.fetch_worker(res..annotations['kube-queue-job-class'])

  payload = deserialize_annotation_payload(res..annotations['kube-queue-job-payload'])

  job = worker.new(*payload)
  job.resource = res
  job
end

#listObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/kube_queue/worker.rb', line 25

def list
  namespace = job_spec.namespace

  KubeQueue.client.list_job(job_spec.job_class, namespace).map do |res|
    worker = KubeQueue.fetch_worker(res..annotations['kube-queue-job-class'])
    job = worker.new(*payload)
    job.resource = res
    job
  end
end

#manifestObject



71
72
73
# File 'lib/kube_queue/worker.rb', line 71

def manifest
  new.manifest
end

#read_templateObject



67
68
69
# File 'lib/kube_queue/worker.rb', line 67

def read_template
  File.read(template)
end