Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(uniquely/flight-crawler): prevent set storage repeated #536

Merged
merged 4 commits into from
Dec 22, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions services/flight-crawler/src/crawl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,29 @@ import type {FetchOptions} from '@alwatr/fetch';
export async function crawlAllJobs(): Promise<void> {
logger.logMethod('crawlAllJobs');
const jobList = (await storageClient.getStorage()).data;
for (const jobId in jobList) {
if (!Object.prototype.hasOwnProperty.call(jobList, jobId)) continue;
const jobKeyList = Object.keys(jobList);
let updated = false;

for (let i = 0; i < jobKeyList.length; i++) {
try {
const job = jobList[jobId];
const job = jobList[jobKeyList[i]];
const oldResultList = job.resultList;
const resultList = await crawl(job.detail);
job.resultList = resultList;
if (differentObject(job.resultList, oldResultList)) {
const message = makeMessage(job);
await notify(config.notifier.to, message);
logger.logOther(`Notified to ${config.notifier.to}!`);
await storageClient.set(job);
updated = true;
}
await storageClient.set(job);
}
catch (err) {
logger.error('crawlAllJobs', 'crawling_failed', err);
}
}
// for updating meta
if (updated === false) await storageClient.set(jobList[jobKeyList[jobKeyList.length - 1]]);
}

async function crawl(detail: JobDetail): Promise<Array<JobResult>> {
Expand Down