Skip to content

Add runnable examples demonstrating job-queue usage - #309

Open
paulbjensen wants to merge 1 commit into
masterfrom
feature/examples
Open

Add runnable examples demonstrating job-queue usage#309
paulbjensen wants to merge 1 commit into
masterfrom
feature/examples

Conversation

@paulbjensen

Copy link
Copy Markdown
Member

Summary

  • Adds six self-contained example projects under examples/, each pairing a real-world use case with one of the library's backends, plus a top-level examples/README.md indexing them all:
    • mp4-to-hls (SQLite) — transcode an uploaded video into HLS (.m3u8 + .ts) with ffmpeg
    • email-sending (Redis) — send email in the background via nodemailer + an auto-created Ethereal test account
    • csv-import (Postgres) — stream-parse a CSV file and bulk-insert its rows
    • image-thumbnails (SQLite) — resize images into multiple sizes with sharp; the fastest one to try, good as a first example
    • webhook-delivery (SQLite) — retry failed HTTP deliveries with backoff, the only example built around the queue's fail/retry hooks rather than just add/take
    • pdf-report-generation (SQLite) — render a PDF invoice with pdfkit, no headless browser needed
  • Each example depends on the library via file:../.. and follows the same shape (src/queue.ts, src/worker.ts, src/add-job.ts, src/start-worker.ts), so the pattern is easy to compare across examples and backends.
  • Each example's own README documents its prerequisites and exact commands to run it.

Test plan

  • Every example: npm install, npx tsc --noEmit — clean
  • npx @biomejs/biome check — clean on all example files
  • Ran each example end-to-end locally and verified output:
    • mp4-to-hls: generated a test mp4, confirmed a valid .m3u8 playlist + .ts segment
    • email-sending: queued and sent an email, confirmed an Ethereal preview URL
    • csv-import: queued and imported the sample CSV into a scratch Postgres database, confirmed all rows landed correctly and the job reached completed
    • image-thumbnails: generated a test image, confirmed three correctly-sized .webp outputs
    • webhook-delivery: confirmed both the retry-with-backoff path (fails twice, succeeds on 3rd attempt) and the exhausted-retries path (job ends failed after 3 retries)
    • pdf-report-generation: rendered the sample invoice, parsed the output PDF's text and confirmed all line items and the grand total are correct
  • npm t (root package, via pre-commit hook) — 69/69 tests pass, unaffected by this change

🤖 Generated with Claude Code

Adds six self-contained example projects under examples/, each showing
a different real-world use case paired with one of the library's
backends, plus a top-level README indexing them all:

- mp4-to-hls (SQLite) - transcode video into HLS with ffmpeg
- email-sending (Redis) - background email via nodemailer + Ethereal
- csv-import (Postgres) - stream-parse and bulk-insert a CSV file
- image-thumbnails (SQLite) - resize images with sharp
- webhook-delivery (SQLite) - retry-with-backoff using the fail/retry hooks
- pdf-report-generation (SQLite) - render a PDF invoice with pdfkit

Each example depends on the library via `file:../..` and follows the
same shape (src/queue.ts, src/worker.ts, src/add-job.ts,
src/start-worker.ts) so the pattern is easy to compare across examples.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​pdfkit@​0.17.61001007584100
Added@​types/​nodemailer@​8.0.11001007687100
Addedcsv-parse@​7.0.21001009790100
Addedsharp@​0.35.39710010091100
Addedpdfkit@​0.19.19910010092100
Addednodemailer@​9.0.5961009794100

View full report

@socket-security

Copy link
Copy Markdown

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: npm @noble/hashes is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: ?npm/pdfkit@0.19.1npm/@noble/hashes@1.8.0

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@noble/hashes@1.8.0. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm @noble/hashes is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: ?npm/pdfkit@0.19.1npm/@noble/hashes@1.8.0

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@noble/hashes@1.8.0. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm brotli is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: ?npm/pdfkit@0.19.1npm/brotli@1.3.3

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/brotli@1.3.3. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm brotli is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: ?npm/pdfkit@0.19.1npm/brotli@1.3.3

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/brotli@1.3.3. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

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