Skip to content

Latest commit

 

History

History
49 lines (32 loc) · 1.08 KB

README.md

File metadata and controls

49 lines (32 loc) · 1.08 KB

ActiveJobProcessor

Interface for adapters to work with async jobs on node.

Install

npm install @enviabybus/active-job-processor

Adapters

Bull Adapter

Google Cloud Tasks Adapter

Creating a job

// src/jobs/ping.job.ts

class PingJob {
  static perform(message: string): void {
    console.log(message);
  }
}

export default PingJob;

How to use

// src/index.ts

import ActiveJobProcessor, { initActiveJobProcessor } from '@enviabybus/active-job-processor';
import ActiveJobProcessorBullAdapter from '@enviabybus/active-job-processor-bull-adapter';

import PingJob from './jobs/ping.job.ts'

initActiveJobProcessor(path.resolve(__dirname, './jobs'));

const adapter = new ActiveJobProcessorBullAdapter();
const jobProcessor = new ActiveJobProcessor(adapter);

jobProcessor.performLater(PingJob, ['pong']);
jobProcessor.performIn(5000, PingJob, ['pong']);
jobProcessor.performAt(new Date(), PingJob, ['pong']);