拍卖行:定时任务加锁
This commit is contained in:
@@ -15,6 +15,8 @@ import { RewardInter } from '../pubUtils/interface';
|
||||
import { reportTAEvent } from './sdkService';
|
||||
import { getAllServers } from './redisService';
|
||||
import { sendMessageToGuildWithSuc, sendMessageToServer, sendMessageToServerWithSuc } from './pushService';
|
||||
import { lockDataWithNoParam } from './redLockService';
|
||||
import { DATA_NAME } from '../consts';
|
||||
|
||||
// ! 获取底价,假数据
|
||||
export function getBasePrice(gid: number, count: number) {
|
||||
@@ -290,6 +292,9 @@ export async function calculateDividend(dividend: DividendType) {
|
||||
}
|
||||
|
||||
export async function startGuildAuction() {
|
||||
let res: any = await lockDataWithNoParam(DATA_NAME.SEND_AUCTION);//加锁
|
||||
if (!!res.err) return false;
|
||||
|
||||
try {
|
||||
console.log('schedule startGuildAuction called:', new Date());
|
||||
const begin = await todayGuildBegin();
|
||||
@@ -304,10 +309,11 @@ export async function startGuildAuction() {
|
||||
}
|
||||
|
||||
await pushAuctionUpdate(lots, dividends);
|
||||
|
||||
res.releaseCallback();
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error('startGuildAuction err: ', e);
|
||||
res.releaseCallback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -330,6 +336,8 @@ export async function sendLotsRewardToMlail(lots: LotType[]) {
|
||||
}
|
||||
|
||||
export async function startWorldAuction() {
|
||||
let res: any = await lockDataWithNoParam(DATA_NAME.SEND_AUCTION);//加锁
|
||||
if (!!res.err) return false;
|
||||
try {
|
||||
console.log('schedule startWorldAuction called:', new Date());
|
||||
const begin = await todayGuildBegin();
|
||||
@@ -345,14 +353,18 @@ export async function startWorldAuction() {
|
||||
await pushCurrentTime(time);
|
||||
}
|
||||
await pushAuctionUpdate(lots, dividends);
|
||||
res.releaseCallback();
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error('startWorldAuction err: ', e);
|
||||
res.releaseCallback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function stopAuction() {
|
||||
let res: any = await lockDataWithNoParam(DATA_NAME.SEND_AUCTION);//加锁
|
||||
if (!!res.err) return false;
|
||||
try {
|
||||
console.log('schedule stopAuction called:', new Date());
|
||||
const begin = await todayGuildBegin();
|
||||
@@ -367,9 +379,11 @@ export async function stopAuction() {
|
||||
await pushCurrentTime(time);
|
||||
}
|
||||
await pushAuctionUpdate(lots, []);
|
||||
res.releaseCallback();
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error('stopAuction err: ', e);
|
||||
res.releaseCallback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ export async function getModuleData(type: string, data: { role: RoleType, sessio
|
||||
case 'daily': // 每日
|
||||
return await getDailyBattleList(role);
|
||||
case 'expedition': // 远征
|
||||
return await getExpeditionStatus(roleId, roleName);
|
||||
return await getExpeditionStatus(roleId, roleName, true);
|
||||
case 'tower': // 镇念塔
|
||||
return await getTowerEntryData(role);
|
||||
case 'comBattle': // 寻宝
|
||||
|
||||
@@ -18,10 +18,11 @@ import { checkSystemIsOpen } from './roleService';
|
||||
* @param roleId
|
||||
* @param roleName
|
||||
*/
|
||||
export async function getExpeditionStatus(roleId: string, roleName: string) {
|
||||
export async function getExpeditionStatus(roleId: string, roleName: string, isEntry = false) {
|
||||
// 重置次数
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if(!checkSystemIsOpen(role, SYSTEM_OPEN_ID.EXPEDITION)) return false
|
||||
if(!role.hasInit) return false;
|
||||
if(isEntry && !checkSystemIsOpen(role, SYSTEM_OPEN_ID.EXPEDITION)) return false
|
||||
// 获取远征关卡状态
|
||||
let expeditionRecord = await ExpeditionRecordModel.getCurRecord(roleId);
|
||||
if (!expeditionRecord) { // 首次新建一条记录
|
||||
|
||||
@@ -68,6 +68,11 @@ export async function lockData(serverId: number, dataName: string, id: string )
|
||||
return await lock(lockKey);
|
||||
}
|
||||
|
||||
export async function lockDataWithNoParam(dataName: string) {
|
||||
let key = `${dataName}`;
|
||||
return await lock(key);
|
||||
}
|
||||
|
||||
function lock(lockKey: string) {
|
||||
return _redlockCache.redlock.lock(lockKey, _redlockCache.ttl).then(function(lock) {
|
||||
setLock(lockKey, lock);
|
||||
|
||||
Reference in New Issue
Block a user