Class: AgentC::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_c/processor.rb

Defined Under Namespace

Classes: Handler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context:, handlers:) ⇒ Processor

Returns a new instance of Processor.



15
16
17
18
# File 'lib/agent_c/processor.rb', line 15

def initialize(context:, handlers:)
  @context = context
  @handlers = handlers.transform_keys(&:to_s)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



14
15
16
# File 'lib/agent_c/processor.rb', line 14

def context
  @context
end

#handlersObject (readonly)

Returns the value of attribute handlers.



14
15
16
# File 'lib/agent_c/processor.rb', line 14

def handlers
  @handlers
end

Instance Method Details

#abort!Object



36
37
38
# File 'lib/agent_c/processor.rb', line 36

def abort!
  @abort = true
end

#abort?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/agent_c/processor.rb', line 40

def abort?
  @abort
end

#add_task(record, handler) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
# File 'lib/agent_c/processor.rb', line 20

def add_task(record, handler)
  raise ArgumentError.new("invalid handler") unless handlers.include?(handler.to_s)

  store.task.find_or_create_by!(record:, handler:)
end

#callObject



26
27
28
29
30
31
32
33
34
# File 'lib/agent_c/processor.rb', line 26

def call(&)
  raise "must provide at least one workspace" if workspace_count == 0

  if workspace_count == 1
    call_synchronous(context.workspaces.first, &)
  else
    call_asynchronous(&)
  end
end