Class: Textus::Background::Planner::Plan

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

Constant Summary collapse

ACTIONS_BY_TRIGGER =
{
  "convergence" => %w[materialize refresh 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,
  "refresh" => :stale_intake_keys,
  "sweep" => :lane_keys,
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container:) ⇒ Plan

Returns a new instance of Plan.



30
31
32
33
# File 'lib/textus/background/planner/plan.rb', line 30

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

Class Method Details

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



22
23
24
25
26
27
28
# File 'lib/textus/background/planner/plan.rb', line 22

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



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/textus/background/planner/plan.rb', line 35

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