1.0.13 • Published 7 months ago

active-queue v1.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Active Queue

Simple TypeScript-based task queue inspired by tRPC, Active Job and Sidekiq.

GitHub Tag GitHub Actions Workflow Status

Setup

1. Start redis & postgresql

2. Adjust your drizzle schema

export * from 'active-queue/schema'

And then

yarn drizzle-kit generate & yarn drizzle-kit migrate

3. Define your jobs

src/queue.config.ts:

export { makeQueue } from 'active-queue'

export const queue = makeQueue({
  namespace: 'test-queue',

  factories: {
    redis: _ => new Redis(),
    pg: _ => new Pool({
      connectionString: process.env.DATABASE_URL!
    }),
    sentry: _ => sentry, // you can also use sentryStub if you don't want this 
  },

  settings: {
    polling_interval: duration(10, 'second'),
    load_window: duration(3, 'seconds'),
    retry: { // or 'disabled'
      step: duration(2, 'seconds'),
      max_attempts: 30
    },
  },

  jobs: {
    async ok() {
      console.warn('* running ok *'.repeat(10))
    },

    async hmmm() {
      console.warn('* running hmmm() *'.repeat(10))      
    }

    /// ...
  }
})

4. Setup & start queue process

src/queue.start.ts:

import { queue } from "./queue.config";

void queue.start()

and

yarn tsx src/queue.start.ts

5. Use your jobs

import { queue } from "@/queue.config";

/// ... 

await queue.later().ok()
/// or 
await queue.in(duration(10, 'minutes')).ok()

// or for direct call without running in other process and for easier debugging
await queue.now().ok()
/// ...
1.0.13

7 months ago

1.0.12

7 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago