1.0.13 • Published 9 months ago

active-queue v1.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
9 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

9 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago