improve: cookie test and activity scan range
This commit is contained in:
@@ -76,25 +76,39 @@ async function clearCookieCache() {
|
||||
async function testCookieValidity(cookieString) {
|
||||
if (!cookieString) return false;
|
||||
logger.debug("Testing cookie validity...");
|
||||
try {
|
||||
const url = 'https://engage.nkcswx.cn/Services/ActivitiesService.asmx/GetActivityDetails';
|
||||
const headers = {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Cookie': cookieString,
|
||||
'User-Agent': 'Mozilla/5.0 (Node.js DSAS-CCA get-activity Module)',
|
||||
};
|
||||
const payload = { "activityID": "3350" };
|
||||
await axios.post(url, payload, { headers, timeout: 10000 });
|
||||
logger.debug("Cookie test successful (API responded 2xx). Cookie is valid.");
|
||||
return true;
|
||||
} catch (error) {
|
||||
logger.warn("Cookie validity test failed.");
|
||||
if (error.response) {
|
||||
logger.warn(`Cookie test API response status: ${error.response.status}. Cookie is likely invalid or expired.`);
|
||||
} else {
|
||||
logger.warn(`Cookie test failed due to network or other error: ${error.message}`);
|
||||
|
||||
const MAX_RETRIES = 3;
|
||||
let attempt = 0;
|
||||
|
||||
while (attempt < MAX_RETRIES) {
|
||||
try {
|
||||
attempt++;
|
||||
const url = 'https://engage.nkcswx.cn/Services/ActivitiesService.asmx/GetActivityDetails';
|
||||
const headers = {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Cookie': cookieString,
|
||||
'User-Agent': 'Mozilla/5.0 (Node.js DSAS-CCA get-activity Module)',
|
||||
};
|
||||
const payload = { "activityID": "3350" };
|
||||
|
||||
logger.debug(`Attempt ${attempt}/${MAX_RETRIES}`);
|
||||
await axios.post(url, payload, { headers, timeout: 20000 });
|
||||
|
||||
logger.debug("Cookie test successful (API responded 2xx). Cookie is valid.");
|
||||
return true;
|
||||
} catch (error) {
|
||||
logger.warn(`Cookie validity test failed (attempt ${attempt}/${MAX_RETRIES}).`);
|
||||
if (error.response) {
|
||||
logger.warn(`Cookie test API response status: ${error.response.status}.`);
|
||||
} else {
|
||||
logger.warn(`Network/other error: ${error.message}`);
|
||||
}
|
||||
|
||||
if (attempt >= MAX_RETRIES) {
|
||||
logger.warn("Max retries reached. Cookie is likely invalid or expired.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ S3_SECRET_ACCESS_KEY=
|
||||
S3_REGION=
|
||||
S3_PUBLIC_URL_PREFIX=files
|
||||
REDIS_URL=redis://:dsas-cca@redis:6379
|
||||
MAX_ACTIVITY_ID_SCAN=9999
|
||||
MIN_ACTIVITY_ID_SCAN=3000
|
||||
MAX_ACTIVITY_ID_SCAN=8000
|
||||
CONCURRENT_API_CALLS=16
|
||||
STAFF_UPDATE_INTERVAL_MINS=360
|
||||
CLUB_UPDATE_INTERVAL_MINS=360
|
||||
|
||||
@@ -20,6 +20,7 @@ dotenv.config();
|
||||
|
||||
const USERNAME = process.env.API_USERNAME;
|
||||
const PASSWORD = process.env.API_PASSWORD;
|
||||
const MIN_ACTIVITY_ID_SCAN = parseInt(process.env.MIN_ACTIVITY_ID_SCAN || '0', 10);
|
||||
const MAX_ACTIVITY_ID_SCAN = parseInt(process.env.MAX_ACTIVITY_ID_SCAN || '9999', 10);
|
||||
const CONCURRENT_API_CALLS = parseInt(process.env.CONCURRENT_API_CALLS || '10', 10);
|
||||
const CLUB_UPDATE_INTERVAL_MINS = parseInt(process.env.CLUB_UPDATE_INTERVAL_MINS || '60', 10);
|
||||
@@ -68,9 +69,9 @@ async function processAndCacheActivity(activityId) {
|
||||
}
|
||||
|
||||
export async function initializeClubCache() {
|
||||
logger.info(`Starting initial club cache population up to ID ${MAX_ACTIVITY_ID_SCAN}...`);
|
||||
logger.info(`Starting initial club cache population from ID ${MAX_ACTIVITY_ID_SCAN} to ${MAX_ACTIVITY_ID_SCAN}`);
|
||||
const promises = [];
|
||||
for (let i = 0; i <= MAX_ACTIVITY_ID_SCAN; i++) {
|
||||
for (let i = MIN_ACTIVITY_ID_SCAN; i <= MAX_ACTIVITY_ID_SCAN; i++) {
|
||||
const activityId = String(i);
|
||||
promises.push(limit(async () => {
|
||||
const cachedData = await getActivityData(activityId);
|
||||
|
||||
Reference in New Issue
Block a user