Skip to content

Add Faktory Enterprise Batch API support#441

Open
Otanikotani wants to merge 5 commits intojbielick:mainfrom
Otanikotani:feat/batch-api
Open

Add Faktory Enterprise Batch API support#441
Otanikotani wants to merge 5 commits intojbielick:mainfrom
Otanikotani:feat/batch-api

Conversation

@Otanikotani
Copy link
Copy Markdown

Summary

Adds support for Faktory Enterprise Batches, mirroring the Go client's batch API.

  • New Batch class with lifecycle management (jobs(), push(), commit(), reopened())
  • Client methods: batch(), batchNew(), batchOpen(), batchCommit(), batchStatus()
  • Exported from the faktory module alongside existing Mutation, Job, etc.
  • 10 tests using mock server infrastructure

Usage

const client = await faktory.connect();

// Create batch with callbacks
const batch = client.batch({
  description: "Import users",
  success: client.job("ImportComplete", userId),
  complete: client.job("ImportNotify", userId),
});
await batch.jobs(async () => {
  await batch.push(client.job("ImportRow", row1));
  await batch.push(client.job("ImportRow", row2));
});

// Reopen from within a batch job
const batch = await client.batchOpen(bid);
await batch.push(client.job("MoreWork", arg));
await batch.commit();

// Check status
const status = await client.batchStatus(bid);

Wire protocol

Method Command Response
batchNew(batch) BATCH NEW <json> BID string
batchOpen(bid) BATCH OPEN <bid> OK
batchCommit(bid) BATCH COMMIT <bid> OK
batchStatus(bid) BATCH STATUS <bid> JSON status

Test plan

  • Constructor sets defaults
  • toJSON() serializes callback jobs correctly
  • push() throws if batch not opened
  • push() throws if already committed
  • commit() throws if already committed
  • jobs() throws if called twice
  • push() sets custom.bid on job
  • jobs() sends BATCH NEW → PUSH → BATCH COMMIT in order
  • batchOpen returns usable batch for reopening
  • batchStatus returns parsed status object

🤖 Generated with Claude Code

Otanikotani and others added 5 commits March 24, 2026 18:52
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Prevents calling jobs() on a reopened batch from creating a duplicate
batch on the server.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Otanikotani
Copy link
Copy Markdown
Author

Hello @jbielick ! I want to apologize from the get go about submitting AI-assisted pull request. Please let me know if this is not something you would even consider to be added to the repository.

This PR adds .batch() functionality to node version. I tried to copy https://github.com/contribsys/faktory_worker_go for what I could. I am definitely not an expert in this, but our company uses node and we do want batching. We have something done internally already to address this, but I was thinking to share it and make it available to all.

Please let me know if something is off here!

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