Repository navigation
Simplify published job execution #251
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
Merged
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d72ac37
WIP: simplify published source execution
cursoragent 270362c
Adjust job tests for artifact-first execution
cursoragent 7035894
Continue adapting job tests to artifact execution
cursoragent 4110f97
Keep aligning job tests with artifact runtime
cursoragent 4f9d07f
Narrow remaining job test drift
cursoragent 9270545
Reduce remaining repo-backed test drift
cursoragent 43d38c3
Refine artifact-first job execution checks
cursoragent 43f2316
Finish simplifying published job execution
cursoragent e14abed
Finish CI fallout for artifact execution
cursoragent d11aca8
Stabilize job service artifact tests
cursoragent 91cb4e0
Fix job bundle artifact identity
cursoragent 06aaf85
Guard rebuilt job artifact source IDs
cursoragent c9e71fb
Harden published artifact persistence
cursoragent bd60ea1
Update package projection test metadata
cursoragent 1775e57
Harden source snapshot sync logging
cursoragent 49aa3bd
Rollback source sync snapshot failures
cursoragent 0dfad45
Optimize rebuilt job artifact lookup
cursoragent 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
45 changes: 45 additions & 0 deletions
45
packages/worker/migrations/0028-published-bundle-artifacts-and-archived-jobs.sql
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,45 @@ | ||
| CREATE TABLE IF NOT EXISTS published_bundle_artifacts ( | ||
| id TEXT PRIMARY KEY, | ||
| user_id TEXT NOT NULL, | ||
| source_id TEXT NOT NULL, | ||
| published_commit TEXT NOT NULL, | ||
| artifact_kind TEXT NOT NULL, | ||
| artifact_name TEXT, | ||
| entry_point TEXT NOT NULL, | ||
| kv_key TEXT NOT NULL, | ||
| dependencies_json TEXT NOT NULL DEFAULT '[]', | ||
| created_at TEXT NOT NULL, | ||
| updated_at TEXT NOT NULL | ||
| ); | ||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_published_bundle_artifacts_source_identity | ||
| ON published_bundle_artifacts( | ||
| user_id, | ||
| source_id, | ||
| artifact_kind, | ||
| COALESCE(artifact_name, ''), | ||
| entry_point | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_published_bundle_artifacts_user_id | ||
| ON published_bundle_artifacts(user_id); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_published_bundle_artifacts_source_id | ||
| ON published_bundle_artifacts(source_id); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS archived_job_artifacts ( | ||
| job_id TEXT PRIMARY KEY, | ||
| user_id TEXT NOT NULL, | ||
| source_id TEXT NOT NULL, | ||
| published_commit TEXT NOT NULL, | ||
| storage_id TEXT NOT NULL, | ||
| retain_until TEXT NOT NULL, | ||
| created_at TEXT NOT NULL, | ||
| updated_at TEXT NOT NULL | ||
| ); | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_archived_job_artifacts_user_id | ||
| ON archived_job_artifacts(user_id); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_archived_job_artifacts_retain_until | ||
| ON archived_job_artifacts(retain_until); | ||
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,100 @@ | ||
| export type ArchivedJobArtifactRecord = { | ||
| id: string | ||
| jobId: string | ||
| userId: string | ||
| sourceId: string | ||
| publishedCommit: string | ||
| storageId: string | ||
| retainUntil: string | ||
| createdAt: string | ||
| updatedAt: string | ||
| } | ||
|
|
||
| export async function upsertArchivedJobArtifact(input: { | ||
| db: D1Database | ||
| jobId: string | ||
| userId: string | ||
| sourceId: string | ||
| publishedCommit: string | ||
| storageId: string | ||
| retainUntil: string | ||
| }) { | ||
| const now = new Date().toISOString() | ||
| const existing = await input.db | ||
| .prepare( | ||
| `SELECT id FROM archived_job_artifacts WHERE job_id = ? AND user_id = ? LIMIT 1`, | ||
| ) | ||
| .bind(input.jobId, input.userId) | ||
| .first<{ id: string }>() | ||
| if (existing?.id) { | ||
| await input.db | ||
| .prepare( | ||
| `UPDATE archived_job_artifacts | ||
| SET source_id = ?, published_commit = ?, storage_id = ?, retain_until = ?, updated_at = ? | ||
| WHERE id = ?`, | ||
| ) | ||
| .bind( | ||
| input.sourceId, | ||
| input.publishedCommit, | ||
| input.storageId, | ||
| input.retainUntil, | ||
| now, | ||
| existing.id, | ||
| ) | ||
| .run() | ||
| return existing.id | ||
| } | ||
| const id = crypto.randomUUID() | ||
| await input.db | ||
| .prepare( | ||
| `INSERT INTO archived_job_artifacts ( | ||
| id, job_id, user_id, source_id, published_commit, storage_id, retain_until, created_at, updated_at | ||
| ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| ) | ||
| .bind( | ||
| id, | ||
| input.jobId, | ||
| input.userId, | ||
| input.sourceId, | ||
| input.publishedCommit, | ||
| input.storageId, | ||
| input.retainUntil, | ||
| now, | ||
| now, | ||
| ) | ||
| .run() | ||
| return id | ||
| } | ||
|
|
||
| export async function listArchivedJobArtifactsDueBefore( | ||
| db: D1Database, | ||
| retainUntil: string, | ||
| ): Promise<Array<ArchivedJobArtifactRecord>> { | ||
| const { results } = await db | ||
| .prepare( | ||
| `SELECT id, job_id, user_id, source_id, published_commit, storage_id, retain_until, created_at, updated_at | ||
| FROM archived_job_artifacts | ||
| WHERE retain_until <= ? | ||
| ORDER BY retain_until ASC`, | ||
| ) | ||
| .bind(retainUntil) | ||
| .all<Record<string, unknown>>() | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| return (results ?? []).map((row) => ({ | ||
| id: String(row['id']), | ||
| jobId: String(row['job_id']), | ||
| userId: String(row['user_id']), | ||
| sourceId: String(row['source_id']), | ||
| publishedCommit: String(row['published_commit']), | ||
| storageId: String(row['storage_id']), | ||
| retainUntil: String(row['retain_until']), | ||
| createdAt: String(row['created_at']), | ||
| updatedAt: String(row['updated_at']), | ||
| })) | ||
| } | ||
|
|
||
| export async function deleteArchivedJobArtifact(db: D1Database, id: string) { | ||
| await db | ||
| .prepare(`DELETE FROM archived_job_artifacts WHERE id = ?`) | ||
| .bind(id) | ||
| .run() | ||
| } | ||
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.