405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
|
# File 'lib/simplews/jobs.rb', line 405
def initialize(name = nil, description = nil, host = nil, port = nil, workdir = nil, *args)
super(name, description, host, port, *args)
@workdir = workdir || "/tmp/#{ name }"
Scheduler.workdir = @workdir
@results = {}
INHERITED_TASKS.each{|task,info|
@@last_description = info[:description]
@@last_param_description = info[:param_description]
task(task, info[:params], info[:types], info[:results], &info[:block])
}
desc "Job management: Return the names of the jobs in the queue"
param_desc :return => "Array of job names"
serve :queue, [], :return => :array do
Scheduler.queue.collect{|info| info[:name]}
end
desc "Job management: Check the status of a job"
param_desc :job => "Job identifier", :return => "Status code. Special status codes are: 'queue', 'done', 'error', and 'aborted'"
serve :status, ['job'], :job => :string, :return => :string do |job|
Scheduler.job_info(job)[:status].to_s
end
desc "Job management: Return an array with the messages issued by the job"
param_desc :job => "Job identifier", :return => "Array with message strings"
serve :messages, ['job'], :job => :string, :return => :array do |job|
Scheduler.job_info(job)[:messages]
end
desc "Job management: Return a YAML string containing arbitrary information set up by the job"
param_desc :job => "Job identifier", :return => "Hash with arbitrary values in YAML format"
serve :info, ['job'], :job => :string, :return => :string do |job|
Scheduler.job_info(job)[:info].to_yaml
end
desc "Job management: Abort the job"
param_desc :job => "Job identifier"
serve :abort, %w(job), :job => :string, :return => false do |job|
Scheduler.abort(job)
end
desc "Job management: Check if the job is done. Could have finished successfully, with error, or have been aborted"
param_desc :job => "Job identifier", :return => "True if the job has status 'done', 'error' or 'aborted'"
serve :done, %w(job), :job => :string, :return => :boolean do |job|
[:done, :error, :aborted].include? Scheduler.job_info(job)[:status].to_sym
end
desc "Job management: Check if the job has finished with error. The last message is the error message"
param_desc :job => "Job identifier", :return => "True if the job has status 'error'"
serve :error, %w(job), :job => :string, :return => :boolean do |job|
Scheduler.job_info(job)[:status] == :error
end
desc "Job management: Check if the job has been aborted"
param_desc :job => "Job identifier", :return => "True if the job has status 'aborted'"
serve :aborted, %w(job), :job => :string, :return => :boolean do |job|
Scheduler.job_info(job)[:status] == :aborted
end
desc "Job management: Return an array with result identifiers to be used with the 'result' operation. The content of the results depends
on the task"
param_desc :job => "Job identifier", :return => "Array of result identifiers"
serve :results, %w(job), :return => :array do |job|
results = Scheduler.job_results(job)
@results.merge! Hash[*results.flatten]
results.collect{|p| p[0]}
end
desc "Job management: Return the content of the result specified by the result identifier. These identifiers are retrieve using the 'results' operation. Results are Base64 encoded to allow binary data"
param_desc :result => "Result identifier", :return => "Content of the result file, in Base64 encoding for compatibility"
serve :result, %w(result), :return => :binary do |result|
path = @results[result]
raise ResultNotFound if path.nil? || ! File.exist?(path)
Base64.encode64 File.open(path).read
end
end
|