JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q31511F
  • License MIT

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (active-queue) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Active Queue

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

    GitHub Tag NPM Downloads 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()
    /// ...