Class: Textus::Jobs::Planner

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/jobs/planner.rb

Constant Summary collapse

ACTIONS_BY_TRIGGER =
{
  "convergence" => %w[materialize sweep],
  "entry.written" => %w[materialize],
  "entry.deleted" => %w[materialize],
  "entry.moved" => %w[materialize],
  "proposal.accepted" => %w[materialize],
  "proposal.rejected" => %w[materialize],
}.freeze
SCOPE_RESOLVERS =
{
  "materialize" => :producible_keys,
  "sweep" => :lane_keys,
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container:) ⇒ Planner

Returns a new instance of Planner.



28
29
30
31
# File 'lib/textus/jobs/planner.rb', line 28

def initialize(container:)
  @container = container
  @manifest  = container.manifest
end

Class Method Details

.seed(container:, queue:, role:) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/textus/jobs/planner.rb', line 20

def self.seed(container:, queue:, role:)
  jobs = new(container: container).plan(
    trigger: { "type" => "convergence" },
    role: role,
  )
  jobs.each { |j| queue.enqueue(j) }
end

Instance Method Details

#plan(trigger:, role:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/textus/jobs/planner.rb', line 33

def plan(trigger:, role:)
  type = trigger["type"] || trigger[:type]
  trigger["target"] || trigger[:target]
  return [] if type.nil?

  blocks_with_react = @manifest.rules.blocks.select(&:react)
  if blocks_with_react.any?
    plan_from_rules(blocks_with_react, type, role)
  else
    plan_from_defaults(type, role)
  end
end