Class: Textus::Store::Jobs::Planner

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

Constant Summary collapse

ACTIONS_BY_TRIGGER =
{
  "convergence" => %w[materialize sweep index],
  "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
GLOBAL_ACTIONS =
{
  "index" => {},
  "sweep" => { "scope" => {} },
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container:) ⇒ Planner

Returns a new instance of Planner.



34
35
36
37
# File 'lib/textus/store/jobs/planner.rb', line 34

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

Class Method Details

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



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

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



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/textus/store/jobs/planner.rb', line 39

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