Class: Fractor::Workflow::Helpers::SimpleWorker

Inherits:
Fractor::Worker show all
Defined in:
lib/fractor/workflow/helpers.rb

Overview

Simple worker for basic transformations Just implement the transform method

Example:

class MyWorker < Fractor::Workflow::Helpers::SimpleWorker
input_type InputData
output_type OutputData

def transform(input)
  OutputData.new(result: input.value * 2)
end
end

Instance Method Summary collapse

Methods inherited from Fractor::Worker

effective_timeout, #initialize, input_type, output_type, timeout, #timeout

Constructor Details

This class inherits a constructor from Fractor::Worker

Instance Method Details

#process(work) ⇒ Object



20
21
22
23
24
# File 'lib/fractor/workflow/helpers.rb', line 20

def process(work)
  input = work.input
  output = transform(input)
  Fractor::WorkResult.new(result: output, work: work)
end

#transform(input) ⇒ Object

Override this method in subclasses

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/fractor/workflow/helpers.rb', line 27

def transform(input)
  raise NotImplementedError, "Subclasses must implement #transform"
end