Skip to content

ikexing-cn/xxl-job-nodejs

Repository files navigation

XXL-JOB-NODEJS

NPM version

Provide xxl-job SDK for NodeJs.

TODO

  • Example
  • Complete basic functions
  • Koa support [low-priority]

Features

  • Job Execution
  • Log Query & Saved
  • Typescript Support
  • Express Integration
  • Run Request Params Support(broad cast…)

Install

npm install xxl-job

Usage

import express from 'express'
import type { JobHandler } from 'xxl-job'
import { createXxlJobExecutor } from 'xxl-job'

const jobHandlers = new Map<string, JobHandler>()
jobHandlers.set('nodejs_test', async (jobLogger, jobRequest, jobParams) => {
  jobLogger.warn(`request: ${JSON.stringify(jobRequest)}, params: ${jobParams}`)
})

const app = express()
app.use(express.json())

app.listen(8081, () => {
  const xxlJobExecutor = createXxlJobExecutor({
    app,
    jobHandlers,
    appType: 'express',
    accessToken: 'default_token',
    baseUrl: 'https://127.0.0.1:8081', // Server address
    executorKey: 'executor-nodejs-express',
    scheduleCenterUrl: 'https://127.0.0.1:8080/xxl-job-admin', // xxl-job address
  })
  xxlJobExecutor.initialization()
})

See the example folder for details

License

MIT License © 2022 KeXing

Code Reference

xxl-job-executor-nodejs