npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@aws-blocks/bb-async-job

v0.1.1

Published

Background job processing backed by SQS and Lambda.

Downloads

1,709

Readme

@aws-blocks/bb-async-job

Background job processing backed by SQS and Lambda.

Quick Reference

Common Operations → Methods

| What you want | Use this method | |---------------|----------------| | Submit a job | submit(payload) | | Submit with delay | submit(payload, { delaySeconds: 60 }) | | Submit multiple jobs | submitBatch(payloads) | | Get job ID back | const { jobId } = await job.submit(payload) |

Keywords: queue, job, background, async, worker, submit, batch, retry, SQS

Available Methods:

  • submit(payload, options?) - Enqueue a single job (returns { jobId })
  • submitBatch(payloads, options?) - Enqueue up to 10 jobs in one call (returns { jobIds, failed: [] } on full success). On partial failure, throws AsyncJobErrors.BatchSubmitFailed — the error has .jobIds (with null at failed indexes) and .failed[] (each entry's index, code, message). The mock runtime never partially fails; this is AWS-only.

Quick Start

import { Scope } from '@aws-blocks/core';
import { AsyncJob } from '@aws-blocks/bb-async-job';

const scope = new Scope('my-app');

const emailJob = new AsyncJob(scope, 'welcome-email', {
  handler: async (payload: { to: string; subject: string }, ctx) => {
    console.log(`Processing job ${ctx.jobId}, attempt ${ctx.receiveCount}`);
    await sendEmail(payload.to, payload.subject);
  },
});

// Submit from your API — returns immediately
const { jobId } = await emailJob.submit({ to: '[email protected]', subject: 'Welcome' });

When to Use

  • Sending emails or notifications
  • Processing file uploads
  • Generating reports
  • Any fire-and-forget task that shouldn't block the API response

Options

| Option | Default | Description | |--------|---------|-------------| | handler | (required) | Async function that processes each job | | schema | — | StandardSchemaV1 (Zod, Valibot, etc.) for payload validation on submit | | maxRetries | 3 | Maximum attempts before sending to the dead-letter queue | | batchSize | 1 | Messages per Lambda invocation | | logger | — | Optional logger for internal operations; defaults to a Logger at error level |

Error Constants

import { AsyncJobErrors } from '@aws-blocks/bb-async-job';

AsyncJobErrors.PayloadTooLarge    // payload > 256 KB
AsyncJobErrors.BatchEmpty         // submitBatch([]) called with no items
AsyncJobErrors.BatchTooLarge      // batch > 10 items
AsyncJobErrors.ValidationFailed   // schema validation failed
AsyncJobErrors.BatchSubmitFailed  // one or more messages failed to enqueue

Local Development

In local dev mode, AsyncJob uses an in-process queue. Jobs process via setTimeout in the same Node.js process. Retries, DLQ behavior, and payload limits are enforced identically to AWS.

AWS Deployment

Automatically provisions an SQS queue, dead-letter queue, and connects to the shared API Lambda. Failed jobs become visible for retry after 900 seconds (matching the Lambda timeout).

How Do I Know My Job Ran?

AsyncJob is fire-and-forget — submit() returns immediately, and the handler runs later.

Track job status in your handler:

const store = new KVStore(scope, 'job-status');

const job = new AsyncJob(scope, 'process', {
  handler: async (payload, ctx) => {
    await store.put(`job:${ctx.jobId}`, 'processing');
    await doWork(payload);
    await store.put(`job:${ctx.jobId}`, 'complete');
  },
});

Use ctx.jobId for logging:

handler: async (payload, ctx) => {
  console.log(`[${ctx.jobId}] Starting work...`);
  // Your logs will include the job ID for tracing
}

Check the dead-letter queue: Jobs that fail after maxRetries attempts land in the DLQ. In AWS, check the {scope}-{id}-dlq queue in the SQS console. In local dev, failed jobs are logged to the console with their full payload.