Module: Bj::Table::Job::InstanceMethods

Defined in:
lib/bj/table.rb

Instance Method Summary collapse

Instance Method Details

#finishedObject Also known as: finished?



159
160
161
162
# File 'lib/bj/table.rb', line 159

def finished
  reload
  exit_status
end

#run!(options = {}) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/bj/table.rb', line 165

def run! options = {}
  job = self
  thread = nil
  
  command = job.command
  env = job.env ? YAML.load(job.env) : {}
  stdin = job.stdin || ''
  stdout = job.stdout || ''
  stderr = job.stderr || ''
  started_at = Time.now.utc

  job.state = "starting"
  job.save!

  thread = Util.start command, :cwd=>Bj.rails_root, :env=>env, :stdin=>stdin, :stdout=>stdout, :stderr=>stderr

  job.state = "running"
  job.runner = Bj.hostname
  job.pid = thread.pid
  job.started_at = started_at 

  Bj.transaction(options) do
    job.save!
    job.reload
  end

  exit_status = thread.value

  job.state = "finished"
  job.finished_at = Time.now.utc
  job.stdout = stdout
  job.stderr = stderr
  job.exit_status = exit_status

  Bj.transaction(options) do
    job.save!
    job.reload
  end

  job
end

#titleObject



155
156
157
# File 'lib/bj/table.rb', line 155

def title
  "job[#{ id }](#{ command })"
end