fix 每日定时器只执行1次
This commit is contained in:
parent
a9a5193efe
commit
85dc5e02ff
@ -211,7 +211,8 @@ export function addListener() {
|
||||
|
||||
// 签到增加天数
|
||||
SignFun.updateLogin(gud.uid);
|
||||
ActionLog.initDayLog(gud.uid);
|
||||
//移到定时器里统一执行
|
||||
//ActionLog.initDayLog(gud.uid);
|
||||
ActionLog.addRetainLog(gud.uid, { key: 'login_day', val: 1 });
|
||||
ZhanLingTasks.clearLog(gud.uid, 'day');
|
||||
PayFun.checkGiftDayEmail(gud, lastTime, curTime);
|
||||
|
@ -1,9 +1,33 @@
|
||||
import { PublicShared } from "../../shared/public/public";
|
||||
|
||||
|
||||
export class ActionLog {
|
||||
static async initDayLog(uid: string) {
|
||||
G.mongodb.cActionLog('day').updateOne({ uid: uid, type: 'day' }, { $set: { log: {} } }, { upsert: true });
|
||||
/**
|
||||
* 每天0点的时候,重置所有的统计数据
|
||||
*/
|
||||
static async initAllDayLog() {
|
||||
await G.mongodb.cActionLog('day').updateMany({type: 'day' }, {
|
||||
$set: {
|
||||
log: {},
|
||||
//增加刷新时间
|
||||
lastTime: PublicShared.getToDayZeroTime(G.time)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置某个玩家的统计信息
|
||||
* @param uid
|
||||
*/
|
||||
// static async initDayLog(uid: string) {
|
||||
// G.mongodb.cActionLog('day').updateOne({ uid: uid, type: 'day' }, {
|
||||
// $set: {
|
||||
// log: {},
|
||||
// //增加刷新时间
|
||||
// lastTime: PublicShared.getToDayZeroTime(G.time)
|
||||
// }
|
||||
// }, { upsert: true });
|
||||
// }
|
||||
static async addDayLog(uid: string, ...args: { key: string, val: number; }[]) {
|
||||
const addObj = G.mongodb.createTreeObj(...args.map(a => { return { key: 'log', k: a.key, val: a.val }; }));
|
||||
G.mongodb.cActionLog('day').updateOne({ uid: uid, type: 'day' }, { $inc: addObj });
|
||||
|
@ -4,11 +4,14 @@ import { Wjjl } from "../../module/collection_wjjl";
|
||||
import { ZhanLingTasks } from "../zhanling";
|
||||
import { setGud } from '../gud';
|
||||
import { EmailFun } from '../email';
|
||||
import { ActionLog } from '../actionLog/actionLog';
|
||||
import { clusterFun } from '../../clusterFunction';
|
||||
import { clusterRunOnce } from '../../clusterUtils';
|
||||
|
||||
|
||||
export class SchedulerNewDayLocalCtor extends Scheduler {
|
||||
id: schedulerType = 'newDay_local_ctor';
|
||||
time = 0;
|
||||
time = 1;
|
||||
name = '定时推送跨天通知';
|
||||
type: 'day' | 'week' = 'day';
|
||||
|
||||
@ -23,6 +26,41 @@ export class SchedulerNewDayLocalCtor extends Scheduler {
|
||||
}
|
||||
|
||||
async start() {
|
||||
|
||||
clusterRunOnce(async ()=>{
|
||||
//这个定时器会被每个进程都启动,这是这部分逻辑,应该只执行1次
|
||||
|
||||
//重置所有的ActionLog
|
||||
await ActionLog.initAllDayLog();
|
||||
|
||||
// 每周一,发放终身卡
|
||||
(async () => {
|
||||
if (PublicShared.getWeek(G.time) == 1) {
|
||||
let logs = await G.mongodb.collection("payLogNew").find(
|
||||
{ key: "zhongshenka", del_time: { $exists: false } }, { projection: { _id: 0, } }
|
||||
).toArray();
|
||||
|
||||
if (logs.length == 0) {
|
||||
console.log("没有终身卡数据,不发放终身卡");
|
||||
}
|
||||
let con = G.gc.payEmail.zhongshenka.filter(e => e.day == 7)[0];
|
||||
for (let i = 0; i < logs.length; i++) {
|
||||
console.log("发放终身卡", logs[i].uid);
|
||||
// 发送邮件
|
||||
EmailFun.addEmail({
|
||||
uid: logs[i].uid,
|
||||
type: "system",
|
||||
title: con.title,
|
||||
content: con.content,
|
||||
contentInsertArr: [],
|
||||
createTime: G.time,
|
||||
prize:con.prize,
|
||||
})
|
||||
}
|
||||
}
|
||||
})()
|
||||
})
|
||||
|
||||
let users = Object.values(G.server.uid_connections)
|
||||
if (users.length) {
|
||||
for (let item of users) {
|
||||
@ -56,34 +94,6 @@ export class SchedulerNewDayLocalCtor extends Scheduler {
|
||||
G.server.broadcastClusterMsg('msg_s2c/NewDay', { time: this.zeroTime });
|
||||
}
|
||||
|
||||
(async () => {
|
||||
// 每周一,发放终身卡
|
||||
if (PublicShared.getWeek(G.time) != 1) {
|
||||
console.log("不是周一,不发放终身卡", PublicShared.getWeek(G.time));
|
||||
return
|
||||
};
|
||||
|
||||
let logs = await G.mongodb.collection("payLogNew").find(
|
||||
{ key: "zhongshenka", del_time: { $exists: false } }, { projection: { _id: 0, } }
|
||||
).toArray();
|
||||
|
||||
if (logs.length == 0) {
|
||||
console.log("没有终身卡数据,不发放终身卡");
|
||||
}
|
||||
let con = G.gc.payEmail.zhongshenka.filter(e => e.day == 7)[0];
|
||||
for (let i = 0; i < logs.length; i++) {
|
||||
console.log("发放终身卡", logs[i].uid);
|
||||
// 发送邮件
|
||||
EmailFun.addEmail({
|
||||
uid: logs[i].uid,
|
||||
type: "system",
|
||||
title: con.title,
|
||||
content: con.content,
|
||||
contentInsertArr: [],
|
||||
createTime: G.time,
|
||||
prize:con.prize,
|
||||
})
|
||||
}
|
||||
})()
|
||||
await this.record();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user