0.0.1 • Published 3 years ago

@enviabybus/active-job-processor v0.0.1

Weekly downloads
48
License
MIT
Repository
github
Last release
3 years ago

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']);