Class: Eco::API::UseCases::GraphQL::Samples::Pages::Template::Deploy::Loop

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/api/usecases/graphql/samples/pages/template/deploy/loop.rb

Overview

Deploy → verify → monitor orchestration (Phase 5).

Ties the four offline-safe pieces into one pass:

  1. APPLY — hand a gem Diff::Deploy plan to the Applier (dry-run by DEFAULT; live only behind an explicit commit: true + executor).
  2. DRIFT — re-read the target and run a pre/post self-version diff, then compare the applied delta to the intended delta (DriftReport). Reports drift honestly.
  3. VERIFY — run the post-deploy template doc through a Verifier (ecoportal-qa when present, else the null verifier).
  4. MONITOR — optional sync-readiness scan of a register subset against the post-deploy template.

Everything is OFFLINE against fixtures. The two seams that would touch a live API — applying the batch and re-reading the target — are injected as callables, so specs (and dry-runs) drive them with fixtures and a RecordingExecutor:

loop = Deploy::Loop.new( plan: gem_deploy_plan, intended: source_version_diff, # the diff the plan was built from pre_doc: target_before_doc, # the target template BEFORE apply reread: -> { recording_executor.doc } # how to fetch the target AFTER apply (post-deploy doc) ) result = loop.run(commit: false, executor: recording_executor, entries: register_entries)

result.applied # => Applier::Outcome result.drift # => DriftReport (nil if pre_doc/reread not supplied) result.verdict # => Verifier::Verdict result.sync_readiness # => SyncReadiness (nil if no entries) result.ok? # => apply not blocked && drift match && verify pass result.report # => aggregate human summary

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(plan:, intended: nil, pre_doc: nil, reread: nil, target: nil, verifier: nil, diff_builder: nil) ⇒ Loop

Returns a new instance of Loop.

Parameters:

  • plan (Ecoportal::API::GraphQL::Diff::Deploy)

    the gem deploy plan.

  • intended (#changes, nil) (defaults to: nil)

    the source diff the plan was built from (for drift check).

  • pre_doc (Hash, nil) (defaults to: nil)

    the target template doc BEFORE apply (for drift check).

  • reread (#call, nil) (defaults to: nil)

    returns the target template doc AFTER apply (for drift + verify).

  • target (#id, nil) (defaults to: nil)

    the target model, forwarded to the Applier for a live apply.

  • verifier (Verifier, nil) (defaults to: nil)

    injected verifier; defaults to Verifier.default.

  • diff_builder (#call, nil) (defaults to: nil)

    diff_builder.call(pre_doc, post_doc) returns the applied self-version diff (must expose #changes). Defaults to the gem's Diff::VersionDiff — which lives in the (currently unreleased) gem Diff module, so it is resolved LAZILY at drift time, never at load. Injectable so offline callers/specs can supply their own diff builder.



95
96
97
98
99
100
101
102
103
104
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/loop.rb', line 95

def initialize(plan:, intended: nil, pre_doc: nil, reread: nil, target: nil, verifier: nil,
               diff_builder: nil)
  @plan         = plan
  @intended     = intended
  @pre_doc      = pre_doc
  @reread       = reread
  @target       = target
  @verifier     = verifier || Verifier.default
  @diff_builder = diff_builder
end

Instance Method Details

#run(commit: false, executor: nil, allow_partial: false, entries: nil) ⇒ Result

Run the full pass.

Parameters:

  • commit (Boolean) (defaults to: false)

    false = dry-run (default). true = live apply.

  • executor (#execute_workflow_commands, nil) (defaults to: nil)

    the mutation facade (live) or a RecordingExecutor (offline). Required for both commit AND for an offline drift check (the RecordingExecutor replays the batch to produce the post-deploy doc).

  • allow_partial (Boolean) (defaults to: false)

    forwarded to the Applier / gem plan.

  • entries (Array, nil) (defaults to: nil)

    register subset for the sync-readiness monitor (optional).

Returns:



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/loop.rb', line 115

def run(commit: false, executor: nil, allow_partial: false, entries: nil)
  applied = Applier.new(@plan, target: @target).apply(
    commit: commit, executor: executor, allow_partial: allow_partial
  )

  post_doc = applied.skipped_reason.nil? ? reread_post_doc : nil
  drift    = build_drift(post_doc)
  verdict  = post_doc ? @verifier.verify(post_doc) : nil
  monitor  = build_monitor(post_doc, entries)

  Result.new(applied: applied, drift: drift, verdict: verdict, sync_readiness: monitor)
end