tbs-cron-queue
v0.1.6
Published
Package for handling cron job queue issue. Will queueing every cron job added with redis distribution between pods. <br><br> ___Note: This package will running on 5s interval on background to check and pick the queue. Also every cron will be run with inte
Downloads
57
Readme
TBS Cron Job Queue Service
Package for handling cron job queue issue. Will queueing every cron job added with redis distribution between pods. Note: This package will running on 5s interval on background to check and pick the queue. Also every cron will be run with internal api call with axios. So remind that your cron job API with block API mechanism
Installation
Yarn
yarn add tbs-cron-queue tbs-site-config global-body-validator-tbs
NPM
npm install tbs-cron-queue tbs-site-config global-body-validator-tbs
Getting Started
For initializing package you need to write in 2 file
app.module.ts
import { TbsCronQueueModule } from 'tbs-cron-queue';
@Module({
imports: [
TbsCronQueueModule.register({
options: {
port: +process.env.REDIS_PORT,
host: process.env.REDIS_HOST
},
prefix: process.env.CRON_JOB_QUEUE_PREFIX,
baseUrl: process.env.CRON_JOB_BASE_URL,
site_config_prefix: process.env.KAFKA_TOPIC_PREFIX,
})
],
controllers: [],
providers: [],
})
export class ExampleModule {}
Adding Cron Job
After initialize this module on your app.module, you can see the controller below on swagger with tags name Queue Worker. Just redirect your cron job url to this controller.
How Package Works
In package controller will have 4 API, with detail:
add-queue
=> will add your cron job to redis queueclean-queue
=> will remove all redis queuesingle-queue
=> will remove single cron job data from redis queuehealth-check
=> will return 200 when there's no queue running on pods and 403 when any queue is running on pods
How the add queue works ?
add-queue
will check in redis queue, is that cron job url and method is registered unleash on processing queue or waiting queue. When that cron is in that state, so cron will be rejected, and vice versa when cron is not in any state then will be inserted to waiting queue.
How the clean queue works ?
clean-queue
will remove all of processing queue and waiting queue
How the single queue works ?
single-queue
will remove a single cron from processing queue and waiting queue based on http method and url target combination you gave
How health check works ?
health-check
will check is this pods is running any queue or not. When the pods running any queue then response will be 403 and cant receive any traffic, vice versa will return response 200. So we recommend that your liveness probe and rediness probe of your kubernetes is directed here.