Commit 3dcd4167 authored by 李尚科's avatar 李尚科

fix

parent 2ac07526
Pipeline #12315 passed with stage
in 5 seconds
......@@ -8,8 +8,8 @@ class HuaYunPaas extends Subscription {
// 通过 schedule 属性来设置定时任务的执行间隔等配置
static get schedule() {
return {
// cron: '0 50 5 * * *',//每天8:50点执行
cron: '*/1 * * * *',//每1分钟执行一次脚本
cron: '0 50 4 * * *',//每天4:50点执行
// cron: '*/1 * * * *',//每1分钟执行一次脚本
type: 'worker',
env: ['prod'],
immediate: false
......@@ -18,28 +18,36 @@ class HuaYunPaas extends Subscription {
// subscribe 是真正定时任务执行时被运行的函数
async subscribe() {
const { ctx, app } = this;
if (['https://dev-nginx.jianbing.com'].includes(this.config.NODE_BASE_URL)) {
if (['https://uat-nginx.jianbing.com'].includes(this.config.NODE_BASE_URL)) {
//用redis的setnx来实现锁机制
let lock = 'huayun:pass:cron:' + moment().format('MMDD');
ctx.logger.info(lock);
ctx.logger.info(JSON.stringify(await app.redis.get(lock)));
let redRes = await app.redis.setnx(lock, 1);
ctx.logger.info('in cron');
await app.redis.expire(lock, 2);
if (Number(redRes) === 1) {
await app.redis.expire(lock, 2);
ctx.logger.info('in redis');
await this.logic();
}
}
}
async logic() {
async logic(){
const { ctx } = this;
ctx.logger.info('in logic');
const accessToken = await this.getAccessToken();
await this.callIn(accessToken);
await this.callOut(accessToken);
}
async callIn(accessToken) {
const { ctx } = this;
ctx.logger.info('in logic');
// const accessToken = await this.getAccessToken();
const url = `http://221.194.132.83:7780/paas/Interface/${accessToken}/CallIn`;
const lastOne = await ctx.prometheusModel.HuayunPaasCallin.findOne({ order: [['id', 'desc']] });
const start = 0;
......@@ -66,6 +74,37 @@ class HuaYunPaas extends Subscription {
}
async callOut(accessToken) {
const { ctx } = this;
ctx.logger.info('in logic');
// const accessToken = await this.getAccessToken();
const url = `http://221.194.132.83:7780/paas/Interface/${accessToken}/CallOut`;
const lastOne = await ctx.prometheusModel.HuayunPaasCallOut.findOne({ order: [['id', 'desc']] });
const start = 0;
const limit = 10000;
let start_time = moment().add(-1, 'days').format('YYYY-MM-DD HH:mm:ss');
const now_time = moment().format('YYYY-MM-DD HH:mm:ss');
if (lastOne && lastOne.end_time) {
start_time = lastOne.end_time;
}
ctx.logger.info(JSON.stringify({ start_time, now_time, start, limit }));
const result = await ctx.curl(url, { method: 'POST', contentType: 'json', dataType: 'json', timing: true, timeout: 300000, data: { start_time, end_time: now_time, start, limit } });
const ret = result.data;
// ctx.logger.info(JSON.stringify({ ret }));
ctx.logger.info('get result');
if (ret.status != 0 || !ret.message || ret.count == 0) {
return;
}
ctx.logger.info('in add');
const message = ret.message;
const list = message.data;
ctx.logger.info(message.count);
const insert_data = await this.format(list);
await ctx.prometheusModel.HuayunPaasCallOut.bulkCreate(insert_data, { ignoreDuplicates: true });
}
async getAccessToken() {
const { ctx } = this;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment