Skip to content

feat(queue): add opt-in error callback and standardize README - #10

Merged
usernane merged 1 commit into
mainfrom
dev
Sep 20, 2026
Merged

usernane merged 1 commit into
mainfrom
dev

Conversation

@usernane

Copy link
Copy Markdown
Member

Summary

Adds an opt-in error callback so applications can observe job-processing failures, and standardizes the README.

Motivation

Closes #9 and #6.

Changes

#9 — expose job-processing exceptions

  • Queue::setOnError(?callable $cb) / getOnError() — an opt-in callback invoked for every caught throwable, with signature fn(?Job $job, \Throwable $e, int $attempts, bool $willRetry): void. It fires for both intermediate retries ($willRetry = true) and terminal failures ($willRetry = false).
  • Failed jobs now record richer context: getFailReason() includes the exception class in addition to the message.
  • Invalid (non-Job) payloads are reported to the callback as terminal failures with a null job (and still marked failed).
  • QueueFacade::setOnError() passthrough.
  • Fully additive/opt-in: with no callback registered, the catch → retry / mark-failed behavior is unchanged.

#6 — standardize README

  • Added Table of Contents and Testing / Examples / Contributing / Support / Changelog sections.
  • Documented the new setOnError (an "Observing Failures" section) and added it to the API table.
  • Fixed an inaccurate example (getFailed() returns QueuedJob[], so retry($failed[0]->getId()), not array access).

How to Test / Verify

  • composer test → 38 tests pass (was 33; +5 new covering: onError on terminal failure, intermediate retry, invalid payload, chainability/getter, facade passthrough). Two existing tests updated for the enriched failReason format.
  • All 6 README PHP code blocks verified with php -l.
  • composer fix-cs clean.

Breaking Changes and Migration Steps

None. The callback is opt-in. The only observable change is that a failed job's getFailReason() now includes the exception class prefix (e.g. RuntimeException: ...) in addition to the message.

Checklist

  • I reviewed my own diff before requesting review
  • My commits follow Conventional Commits
  • I added/updated tests (or explained why not)
  • I updated docs (if needed) Docs Repo — README updated
  • I ran lint/cs-fixer (if applicable) (composer fix-cs)
  • I considered backward compatibility
  • I considered security

Related issues

Closes #9, Closes #6

#9: expose job-processing exceptions
- Add Queue::setOnError()/getOnError(): a callback invoked for every caught
  throwable while processing a job, with signature
  fn(?Job $job, Throwable $e, int $attempts, bool $willRetry). It fires for
  both intermediate retries and terminal failures, letting applications bridge
  queue failures into a centralized logger with full exception context.
- Enrich the failed job's failReason with the exception class in addition to
  the message.
- QueueFacade::setOnError() passthrough.
- Invalid (non-Job) payloads are reported to the callback as terminal failures
  with a null job. Additive and opt-in: behavior is unchanged without a callback.

#6: standardize README
- Add Table of Contents and Testing/Examples/Contributing/Support/Changelog
  sections; document setOnError; fix an inaccurate getFailed() retry example.

Closes #9, closes #6
@codecov

codecov Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.72%. Comparing base (3eb9bf2) to head (9a203ca).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main      #10      +/-   ##
============================================
+ Coverage     96.03%   97.72%   +1.69%     
- Complexity       78       84       +6     
============================================
  Files             4        4              
  Lines           252      264      +12     
============================================
+ Hits            242      258      +16     
+ Misses           10        6       -4     
Flag Coverage Δ
php-8.1 97.72% <100.00%> (+1.69%) ⬆️
php-8.2 97.72% <100.00%> (+1.69%) ⬆️
php-8.3 97.72% <100.00%> (+1.69%) ⬆️
php-8.4 97.72% <100.00%> (+1.69%) ⬆️
php-8.5 97.72% <100.00%> (+1.69%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@usernane
usernane merged commit 0374739 into main Sep 20, 2026
18 checks passed
@sonarqubecloud

Copy link
Copy Markdown

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(queue): expose job-processing exceptions (swallowed in Queue::process()) docs: standardize README.md structure

1 participant