Skip to content

Commit

Permalink
fix(crawler): handle null max price
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Dec 6, 2022
1 parent 31e9688 commit b34689e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions crawler/src/crawl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ export async function crawlAllJobs(): Promise<void> {
const jobList = await storage.getAll();
for (const jobId in jobList) {
if (!Object.prototype.hasOwnProperty.call(jobList, jobId)) continue;
const job = jobList[jobId];
const oldResultList = job.resultList;
const resultList = await crawl(job.detail);
job.resultList = resultList;
if (differentObject(resultList, oldResultList)) {
const message = makeMessage(job);
try {
try {
const job = jobList[jobId];
const oldResultList = job.resultList;
const resultList = await crawl(job.detail);
job.resultList = resultList;
if (differentObject(resultList, oldResultList)) {
const message = makeMessage(job);
await notify(config.notifier.to, message);
logger.logOther(`Notified to ${config.notifier.to}!`);
}
catch (err) {
logger.error('crawlAllJobs', 'notify_failed', (err as Error).stack || err);
}
await storage.set(job);
}
catch (err) {
logger.error('crawlAllJobs', 's', (err as Error).stack);
}
await storage.set(job);
}
}

Expand Down Expand Up @@ -97,8 +97,9 @@ function extraFilterResult(jobResultList: Array<JobResult>, detail: JobDetail):
let filteredJobResultList: Array<JobResult> = jobResultList;

if (detail.maxPrice != null) {
const maxPrice = detail.maxPrice;
filteredJobResultList = filteredJobResultList.filter((job) => {
return job.price >= detail.maxPrice;
return job.price >= maxPrice;
});
}

Expand Down

0 comments on commit b34689e

Please sign in to comment.