UNPKG

owhat-job

Version:

owhat红包清理

60 lines (58 loc) 2.33 kB
//console.log = function() {}; import V from 'gcl'; import pro from 'myprocesscontroller'; //启动一个进程,内部进行默认属性设置 //this.Config,this.Middler,this.Ni,this.Log pro.start(async function() { const conf = V.AppSettings(this.Config, "jobs"); if (!conf) throw new Error('配置获取失败!'); console.log('deal_jobs', conf); const that = this; that.Temp = this.Middler.getObjectByAppName('Ni', 'MT'); const addMQ = async function(data) { //有相同参数且时间比我小5分钟以内的 不插入 //有相同参数且时间比我早5分钟以内的 更新其执行事件为我的执行 //都没有插入 console.log('addRMQ', data); var res = await that.Temp.excute("add.redis.addschedulemq", { value: V.toJsonString({ Type: data.ope, Params: (data.data || []), }) }); var ret = res.last()[0]; res.clear(); return ret; }; //autoreceipt const job = new class extends pro.ACronJob { constructor() { //cron expression super('autoschedule', conf.autoschedule.cron); } async go(data) { if (!data.Temp) data.Temp = that.Middler.getObjectByAppName('Ni', 'MT'); try { const ret = await data.Temp.excute('Module.admin.autoschedule', { count: 10 }); var datas = []; if (ret.hasData()) { var datas = ret.last()[0]; await V.each(ret.last()[0], async function(v) { await addMQ({ ope: v.Type, data: V.json(v.Params || '[]') }); await data.Temp.excute('Module.admin.finishAutoschedule', { ID: v.ID, ret: 3 }); return false; }); } console.log('autoschedule', datas.length ? (datas.length + '行被更新') : '无数据返回'); } catch (ex) { console.log('autoschedule error', ex.stack); } return false; } }; return new pro.CACProcess(new pro.CronWorker('law-jobs', [job]), this.Log, 1, 100) }); const pri = V.pris();