Sha256: 4f3c6acd93ed978ef3736024fec97f83d538da4aeb2e1bc294d623a08470943b

Contents?: true

Size: 1.1 KB

Versions: 70

Compression:

Stored size: 1.1 KB

Contents

module Redcar
  class Task
    include java.util.concurrent.Callable
 
    attr_accessor :_queue, :enqueue_time, :start_time, :completed_time, :description
    attr_reader   :error

    def pending?
      @enqueue_time and !@start_time
    end
    
    def in_process?
      @start_time and !@completed_time
    end
    
    def completed?
      @completed_time
    end
    
    def cancel
      @cancelled = true
      _queue.send(:completed_task, self)
    end
    
    def cancelled?
      @cancelled
    end
    
    def call
      begin
        unless cancelled?
          _queue.send(:started_task, self)
          @start_time = Time.now
          result = execute
          @completed_time = Time.now
          _queue.send(:completed_task, self)
          result
        end
      rescue Object => e
        @error = e
        @completed_time = Time.now
        _queue.send(:completed_task, self)
        nil
      end
    end
    
    def execute
      raise "implement me!"
    end
    
    def inspect
      "<Task>"
    end
    
    private
    
    def _set_cancelled
      @cancelled = true
    end
  end
end

Version data entries

70 entries across 70 versions & 2 rubygems

Version Path
redcar-dev-0.12.16dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.15dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.14dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.13dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.12dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.11dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.10dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.9dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.8dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.7dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.6dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.4dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.3dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.1dev-java plugins/core/lib/core/task.rb
redcar-dev-0.12.0dev-java plugins/core/lib/core/task.rb
redcar-0.11 plugins/core/lib/core/task.rb
redcar-0.11.0dev plugins/core/lib/core/task.rb
redcar-0.10 plugins/core/lib/core/task.rb
redcar-0.9.2 plugins/core/lib/core/task.rb
redcar-0.9.1 plugins/core/lib/core/task.rb