Module: KubeQueue::Worker

Defined in:
lib/kube_queue/worker.rb,
lib/kube_queue/worker/dsl.rb

Defined Under Namespace

Modules: ClassMethods, DSL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argumentsObject (readonly) Also known as: payload

Returns the value of attribute arguments.



100
101
102
# File 'lib/kube_queue/worker.rb', line 100

def arguments
  @arguments
end

#job_idObject

Returns the value of attribute job_id.



99
100
101
# File 'lib/kube_queue/worker.rb', line 99

def job_id
  @job_id
end

#resourceObject

Returns the value of attribute resource.



100
101
102
# File 'lib/kube_queue/worker.rb', line 100

def resource
  @resource
end

#scheduled_atObject

Returns the value of attribute scheduled_at.



99
100
101
# File 'lib/kube_queue/worker.rb', line 99

def scheduled_at
  @scheduled_at
end

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
# File 'lib/kube_queue/worker.rb', line 6

def self.included(base)
  base.extend(ClassMethods)

  KubeQueue.register_worker(base.name, base)
end

Instance Method Details

#initialize(*arguments) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/kube_queue/worker.rb', line 104

def initialize(*arguments)
  # Compatibility for ActiveJob interface
  if method(__method__).super_method.arity.zero?
    super()
  else
    super
  end

  @arguments = arguments
  @job_id    = SecureRandom.uuid
  @loaded    = false
end

#job_specObject



95
96
97
# File 'lib/kube_queue/worker.rb', line 95

def job_spec
  self.class.job_spec
end

#loaded?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/kube_queue/worker.rb', line 136

def loaded?
  @loaded
end

#manifestObject



147
148
149
150
151
152
153
154
155
# File 'lib/kube_queue/worker.rb', line 147

def manifest
  if scheduled_at
    # Kubernetes CronJob does not support timezone
    cron = Time.at(scheduled_at).utc.strftime("%M %H %d %m %w")
    ManifestBuilder.new(self).build_cron_job(cron)
  else
    ManifestBuilder.new(self).build_job
  end
end

#performObject

Raises:

  • (NotImplementedError)


124
125
126
# File 'lib/kube_queue/worker.rb', line 124

def perform(*)
  raise NotImplementedError
end

#perform_nowObject



117
118
119
120
121
122
# File 'lib/kube_queue/worker.rb', line 117

def perform_now
  # Compatibility for ActiveJob interface
  return super if defined?(super)

  perform(*arguments)
end

#read_templateObject



91
92
93
# File 'lib/kube_queue/worker.rb', line 91

def read_template
  self.class.read_template
end

#reload!Object



140
141
142
143
144
145
# File 'lib/kube_queue/worker.rb', line 140

def reload!
  @loaded = false
  @resource = nil

  load_target
end

#serialized_payloadObject



157
158
159
160
161
162
163
# File 'lib/kube_queue/worker.rb', line 157

def serialized_payload
  if self.class.active_job?
    ActiveJob::Arguments.serialize(arguments)
  else
    arguments
  end
end

#statusObject



128
129
130
131
132
133
134
# File 'lib/kube_queue/worker.rb', line 128

def status
  return @resource.status if loaded?

  load_target

  @resource.status
end