Sha256: 1ccd60f740312bb5eb963fd7e1aee99a22beb92f90e451cb6cdd41d84ffea5d5

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

require 'fasten/support/state'

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

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

    def initialize(name:, shell: nil, ruby: nil, block: nil, request: nil, after: nil, weight: 1, worker_class: nil)
      self.name = name
      self.shell = shell
      self.ruby = ruby
      self.block = block
      self.request = request
      self.after = after
      self.weight = weight
      self.worker_class = worker_class
    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

7 entries across 7 versions & 1 rubygems

Version Path
fasten-0.14.2 lib/fasten/task.rb
fasten-0.14.0 lib/fasten/task.rb
fasten-0.12.8 lib/fasten/task.rb
fasten-0.12.6 lib/fasten/task.rb
fasten-0.12.4 lib/fasten/task.rb
fasten-0.12.2 lib/fasten/task.rb
fasten-0.12.0 lib/fasten/task.rb