From ee97a111507b0b2f3be50f8ffbe1056a511ace12 Mon Sep 17 00:00:00 2001 From: Guillaume Malette Date: Fri, 26 Feb 2021 11:36:22 -0500 Subject: [PATCH] refactor: use logstream notification for in_stock logging too --- src/notification/link_poll_event.ts | 2 +- src/notification/logstream.ts | 4 +++- src/store/lookup.ts | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/notification/link_poll_event.ts b/src/notification/link_poll_event.ts index a6bfc04087..2f0c32b68c 100644 --- a/src/notification/link_poll_event.ts +++ b/src/notification/link_poll_event.ts @@ -15,7 +15,7 @@ type LinkPollError = {result: 'failure'} & ( | OutOfStock | BannedSeller ); -type LinkPollSuccess = {result: 'in_stock'}; +type LinkPollSuccess = {result: 'in_stock'; url: string}; export type LinkPollEvent = (LinkPollError | LinkPollSuccess) & { link: Link; diff --git a/src/notification/logstream.ts b/src/notification/logstream.ts index 529e15f12f..74bb599cb8 100644 --- a/src/notification/logstream.ts +++ b/src/notification/logstream.ts @@ -7,7 +7,9 @@ function assertNever(x: never): never { export function sendLogstream(pollEvent: LinkPollEvent) { const {link, store} = pollEvent; - if (pollEvent.result === 'failure') { + if (pollEvent.result === 'in_stock') { + logger.info(`${Print.inStock(link, store, true)}\n${pollEvent.url}`); + } else { switch (pollEvent.failureReason) { case 'captcha': logger.warn(Print.captcha(link, store, true)); diff --git a/src/store/lookup.ts b/src/store/lookup.ts index 5efe6f0dc5..3efc591c5b 100644 --- a/src/store/lookup.ts +++ b/src/store/lookup.ts @@ -23,7 +23,7 @@ import {filterStoreLink} from './filter'; import open from 'open'; import {processBackoffDelay} from './model/helpers/backoff'; import useProxy from '@doridian/puppeteer-page-proxy'; -import {LinkPollEvent} from "../notification/link_poll_event"; +import {LinkPollEvent} from '../notification/link_poll_event'; const inStock: Record = {}; @@ -331,7 +331,6 @@ async function lookupCard( if (await lookupCardInStock(store, page, link, sendNotification)) { const givenUrl = link.cartUrl && config.store.autoAddToCart ? link.cartUrl : link.url; - logger.info(`${Print.inStock(link, store, true)}\n${givenUrl}`); if (config.browser.open) { await (link.openCartAction === undefined @@ -341,6 +340,7 @@ async function lookupCard( sendNotification({ result: 'in_stock', + url: givenUrl, link, store, });