
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
bc-schedule-server
Advanced tools
将整体的koa服务、常规中间件,以及xxlJob所需api服务等处理逻辑封装在内部。对外暴koa实例、router实例及定时任务注册函数和logger函数。
import { BcScheduleServer } form 'bc-schedule-server'const { BcScheduleServer } require('bc-schedule-server')import { BcScheduleServer } form 'bc-schedule-server'
const schedule = new BcScheduleServer({
port: 9501,
scheduleCenterUrl: 'https://xxljob.xxx.com'
})
/**
* 注册待调用的定时任务
* 注意:不能是 ()=>{} 和 function(){} 方式
*/
const fn = (logger: ExposeLogger) => {
logger.info('# hahah')
// 返回的信息可在“执行备注”中查看
return 'change rows: 3'
}
const registered = schedule.registerTask([
fn,
function fn2(logger, xxlJobParams) {
logger.info('balabal')
},
async function fn3(logger, xxlJobParams) {},
])
// 返回已经注册的任务函数列表
console.log(registered) // [ 'fn', 'fn2', 'fn3' ]
// info:balabala
logger.info('balabala')
// info:{"extra":"","msg":"test info","other":1}
logger.info({ msg: 'test info', other: 1 })
// info:[1,2,3]
logger.info([1, 2, 3])
// info:"number -- 123"
logger.info(`number -- %d`, 123)
// info:"json -- {\"test\":\"balabala\"}"
logger.info(`json -- %j`, { test: 'balabala' })
// info:"string and object to string { a: 1 } And { b: 2 }"
logger.info('string and object to string %s And %s', { a: 1 }, { b: 2 })
// info:"more info abc | other text"
logger.info(`more info %s | %s`, 'abc', 'other text', 'more...')
// BcScheduleServer 配置
{
port: number, // 服务监听端口
scheduleCenterUrl: string, // xxl-job 任务执行后的回调域名
localLog?: {
opLog: boolean, // 是否启动访问日志输出
logPath: string // log日志文件目录
}
route?: string, // api 地址前缀
koaOptions?: any // new Koa() 本身对应的参数
}
// registerTask 配置
schedule.registerTask([...tasks], {
excludeJobId: true | string[] // 配置 true 所有任务都不加执行限制;string[] 只对配置了的任务明跳过限制
})
// 基本使用方式
import { BcScheduleServer } form 'bc-schedule-server'
const schedule = new BcScheduleServer({
port: 9501,
scheduleCenterUrl: 'https://xxljob.xxx.com'
})
// 注册待调用的定时任务
schedule.registerTask([
function fn1(logger, xxlJobParams) {
logger.info('balabal')
// logger 支持对象形式
logger.info({msg: 'heihei', params: {a:1, b:2}})
},
async function fn2(logger, xxlJobParams) {},
])
{
"jobId": 1, // 任务 id
"executorHandler": "test", // 当前待执行的任务名称
"executorParams": "{\"code\": 400, \"msg\": \"123\"}", // 执行时传递的参数
"executorBlockStrategy": "SERIAL_EXECUTION",
"executorTimeout": 0, // 超时时间
"logId": 1, // 日志 id
"logDateTime": 1679283887584, // 日志时间戳
"glueType": "BEAN", // 任务模式
"glueSource": "",
"glueUpdatetime": 1679283187000,
"broadcastIndex": 0,
"broadcastTotal": 1
}
{
"logDateTim": 1680925146000,
"logId": 1,
"fromLineNum": 1
}
FAQs
xxl-job koa server
We found that bc-schedule-server demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.