Decompose publish_draft_campaign into named steps - #27
Merged
Conversation
The publish flow was a single ~159-line function nesting budget selection, group creation, org-URN resolution, per-line-item campaign creation, per-ad post/creative creation, and rollback-on-failure. Extract each concern into a focused helper (_group_budget, _resolve_org_urn, _create_group, _create_line_items, _create_ads, _rollback_and_raise) so the orchestrator reads as the sequence of steps it performs. Behaviour is unchanged — the rollback tracker and reverse-order teardown are preserved exactly (the publish tests pin both). Pure refactor. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
th0rz05
added a commit
that referenced
this pull request
Jun 9, 2026
The publish flow was a single ~159-line function nesting budget selection, group creation, org-URN resolution, per-line-item campaign creation, per-ad post/creative creation, and rollback-on-failure. Extract each concern into a focused helper (_group_budget, _resolve_org_urn, _create_group, _create_line_items, _create_ads, _rollback_and_raise) so the orchestrator reads as the sequence of steps it performs. Behaviour is unchanged — the rollback tracker and reverse-order teardown are preserved exactly (the publish tests pin both). Pure refactor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pure refactor of the LinkedIn publish flow.
publish_draft_campaignwas a single ~159-line function that nested six distinct concerns inside onetryblock. It's now a slim orchestrator delegating to focused helpers:_group_budget— pick the campaign-group total budget (explicit lifetime vs. summed line items)._resolve_org_urn— resolve the Company Page URN, only when an ad needs a freshly minted post._create_group— create + track the Campaign Group._create_line_items— one Campaign per LineItem, with B2B targeting resolution; returns URNs, unresolved facets, and result rows._create_ads— one Creative per Ad, minting a dark post where needed._rollback_and_raise— tear down partial work and re-raise with a summary.The orchestrator body drops from ~140 lines to ~35 and reads as the sequence of steps it performs.
Behaviour
Unchanged. The
_Createdrollback tracker and its reverse-dependency-order teardown are preserved exactly — the publish tests pin both the rollback ordering and the dark-post/existing-post branching, and all pass untouched.Also tidies a stale docstring line (B2B resolution is wired since #25, no longer "a follow-up").
Test plan
pytest -qgreen (43) — including the 5 publish/rollback tests, unchangedruff checkclean onserver.py