Class: Fractor::Work

Inherits:
Object
  • Object
show all
Defined in:
lib/fractor/work.rb

Overview

Base class for defining work items. Contains the input data for a worker.

Direct Known Subclasses

PriorityWork

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, timeout: nil) ⇒ Work

Initializes a new work item.

Parameters:

  • input (Object)

    The input data for the worker

  • timeout (Numeric, nil) (defaults to: nil)

    Optional per-work-item timeout in seconds. If nil, uses the worker's default timeout.



14
15
16
17
# File 'lib/fractor/work.rb', line 14

def initialize(input, timeout: nil)
  @input = input
  @timeout = timeout
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



7
8
9
# File 'lib/fractor/work.rb', line 7

def input
  @input
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



7
8
9
# File 'lib/fractor/work.rb', line 7

def timeout
  @timeout
end

Instance Method Details

#inspectString

Provide detailed inspection of work item for debugging

Returns:

  • (String)

    Detailed inspection string



25
26
27
28
29
30
31
32
33
34
# File 'lib/fractor/work.rb', line 25

def inspect
  details = [
    "#<#{self.class.name}",
    "0x#{(object_id << 1).to_s(16)}",
    "@input=#{@input.inspect}",
    "@type=#{input.class.name}",
  ]
  details << "@timeout=#{@timeout.inspect}" if @timeout
  details.join(" ")
end

#to_sObject



19
20
21
# File 'lib/fractor/work.rb', line 19

def to_s
  "Work: #{@input}"
end