Skip to content

feat(jobs): add cancellation and queued source transfers - #666

Open
hmjn023 wants to merge 1 commit into
feat/v2-migration-foundationfrom
feat/v2-migration-backed-jobs
Open

feat(jobs): add cancellation and queued source transfers#666
hmjn023 wants to merge 1 commit into
feat/v2-migration-foundationfrom
feat/v2-migration-backed-jobs

Conversation

@hmjn023

@hmjn023 hmjn023 commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Stack created with GitHub Stacks CLIGive Feedback 💬

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (1)
  • develop

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d6a1cb9c-92ac-4b89-8d67-d9c513b292c8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hmjn023
hmjn023 force-pushed the feat/v2-migration-backed-jobs branch from 253f1ff to 57ff3f7 Compare August 10, 2026 15:22

@hmjn023 hmjn023 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

追加レビューです。#663 に既にある同一source sync、retryのCAS、jobs output schema、raw error、retry eventの指摘とは重複しない追加リスクをコメントしています。特に stale recovery、parent cancellation、restore lifecycle、通常完了イベントはmerge前に対応が必要です。

const staleBaseCondition = and(
eq(jobs.status, "in_progress"),
lt(jobs.updatedAt, olderThan),
notInArray(jobs.type, [

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 長時間 transfer job を stale recovery から保護してください

updatedAt は claim/start と終了時にしか更新されず、JobWorker に実行中の heartbeat がありません。それにもかかわらず、この除外リストには source_export / source_restore が含まれていないため、1時間を超える export/restore がまだ実行中でも pending に戻され、別workerが同じ処理を開始できます。lease/tokenによる所有権確認、実行中heartbeat、または少なくとも非冪等なtransfer jobの除外が必要です。

});
}

await JobRepository.requestCancellation(input.id);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] batch parent のキャンセルを子jobへ伝播するか、UI/APIで拒否してください

このendpointは batch_ccip_parentbulk_tagging_parentthumbnail_generation_parent も受け付けますが、parentはworkerにclaimされず、requestCancellation はフラグを立てるだけです。子jobは継続し、各finalizerがparentを無条件に completed/failed へ更新します。現状のCancel操作は成功したように見えて実処理を止めません。parent種別を拒否するか、子jobのcascade cancelとfinalizer側のcancel優先処理を追加してください。

payload.inputPath,
);
} finally {
await removeJobTransferFile(payload.inputPath);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] restore入力をretry可能な期間まで保持してください

jobs.retry は失敗jobのpayloadをそのまま再利用するため、retry時も同じ inputPath を参照します。しかしこの finally は最初のrestoreが失敗しても入力ファイルを削除します。結果としてretryは必ずmissing-inputになり、再アップロードや入力artifactの再生成もできません。入力をretry用に保持するか、retry時に新しい入力を受け取る設計にしてください。なお、importがエラー配列を返すだけのケースもworker側でcompleted扱いになるため、部分失敗の状態表現も合わせて見直しが必要です。

await this.markCancelled(job);
return;
} else {
await this.jobRepo.markAsCompleted(job.id, safeResult);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 通常のcompleted/failed遷移でもjob eventをpublishしてください

このPRで job-cancelled はpublishされますが、通常の markAsCompleted / markAsFailed の直後には job-completed / job-failed がありません。source transfer jobにはparent finalizerによる代替通知もないため、jobs画面はイベントを受け取れず、別クライアントの表示がpendingのまま残ります。DB更新の成否を確認したうえで、完了・失敗・retryの各遷移を既存event streamへ通知してください。

".cache",
"job-transfers",
);
const JobArtifactTtlMs = 24 * 60 * 60 * 1000;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 期限切れartifactと中断されたinputのcleanupを追加してください

ここでTTLを計算していますが、artifact endpointは期限後に410を返すだけでファイルを削除しません。さらに、processor開始前にcancelされたrestoreのinputも削除されない経路があります。startup/workerの定期cleanup、または明示的なcancel/finalize cleanupを追加しないと、長期運用で .cache/job-transfers が増え続けます。

status: MediaSourceSyncState,
message?: string,
): Promise<void> {
publishSyncStatus(mediaSourceId, status, message);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] sync status は永続化後にpublishするか、event payloadでUI cacheを直接更新してください

現在はDB更新より先にeventをpublishしています。UI側はevent payloadをcacheへ反映せずinvalidateして再取得するだけなので、event直後のrefetchが古いDB状態を読み、syncing/idle/errorの表示が取りこぼされるraceがあります。永続化を先にするか、受信側でeventのstatusを直接適用してください。

});
}),

enqueueExport: os

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] enqueueExport/enqueueImport に共有output schemaを設定してください

これらの新しいhandlerは toJobDto(job) を返しますが、.output(...) がないため、生成されたOpenAPIの200 responseが空の anyOf になります。#663のjobs endpointと同じ jobDtoSchema を共有して、transfer APIの契約と生成clientの型を実行時・OpenAPIの両方で保証してください。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant