-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: Refactor notifications and make them injectable #2034
Conversation
sendLogstream and link_poll_event have been moved to their respective files
getSleepTime(store), | ||
browser, | ||
store, | ||
sendNotification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the main
function we inject the existing sendNotification
function
export type LinkPollEvent = (LinkPollError | LinkPollSuccess) & { | ||
link: Link; | ||
store: Store; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LinkPollEvent
could be made shorter but I liked to express it in a way that prevents representing illegal states.
I wasn't sure if events should be provided for cloudflare
, tryLookupAndLoop
caught errors, inStockWaiting
, lookupCard
caught errors, NoResponse
, RateLimit
, etc.
assertNever(pollEvent); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the logging w.r.t polling had been moved here. Some logging still happends in lookup.ts
but looked ancillary, except for what's mentioned in the comments on notifications
.
async function lookup( | ||
browser: Browser, | ||
store: Store, | ||
sendNotification: SendNotification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the added code in this file is passing the sendNotification
to the functions that need it.
The rest is sending notifications in lieu of logging
logger.info(Print.maxPrice(link, store, pollEvent.maxPrice, true)); | ||
return; | ||
case 'request_failed': | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this case logs too but I haven't found where it happens.
ee97a11
to
dde6c7e
Compare
I'll be looking at this and #2038 very shortly. I appreciate your contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I'm not 100% certain if folks want emails and such everytime captcha, out of stock, and etc show up.
I do understand the concept, but I'm not certain if we want this behavior.
That being said, if you make it configurable, I'll be more than happy to pull it in!
src/notification/notification.ts
Outdated
const {link, store} = pollEvent; | ||
if (pollEvent.result === 'failure') { | ||
switch (pollEvent.failureReason) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const {link, store} = pollEvent; | |
if (pollEvent.result === 'failure') { | |
switch (pollEvent.failureReason) { | |
const {failureReason, link, result, store} = pollEvent; | |
if (result === 'failure') { | |
switch (failureReason) { |
Might as well yank these out as well.
@jef I'm not sure I understand what kind of changes you're asking for. The default injected |
@jef can you clarify what you were looking for me to change? |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days |
Sorry for the late response @gmalette, this have been pretty busy on my end. Let me take another look at this shortly and we can get this in. |
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days |
This issue has been closed because it is stale. Reopen if necessary. |
Description
First I think it's worth giving context to what my goal is. I would like to create a program that wraps streetmerchant and offers another dashboard. I would like for it to run in the same process and avoid adding infrastructure if at all possible.
This PR refactors the notifications to make both failures and success notifications. It also makes the notification function injectable, but the
main
function uses the existing one.I also refactored to make the logging of failures as part of normal notifications. This isn't strictly necessary but I thought it was nice to harmonize both and show that logging is just one way to handle poll events.
This PR, along with https://github.com/jef/streetmerchant/compare/main...gmalette:gm/packaging?expand=1, allow me to use streetmerchant and inject notification handling.
Testing
Ran the program, worked as normal for "out of stock" and other errors.
I was not able to test for "in stock" items.