Class: Fasten::Task

Inherits:
Object
  • Object
show all
Includes:
Support::State
Defined in:
lib/fasten/task.rb

Instance Attribute Summary collapse

Attributes included from Support::State

#dif, #error, #fin, #ini, #runner, #state

Instance Method Summary collapse

Methods included from Support::State

#deps, #deps_str, #deps_str_runner, #deps_str_task, #idle?, #last_avg, #last_err, #last_stat, #paused?, #pausing?, #quitting?, #running?

Constructor Details

#initialize(name:, shell: nil, ruby: nil, block: nil, request: nil, after: nil, weight: 1, worker_class: nil) ⇒ Task

Returns a new instance of Task.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fasten/task.rb', line 9

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

  # ObjectSpace.define_finalizer(self) do
  #   puts "I am dying! pid: #{Process.pid} thread: #{Thread.current} TASK #{@name}"
  # end

  block&.object_id
  # block && begin

  #   # puts "block_id: #{block.object_id} for task #{@name}"
  # end

  # block && ObjectSpace.define_finalizer(block) do
  #   puts "I am dying! pid: #{Process.pid} thread: #{Thread.current} TASK #{@name} BLOCK"
  # end
end

Instance Attribute Details

#afterObject

Returns the value of attribute after.



7
8
9
# File 'lib/fasten/task.rb', line 7

def after
  @after
end

#blockObject

Returns the value of attribute block.



7
8
9
# File 'lib/fasten/task.rb', line 7

def block
  @block
end

#dependantsObject

Returns the value of attribute dependants.



7
8
9
# File 'lib/fasten/task.rb', line 7

def dependants
  @dependants
end

#dependsObject

Returns the value of attribute depends.



7
8
9
# File 'lib/fasten/task.rb', line 7

def depends
  @depends
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/fasten/task.rb', line 7

def name
  @name
end

#requestObject

Returns the value of attribute request.



7
8
9
# File 'lib/fasten/task.rb', line 7

def request
  @request
end

#responseObject

Returns the value of attribute response.



7
8
9
# File 'lib/fasten/task.rb', line 7

def response
  @response
end

#rubyObject

Returns the value of attribute ruby.



7
8
9
# File 'lib/fasten/task.rb', line 7

def ruby
  @ruby
end

#run_scoreObject

Returns the value of attribute run_score.



7
8
9
# File 'lib/fasten/task.rb', line 7

def run_score
  @run_score
end

#shellObject

Returns the value of attribute shell.



7
8
9
# File 'lib/fasten/task.rb', line 7

def shell
  @shell
end

#weightObject

Returns the value of attribute weight.



7
8
9
# File 'lib/fasten/task.rb', line 7

def weight
  @weight
end

#workerObject

Returns the value of attribute worker.



7
8
9
# File 'lib/fasten/task.rb', line 7

def worker
  @worker
end

#worker_classObject

Returns the value of attribute worker_class.



7
8
9
# File 'lib/fasten/task.rb', line 7

def worker_class
  @worker_class
end

Instance Method Details

#kindObject



49
50
51
# File 'lib/fasten/task.rb', line 49

def kind
  'task'
end

#marshal_dumpObject



34
35
36
# File 'lib/fasten/task.rb', line 34

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

#marshal_load(data) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/fasten/task.rb', line 38

def marshal_load(data)
  @name, @state, @ini, @fin, @dif, @request, @response, @shell, @ruby, block_id, @error = data
  @block = begin
    ObjectSpace._id2ref block_id.to_i if block_id
  rescue StandardError
    # pass
  end

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

#to_sObject



53
54
55
# File 'lib/fasten/task.rb', line 53

def to_s
  name
end