Class: DRMAA::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_core/job/adapters/drmaa.rb

Overview

DRMAA Session

Direct Known Subclasses

SessionSingleton

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contact = "") ⇒ Session

initialize DRMAA session



721
722
723
724
725
# File 'lib/ood_core/job/adapters/drmaa.rb', line 721

def initialize(contact = "")
    DRMAA.init(contact)
    ObjectSpace.define_finalizer(self, self.method(:finalize).to_proc)
    @retry = 0
end

Instance Attribute Details

#retryObject

Returns the value of attribute retry.



718
719
720
# File 'lib/ood_core/job/adapters/drmaa.rb', line 718

def retry
  @retry
end

Instance Method Details

#finalize(id) ⇒ Object

close DRMAA session



728
729
730
731
# File 'lib/ood_core/job/adapters/drmaa.rb', line 728

def finalize(id)
    # STDERR.puts "... exiting DRMAA"
    DRMAA.exit
end

#hold(job = ALL_JOBS) ⇒ Object

put specified job or all session jobs in hold state



828
829
830
# File 'lib/ood_core/job/adapters/drmaa.rb', line 828

def hold(job = ALL_JOBS)
    DRMAA.control(job, DRMAA::ACTION_HOLD)
end

#job_ps(job) ⇒ Object

get job state



843
844
845
# File 'lib/ood_core/job/adapters/drmaa.rb', line 843

def job_ps(job)
    DRMAA.job_ps(job)
end

#release(job = ALL_JOBS) ⇒ Object

release hold state for specified job or all session jobs



833
834
835
# File 'lib/ood_core/job/adapters/drmaa.rb', line 833

def release(job = ALL_JOBS)
    DRMAA.control(job, DRMAA::ACTION_RELEASE)
end

#resume(job = ALL_JOBS) ⇒ Object

resume specified job or all session jobs



823
824
825
# File 'lib/ood_core/job/adapters/drmaa.rb', line 823

def resume(job = ALL_JOBS)
    DRMAA.control(job, DRMAA::ACTION_RESUME)
end

#retry_untilObject

non-zero retry interval causes DRMAA::DRMAATryLater be handled transparently



734
735
736
737
738
739
740
741
742
743
744
745
746
747
# File 'lib/ood_core/job/adapters/drmaa.rb', line 734

def retry_until
    if @retry == 0
        job = yield
    else
        begin
            job = yield
        rescue DRMAA::DRMAATryLater
            STDERR.puts "... sleeping"
            sleep @retry
            retry
        end
    end
    return job
end

#run(t) ⇒ Object

submits job described by JobTemplate ‘t’ and returns job id as string



750
751
752
# File 'lib/ood_core/job/adapters/drmaa.rb', line 750

def run(t)
    retry_until { DRMAA.run_job(t.ptr) }
end

#run_bulk(t, first, last, incr = 1) ⇒ Object

submits bulk job described by JobTemplate ‘t’ and returns an array of job id strings



756
757
758
# File 'lib/ood_core/job/adapters/drmaa.rb', line 756

def run_bulk(t, first, last, incr = 1)
    retry_until { DRMAA.run_bulk_jobs(t.ptr, first, last, incr) }
end

#suspend(job = ALL_JOBS) ⇒ Object

suspend specified job or all session jobs



818
819
820
# File 'lib/ood_core/job/adapters/drmaa.rb', line 818

def suspend(job = ALL_JOBS)
    DRMAA.control(job, DRMAA::ACTION_SUSPEND)
end

#sync(jobs, timeout = -1)) ⇒ Object

synchronize with specified session jobs returns false in case of a timeout



813
814
815
# File 'lib/ood_core/job/adapters/drmaa.rb', line 813

def sync(jobs, timeout = -1)
    DRMAA.synchronize(jobs, timeout, false)
end

#sync!(jobs, timeout = -1)) ⇒ Object

synchronize with specified session jobs and dispose any job finish information returns false in case of a timeout



807
808
809
# File 'lib/ood_core/job/adapters/drmaa.rb', line 807

def sync!(jobs, timeout = -1)
    DRMAA.synchronize(jobs, timeout, true)
end

#sync_all(timeout = -1,, dispose = false) ⇒ Object

synchronize with all session jobs returns false in case of a timeout



801
802
803
# File 'lib/ood_core/job/adapters/drmaa.rb', line 801

def sync_all(timeout = -1, dispose = false)
    DRMAA.synchronize([ ALL_JOBS ], timeout, dispose)
end

#sync_all!(timeout = -1)) ⇒ Object

synchronize with all session jobs and dispose any job finish information returns false in case of a timeout



795
796
797
# File 'lib/ood_core/job/adapters/drmaa.rb', line 795

def sync_all!(timeout = -1)
    DRMAA.synchronize([ ALL_JOBS ], timeout, true)
end

#terminate(job = ALL_JOBS) ⇒ Object

terminate specified job or all session jobs



838
839
840
# File 'lib/ood_core/job/adapters/drmaa.rb', line 838

def terminate(job = ALL_JOBS)
    DRMAA.control(job, DRMAA::ACTION_TERMINATE)
end

#wait(job, timeout = -1)) ⇒ Object

wait for job and return JobInfo



766
767
768
# File 'lib/ood_core/job/adapters/drmaa.rb', line 766

def wait(job, timeout = -1)
    DRMAA.wait(job, timeout)
end

#wait_any(timeout = -1)) ⇒ Object

wait for any job of this session and return JobInfo



761
762
763
# File 'lib/ood_core/job/adapters/drmaa.rb', line 761

def wait_any(timeout = -1)
    DRMAA.wait(ANY_JOB, timeout)
end

#wait_each(timeout = -1)) ⇒ Object

run block with JobInfo to finish for each waited session job or return JobInfo array if no block was passed



772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
# File 'lib/ood_core/job/adapters/drmaa.rb', line 772

def wait_each(timeout = -1)
    if ! block_given?
        ary = Array.new
    end
    while true
        begin
            info = DRMAA.wait(ANY_JOB, timeout)
        rescue DRMAAInvalidJobError
            break
        end
        if block_given?
            yield info
        else
            ary << info
        end
    end
    if ! block_given?
        return ary
    end
end