Sha256: 2fdc09922285e3a0009ed94a069fdae86977de866d190294503920546bc6bc34

Contents?: true

Size: 1004 Bytes

Versions: 3

Compression:

Stored size: 1004 Bytes

Contents

require 'fasten/support/state'

module Fasten
  class Task
    include Fasten::Support::State

    attr_accessor :name, :after, :shell, :ruby
    attr_accessor :dependants, :depends, :request, :response, :worker, :run_score, :block

    def initialize(name: nil, shell: nil, ruby: nil, block: nil, request: nil, after: nil)
      self.name = name
      self.shell = shell
      self.ruby = ruby
      self.block = block
      self.request = request
      self.after = after
    end

    def marshal_dump
      [@name, @state, @ini, @fin, @dif, @request, @response, @shell, @ruby, @block&.object_id, @error]
    end

    def marshal_load(data)
      @name, @state, @ini, @fin, @dif, @request, @response, @shell, @ruby, block_id, @error = data
      @block = ObjectSpace._id2ref block_id if block_id

      raise "Sorry, unable to get block for task #{self}, please try using threads" if block_id && !@block.is_a?(Proc)
    end

    def kind
      'task'
    end

    def to_s
      name
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fasten-0.7.2 lib/fasten/task.rb
fasten-0.7.0 lib/fasten/task.rb
fasten-0.6.0 lib/fasten/task.rb