-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(core): reconcile media usage indexes automatically #2443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
khoinguyenpham04
merged 21 commits into
main
from
feature/media-usage-automatic-reconciliation
Aug 13, 2026
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ba4646a
feat(core): add guarded collection deletion foundation
khoinguyenpham04 302ac9e
feat(core): safely detach activated collections
khoinguyenpham04 a576d10
feat(core): process bounded collection deletion cleanup
khoinguyenpham04 83dbf0c
feat(core): expose collection deletion recovery controls
khoinguyenpham04 2d36e13
fix(cloudflare): harden collection deletion guards
khoinguyenpham04 725ef86
fix(core): bound collection deletion completion checks
khoinguyenpham04 110f945
fix(core): use database time for deletion progress
khoinguyenpham04 1d81a96
chore(core): register collection deletion schemas
khoinguyenpham04 808d03e
chore(core): keep deletion lease guards transaction-scoped
khoinguyenpham04 26e4b26
fix(core): preserve collection deletion compatibility
khoinguyenpham04 90f01f8
fix(cloudflare): pin mutation reads to DO primary
khoinguyenpham04 e2a18b6
feat(media): add reconciliation coordinator state
khoinguyenpham04 136ece4
feat(media): add bounded reconciliation scan
khoinguyenpham04 e3d35a2
feat(media): finalize automatic reconciliation
khoinguyenpham04 da3101d
feat(media): schedule automatic reconciliation
khoinguyenpham04 5ce7f25
fix(media): preserve scheduled maintenance compatibility
khoinguyenpham04 da4e77e
Merge remote-tracking branch 'origin/main' into feature/media-usage-a…
khoinguyenpham04 8c8c0e0
docs: clarify automatic reconciliation changeset
khoinguyenpham04 1a96dda
fix(core): guard null media usage revisions on postgres
khoinguyenpham04 7a3ff56
fix(cloudflare): default scheduled cron routing
khoinguyenpham04 29ae696
docs(cloudflare): keep worker comments current
khoinguyenpham04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "emdash": patch | ||
| "@emdash-cms/cloudflare": patch | ||
| --- | ||
|
|
||
| Adds automatic, resumable background indexing so Media Usage can safely catch up on existing content without processing the whole site at once. |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { beforeEach, expect, it, vi } from "vitest"; | ||
|
|
||
| const scheduled = vi.hoisted(() => ({ | ||
| general: vi.fn(async () => ({ published: [] })), | ||
| mediaUsage: vi.fn(async () => ({ outcome: "inactive", taskClass: null, turn: null })), | ||
| })); | ||
|
|
||
| vi.mock("@astrojs/cloudflare/entrypoints/server", () => ({ default: { fetch: vi.fn() } })); | ||
| vi.mock("astro/app/entrypoint", () => ({ | ||
| createApp: () => ({ pipeline: { getCacheProvider: async () => null } }), | ||
| })); | ||
| vi.mock("emdash/middleware", () => ({ | ||
| runScheduledTasks: scheduled.general, | ||
| runScheduledMediaUsageTasks: scheduled.mediaUsage, | ||
| })); | ||
| vi.mock("../src/sandbox/index.js", () => ({ PluginBridge: vi.fn() })); | ||
|
|
||
| import { createScheduledHandler } from "../src/worker.js"; | ||
|
|
||
| beforeEach(() => { | ||
| scheduled.general.mockClear(); | ||
| scheduled.mediaUsage.mockClear(); | ||
| }); | ||
|
|
||
| it("keeps the unconfigured handler backwards-compatible", async () => { | ||
| await invoke(createScheduledHandler(), "custom expression"); | ||
| expect(scheduled.general).toHaveBeenCalledOnce(); | ||
| expect(scheduled.mediaUsage).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it("dispatches distinct configured cron expressions to exactly one lane", async () => { | ||
| const handler = createScheduledHandler({ | ||
| generalCron: "* * * * *", | ||
| mediaUsageCron: "*/2 * * * *", | ||
| }); | ||
|
|
||
| await invoke(handler, "* * * * *"); | ||
| expect(scheduled.general).toHaveBeenCalledOnce(); | ||
| expect(scheduled.mediaUsage).not.toHaveBeenCalled(); | ||
|
|
||
| scheduled.general.mockClear(); | ||
| await invoke(handler, "*/2 * * * *"); | ||
| expect(scheduled.general).not.toHaveBeenCalled(); | ||
| expect(scheduled.mediaUsage).toHaveBeenCalledOnce(); | ||
|
|
||
| scheduled.mediaUsage.mockClear(); | ||
| await invoke(handler, "0 0 * * *"); | ||
| expect(scheduled.general).not.toHaveBeenCalled(); | ||
| expect(scheduled.mediaUsage).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("rejects empty or aliased configured expressions", () => { | ||
| expect(() => | ||
| createScheduledHandler({ generalCron: "* * * * *", mediaUsageCron: "* * * * *" }), | ||
| ).toThrow(/must differ/i); | ||
| expect(() => createScheduledHandler({ generalCron: "", mediaUsageCron: "*/2 * * * *" })).toThrow( | ||
| /non-empty/i, | ||
| ); | ||
| }); | ||
|
|
||
| async function invoke(handler: ExportedHandlerScheduledHandler, cron: string): Promise<void> { | ||
| const pending: Promise<unknown>[] = []; | ||
| const context = { | ||
| waitUntil(promise: Promise<unknown>) { | ||
| pending.push(promise); | ||
| }, | ||
| }; | ||
| Reflect.apply(handler, undefined, [{ cron }, {}, context]); | ||
| await Promise.all(pending); | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.