Skip to content

feat: pass onComplete/onFail callbacks through createJobHooks useRun#155

Merged
coji merged 2 commits into
mainfrom
feat/usejobrun-callbacks
Mar 27, 2026
Merged

feat: pass onComplete/onFail callbacks through createJobHooks useRun#155
coji merged 2 commits into
mainfrom
feat/usejobrun-callbacks

Conversation

@coji
Copy link
Copy Markdown
Owner

@coji coji commented Mar 27, 2026

Summary

  • createJobHooksuseRun フックに onStart/onComplete/onFail コールバックを pass-through できるようにする(Issue feat: pass onComplete/onFail callbacks through createJobHooks useRun #139
  • コールバック options 型を Pick<UseJobRunClientOptions, 'onStart' | 'onComplete' | 'onFail'> として UseJobRunClientOptions から導出し型の重複を排除
  • types.test.tsuseRun 型テスト追加
  • create-job-hooks.test.tsx にコールバック動作テスト追加(onComplete / onFail / onStart 発火、rerender 後の重複発火なし)

Usage

const { runId, clearRunId } = usePersistedRunId()
durably.crawl.useRun(runId, { onComplete: clearRunId, onFail: clearRunId })

Test plan

  • onComplete が run 完了時に正確に 1 回発火する
  • onFail が run 失敗時に正確に 1 回発火する
  • onStart が null → pending 遷移時に正確に 1 回発火し、leased への再遷移では発火しない
  • rerender 後にコールバックが重複発火しない
  • useRun(runId) オプションなしで従来通り動作する
  • pnpm validate 28/28 パス

Closes #139

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • New Features

    • useRun フックがオプションのコールバック(onStart / onComplete / onFail)を受け取れるようになりました。実行開始・完了・失敗時に任意の処理を実行できます。
  • Tests

    • コールバックの振る舞いを検証する実行時テストを追加しました(イベント駆動の遷移と再発火防止を含む)。
    • 型レベルのテストを追加し、useRun の引数と戻り値の型を検証しました。

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
durably-demo Ready Ready Preview Mar 27, 2026 3:00pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
durably-demo-vercel-turso Ignored Ignored Mar 27, 2026 3:00pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a648e0cf-2539-45ea-a0ec-88630ef6c6fe

📥 Commits

Reviewing files that changed from the base of the PR and between 20900a1 and e56d57f.

📒 Files selected for processing (2)
  • packages/durably-react/src/client/create-job-hooks.ts
  • packages/durably-react/tests/client/create-job-hooks.test.tsx
✅ Files skipped from review due to trivial changes (1)
  • packages/durably-react/tests/client/create-job-hooks.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/durably-react/src/client/create-job-hooks.ts

📝 Walkthrough

Walkthrough

createJobHooksuseRunフックが第2引数optionsonStartonCompleteonFail)を受け取るように拡張され、これらのコールバックは基盤のuseJobRunへ転送されます。関連する統合テストと型テストが追加されました。

Changes

Cohort / File(s) Summary
useRun フックの API 拡張
packages/durably-react/src/client/create-job-hooks.ts
useRun(runId)useRun(runId, options?)に変更。RunCallbackOptions型(onStart/onComplete/onFailをPickした型)を導入し、オプションをuseJobRunへスプレッドして渡すように実装を更新。UseJobRunClientOptions型のインポートを追加。
統合テスト追加
packages/durably-react/tests/client/create-job-hooks.test.tsx
useRunのコールバック動作を検証するテスト群を追加。SSEモックを用いてonStart/onComplete/onFailが1回だけ呼ばれること、端末状態後の再レンダリングで再発火しないことを検証。act/waitForを導入して非同期遷移を待機。
型テスト追加
packages/durably-react/tests/types.test.ts
createJobHooks生成のuseRunの型シグネチャを型テストで追加。第1引数が`string

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 新しいオプション、ぴょんと受け取る
onStartで跳び、onCompleteで笑い、onFailで気をつける
useRunから渡して、仕事は続くよ
型もテストも揃えてぴょんぴょん前進!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title clearly summarizes the main change: adding callback pass-through to createJobHooks' useRun hook, aligning with the changeset.
Linked Issues check ✅ Passed All Issue #139 requirements met: callbacks forwarded to useRun with optional second parameter, backward compatibility maintained, type safety ensured via Pick.
Out of Scope Changes check ✅ Passed All changes directly address Issue #139 objectives: implementation updates, comprehensive type tests, and runtime callback verification tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/usejobrun-callbacks

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 and usage tips.

…it.each

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coji coji merged commit a8de66c into main Mar 27, 2026
5 checks passed
@coji coji deleted the feat/usejobrun-callbacks branch March 27, 2026 15:08
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.

feat: pass onComplete/onFail callbacks through createJobHooks useRun

1 participant