Logo Background Jobs

Background Jobs

Cộng đồng
nahid-sparktales
background-jobs

Design queued and scheduled work so it survives duplicates, retries, crashes and restarts — job contract, idempotency, transactional enqueue, backoff, dead letters, leases and the ordering guarantees you actually have. Use when moving work off a request path, adding a worker or cron, or debugging a job that ran twice, never ran, ran out of order, or is stuck retrying forever. Not for in-request async concurrency, and not for stream processing topology design.

Add to TypingMind

Tổng quan

Nhà phát hànhnahid-sparktales
Kho mãagent-dispatcher
Tên kỹ năngbackground-jobs
Sao
58
Bản fork
5
Tệp đi kèm
1
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 1 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được nahid-sparktales công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Background Jobs trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/nahid-sparktales/agent-dispatcher/tree/main/skills/backend/background-jobs
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/nahid-sparktales/agent-dispatcher.git /tmp/agent-dispatcher
mkdir -p .claude/skills
cp -r /tmp/agent-dispatcher/skills/backend/background-jobs .claude/skills/background-jobs
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Background Jobs trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Background Jobs ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Background Jobs với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Background jobs

Every queue gives you at-least-once delivery and no useful ordering. Everything else — exactly once, in order, eventually — is something you build on top, or something you are assuming and will be paged about. Design for the guarantee you have, not the one you want.

When this fires

Work is being moved out of a request path; a queue, worker, scheduler or cron entry is being added or changed; or a job misbehaved — ran twice, silently vanished, processed stale data, or filled a dead-letter queue. It does not fire for concurrency inside a single request, and not for designing a streaming topology.

Procedure

  1. Check it belongs off the request path. If the caller needs the result to respond, it is not a job — making it one just moves the wait somewhere the user cannot see. Enqueue work that is slow, retryable, and whose completion the caller can learn about later.
  2. Define the job contract. Small, serializable payload. Prefer passing an identifier and re-reading current state in the worker over embedding a snapshot — with one exception: when the job must act on the values as they were at enqueue time, embed them and say why. Never enqueue a live object, a connection, or anything whose meaning depends on the sender's memory.
  3. Make the handler idempotent before anything else. Assume every job runs at least twice, sometimes concurrently. Give the work a natural idempotency key, and either guard with a unique constraint on the effect, or check-and-claim the row before acting. "It only runs twice if something crashes" is a statement about how often, not whether.
  4. Enqueue transactionally. Enqueue inside the transaction and the worker can pick up a job for a row that never committed; enqueue after commit and a crash in the gap loses the job silently. Pick one and cover the gap: write the job to an outbox table in the same transaction and have a relay publish it, or enqueue after commit and add a sweep that finds rows whose job never ran. Say which you chose; both are acceptable, silence is not.
  5. Separate retryable from permanent failures. A timeout, a 503 and a deadlock are worth retrying. A validation error, a 404 and a malformed payload are not — retrying them burns the queue and delays everything behind them. Fail those immediately and visibly.
  6. Set backoff, jitter and a cap. Exponential backoff with random jitter, so a downstream outage does not produce a synchronized retry wave that keeps it down. Cap the attempts; an uncapped retry is an infinite loop with a network bill.
  7. Give poison messages somewhere to land, and someone to read it. After the cap, move the job to a dead-letter queue or a failed-jobs table carrying the payload, the error and the attempt count. A dead-letter queue nobody monitors is a deletion with extra steps, so name the alert in the same change. Replaying a dead-letter queue re-executes real side effects — charges, emails, webhooks — so it stops and asks before replay, every time.
  8. Match the lease to the work. Queues hand out a message with a visibility timeout or lease; if the handler is still running when it expires, the message is redelivered and you now have two workers on the same job. Set the lease above the p99 runtime, extend it by heartbeat for long jobs, or split the job until it fits. This is the single most common source of "it ran twice".
  9. State the ordering you actually have. Across a queue: none. Within a partition or a FIFO group key: order holds only while concurrency is one and nothing is retried — one retry puts a message behind its successor. So either serialize per entity with a key and a single consumer, or make the updates order-independent: carry a version or timestamp and ignore anything older than what is already applied. Do not design around order you cannot name.
  10. For scheduled work, handle the four schedule failures. Cron running on N instances fires N times — take a lock or have exactly one scheduler. Decide whether a run missed during downtime is skipped or caught up, because the default is skip and nobody notices. Guard overlap when a run outlives its interval. Pin the timezone explicitly: local-time schedules lose or repeat an hour at DST transitions.
  11. Emit the four numbers. Queue depth, age of the oldest unprocessed message, failure rate, and attempts per job. Alert on age, not depth — a deep queue that is draining is fine, a shallow queue whose oldest message is an hour old is broken.
  12. Test the handler directly. It is a function: call it twice with the same input and assert the effect happened once; make its dependency throw and assert the retry classification; feed it the payload that killed it in production. Enqueuing a job in a test asserts nothing about the handler.

Checklist

  • The caller genuinely does not need the result inline
  • Payload is small, serializable, and either an id or a justified snapshot
  • Handler is idempotent, with the guard named (unique constraint, claim, idempotency key)
  • Enqueue is transactional, or the gap is covered by an outbox or a sweep
  • Retryable vs permanent failures are distinguished in code, not by hope
  • Backoff has jitter and an attempt cap
  • Dead letters land somewhere and an alert names them
  • Lease/visibility timeout exceeds p99 runtime, or is heartbeated
  • The ordering guarantee is stated, and the design does not need more than it has
  • Scheduled work: single-firing, missed-run policy, overlap guard, explicit timezone
  • Queue age is monitored and alerted, not just depth
  • Handler tested twice-called and failure-path tested

Failure handling

  • Job ran twice — look at the lease before the enqueue code. A handler that outlives its visibility timeout is redelivered, and no amount of enqueue-side deduplication prevents it. Fix idempotency first; it is the only durable fix.
  • Job never ran — establish which it is: never enqueued, enqueued and lost, or consumed and failed silently. These have different fixes, and the logs distinguish them. Check the dead-letter queue before concluding it vanished.
  • Queue backing up — check age of oldest and failure rate together. Rising age with a rising failure rate is a retry storm feeding itself, not a capacity problem; adding workers makes it worse. Stop the retry storm first.
  • Worker stuck on one message — a poison message with no attempt cap. Find it, cap the attempts, and route it to dead letters. Purging the queue to clear it is destructive and discards unrelated work: stop and ask, and say how many messages would be lost.
  • Cannot reproduce locally — expected. Single-worker local runs hide every concurrency, redelivery and ordering failure this skill exists for. Report it as unreproduced, not as fixed.

Evidence to report

Distinguish plainly: the job was created (code written), executed (a worker picked it up and the run is in the logs), succeeded (the effect is visible in the data), and tested (the handler was called twice and the duplicate was absorbed). Report the delivery guarantee, the idempotency key, the retry policy and cap, the lease value against measured runtime, the ordering guarantee relied on, and where dead letters go and who is alerted. Name what was not exercised — concurrent duplicate delivery, the enqueue crash gap, and DST behaviour are usually among them.

Tệp đi kèm

Khi kỹ năng đã được tải, mô hình có thể đọc các tệp này nếu cần. Các tệp này chỉ dùng để đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Background Jobs làm được gì?

Design queued and scheduled work so it survives duplicates, retries, crashes and restarts — job contract, idempotency, transactional enqueue, backoff, dead letters, leases and the ordering guarantees you actually have. Use when moving work off a request path, adding a worker or cron, or debugging a job that ran twice, never ran, ran out of order, or is stuck retrying forever. Not for in-request async concurrency, and not for stream processing topology design.

Vì sao nên dùng Background Jobs trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Background Jobs là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Background Jobs trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/nahid-sparktales/agent-dispatcher/tree/main/skills/backend/background-jobs. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm rồi cài đặt cả gói dưới dạng một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Background Jobs?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Background Jobs với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Background Jobs với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Background Jobs có miễn phí không?

Có. Kỹ năng này được nahid-sparktales phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇