Class: SimpleWS::Jobs
- Defined in:
- lib/simplews/jobs.rb
Defined Under Namespace
Modules: Scheduler Classes: Aborted, JobNotFound, ResultNotFound
Constant Summary collapse
- SLEEP_TIMES =
{ :job_info => 1, :monitor => 2, }
- @@tasks =
{}
Constants inherited from SimpleWS
Class Method Summary collapse
- .configure(name, value) ⇒ Object
- .helper(name, &block) ⇒ Object
- .task(name, params = [], types = {}, results = [], &block) ⇒ Object
Instance Method Summary collapse
- #abort_jobs ⇒ Object
- #configure(name, value) ⇒ Object
- #helper(name, &block) ⇒ Object
-
#initialize(name, description, host, port, workdir = nil, *args) ⇒ Jobs
constructor
A new instance of Jobs.
- #old_shutdown ⇒ Object
- #old_start ⇒ Object
- #shutdown(*args) ⇒ Object
- #start(*args) ⇒ Object
- #task(name, params = [], types = {}, results = [], &block) ⇒ Object
- #workdir ⇒ Object
Methods inherited from SimpleWS
get_driver, get_wsdl, #serve, serve, #wsdl
Constructor Details
#initialize(name, description, host, port, workdir = nil, *args) ⇒ Jobs
Returns a new instance of Jobs.
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 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 |
# File 'lib/simplews/jobs.rb', line 385 def initialize(name, description, host, port, workdir = nil, *args) super(name, description, host, port, *args) @workdir = workdir || "/tmp/#{ name }" Scheduler.workdir = @workdir @results = {} @@tasks.each{|task, values| serve task.to_s, values[:params] + ['suggested_name'], values[:types].merge(:suggested_name => 'string', :return => :string) do |*args| Scheduler.run task, *args end } serve :queue, [], :return => :array do Scheduler.queue.collect{|info| info[:name]} end serve :status, ['job'], :job => :string, :return => :string do |job| Scheduler.job_info(job)[:status].to_s end serve :messages, ['job'], :job => :string, :return => :array do |job| Scheduler.job_info(job)[:messages] end serve :info, ['job'], :job => :string, :return => :string do |job| Scheduler.job_info(job)[:info].to_yaml end serve :abort, %w(job), :job => :string do |job| Scheduler.abort(job) end serve :done, %w(job), :job => :string, :return => :boolean do |job| [:done, :error, :aborted].include? Scheduler.job_info(job)[:status].to_sym end serve :error, %w(job), :job => :string, :return => :boolean do |job| Scheduler.job_info(job)[:status] == :error end serve :aborted, %w(job), :job => :string, :return => :boolean do |job| Scheduler.job_info(job)[:status] == :aborted end serve :results, %w(job), :return => :array do |job| results = Scheduler.job_results(job) @results.merge! Hash[*results.flatten] results.collect{|p| p[0]} end serve :result, %w(result), :return => :binary do |result| path = @results[result] raise ResultNotFound unless File.exist? path File.open(path).read end end |
Class Method Details
.configure(name, value) ⇒ Object
355 356 357 |
# File 'lib/simplews/jobs.rb', line 355 def self.configure(name, value) Scheduler.configure(name, value) end |
Instance Method Details
#abort_jobs ⇒ Object
376 377 378 |
# File 'lib/simplews/jobs.rb', line 376 def abort_jobs Scheduler.abort_jobs end |
#configure(name, value) ⇒ Object
359 360 361 |
# File 'lib/simplews/jobs.rb', line 359 def configure(name, value) self.class.configure(name, value) end |
#helper(name, &block) ⇒ Object
351 352 353 |
# File 'lib/simplews/jobs.rb', line 351 def helper(name,&block) Scheduler.helper name, block end |
#old_shutdown ⇒ Object
449 |
# File 'lib/simplews/jobs.rb', line 449 alias_method :old_shutdown, :shutdown |
#old_start ⇒ Object
443 |
# File 'lib/simplews/jobs.rb', line 443 alias_method :old_start, :start |
#shutdown(*args) ⇒ Object
450 451 452 453 |
# File 'lib/simplews/jobs.rb', line 450 def shutdown(*args) Scheduler.abort_jobs old_shutdown(*args) end |
#start(*args) ⇒ Object
444 445 446 447 |
# File 'lib/simplews/jobs.rb', line 444 def start(*args) Scheduler.job_monitor old_start(*args) end |
#task(name, params = [], types = {}, results = [], &block) ⇒ Object
363 364 365 366 367 368 |
# File 'lib/simplews/jobs.rb', line 363 def task(name, params=[], types={}, results = [], &block) Scheduler.task name, results, block serve name.to_s, params + ['suggested_name'], types.merge(:suggested_name => 'string', :return => :string) do |*args| Scheduler.run name, *args end end |
#workdir ⇒ Object
381 382 383 |
# File 'lib/simplews/jobs.rb', line 381 def workdir @workdir end |