parent
1c05df8537
commit
2c8c3a09e5
@ -0,0 +1,28 @@
|
||||
import * as schedule from 'node-schedule'
|
||||
import { Interface } from '../models'
|
||||
import { Op } from 'sequelize'
|
||||
import { DATE_CONST } from '../routes/utils/const'
|
||||
|
||||
export async function startTask() {
|
||||
|
||||
console.log(`Starting task: locker check`)
|
||||
|
||||
/**
|
||||
* 每5分钟检查lock超时
|
||||
*/
|
||||
schedule.scheduleJob('*/5 * * * *', async () => {
|
||||
// tslint:disable-next-line: no-null-keyword
|
||||
const [num] = await Interface.update({ lockerId: null }, {
|
||||
where: {
|
||||
lockerId: {
|
||||
[Op.gt]: 0,
|
||||
},
|
||||
updatedAt: {
|
||||
[Op.lt]: new Date(Date.now() - DATE_CONST.DAY),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
num > 0 && console.log(`cleared ${num} locks`)
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue