Skip to content

Instantly share code, notes, and snippets.

@meskallito
Created October 8, 2013 23:01
Show Gist options
  • Select an option

  • Save meskallito/6893301 to your computer and use it in GitHub Desktop.

Select an option

Save meskallito/6893301 to your computer and use it in GitHub Desktop.
module PiProcessing
class TaskInitializer
attr_accessor :result
def initialize(flow, shared_context, tokens)
@flow = flow
@shared_context = shared_context
@dependency_manager = DependencyManager.new(tokens)
end
def create(assignment: nil)
shared_context = @shared_context
dependencies = @dependency_manager
if assignment
root = dependencies.by_name(assignment.reference).first
end
result = @result = PiProcessing::ProcessingResult.new({}, dependencies: dependencies)
@flow.task(declares: [ root ]) do
tokens = assignment && dependencies.get(assignment.calculation_dependencies) || dependencies.all
dep_vars = [*import(*tokens)]
result.save(tokens.zip(dep_vars.map(&:value)))
if assignment
variable = import root
variable.value = assignment.calculate result.merge(shared_context)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment