0.1.5 • Published 2 months ago

tbs-cron-queue v0.1.5

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
2 months ago

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: 1. add-queue => will add your cron job to redis queue 2. clean-queue => will remove all redis queue 3. single-queue => will remove single cron job data from redis queue 4. health-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.

0.1.2

2 months ago

0.1.4

2 months ago

0.1.3

2 months ago

0.1.5

2 months ago

0.0.12

2 months ago

0.1.0

5 months ago

0.0.10

6 months ago

0.0.11

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago