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
ENTRY_LEVEL_TRIGGERS =
%w[
  entry.written entry.deleted entry.moved
  proposal.accepted proposal.rejected
].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.



39
40
41
42
# File 'lib/textus/store/jobs/planner.rb', line 39

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

Class Method Details

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



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

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



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/textus/store/jobs/planner.rb', line 44

def plan(trigger:, role:)
  type   = trigger["type"] || trigger[:type]
  target = 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, target: target)
  else
    plan_from_defaults(type, role, target: target)
  end
end