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

Fixes #462, Integrate inactive blog url and include logic to filter inactive feeds #639

Merged
merged 25 commits into from
Feb 7, 2020

Conversation

c3ho
Copy link
Contributor

@c3ho c3ho commented Feb 2, 2020

#462

Type of Change

  • Bugfix: Change which fixes an issue
  • New Feature: Change which adds functionality
  • Documentation Update: Change which improves documentation
  • UI: Change which improves UI

Description

As per discussion, removed the inactive-blog-filter.js files (sorry Rafi). Added new functions in storage.js + feed.js to handle invalid feeds. Modified processor.js to use the new functions for the appropriate errors.

Checklist

  • Quality: This PR builds and passes our npm test and works locally
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not (if applicable)
  • Documentation: This PR includes updated/added documentation to user exposed functionality or configuration variables are added/changed or an explanation of why it does not(if applicable)

Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is heading in the right direction. I left some initial comments.

src/backend/utils/storage.js Outdated Show resolved Hide resolved
src/backend/utils/storage.js Outdated Show resolved Hide resolved
src/backend/data/feed.js Outdated Show resolved Hide resolved
src/backend/utils/storage.js Outdated Show resolved Hide resolved
src/backend/data/feed.js Outdated Show resolved Hide resolved
src/backend/feed/processor.js Outdated Show resolved Hide resolved
src/backend/feed/processor.js Outdated Show resolved Hide resolved
@vercel
Copy link

vercel bot commented Feb 4, 2020

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/humphd/telescope/fqsooi59p
✅ Preview: https://telescope-git-fork-c3ho-issue-462.humphd.now.sh

@c3ho
Copy link
Contributor Author

c3ho commented Feb 4, 2020

Still need to work on the logic and the failedReason, fail event has been added and can kind of confirm it is working.

Edit: There is no way to access the failedReason as noted by this issue here

@c3ho
Copy link
Contributor Author

c3ho commented Feb 4, 2020

To test, the stuff for now:

  1. set the .env var FEED_QUEUE_ATTEMPTS to 1 AND inside queue.js set removeOnFail: to removeOnFail: false<--- this prevents failed jobs from disappearing so you can use any of the ids there to test
  2. npm start
  3. check for failed jobs in localhost:(yourPort#Here)/admin/queues in the failed tab
  4. open up a terminal to interact with redis and use the following command
    redis-cli exists t:feed:jobId:invalid jobId being whatever id you see in the failed queue, if it returns 1, its there
    to check the reason why it was invalid use:
    redis-cli get t:feed:jobId:invalid

for example I have a job id #937dda54ec
redis-cli exists t:feed:937dda54ec:invalid should return 1
redis-cli get t:feed:937dda54ec:invalid should also give me a reason.

I set a logger.debug message to display something along the lines of Skipping (job.id) as it is an invalid feed. After the initial run the console should display something like that message pretty often

@c3ho
Copy link
Contributor Author

c3ho commented Feb 4, 2020

Further testing is making it weird, its also saving the posts it can't process as part of the t:feed:**:invalid set to Redis. Not entirely sure how the err is supposed to behave as there's a discrepancy between the bull board failureReason and the reason in redis

src/backend/data/feed.js Outdated Show resolved Hide resolved
src/backend/data/feed.js Show resolved Hide resolved
src/backend/data/feed.js Outdated Show resolved Hide resolved
src/backend/feed/processor.js Outdated Show resolved Hide resolved
@@ -26,7 +26,7 @@ queue.addFeed = async function(feed) {
delay: process.env.FEED_QUEUE_DELAY_MS || 60 * 1000,
},
removeOnComplete: true,
removeOnFail: true,
removeOnFail: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change? Will this still allow the job to be retried?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, enabled that for now just so I can refer to which jobs failed or not and can manually find them in redis

@@ -54,6 +54,10 @@ function processFeeds(feeds) {
const currentFeed = await updateFeed(feed);
// Add a job to the feed queue to process all of this feed's posts.
await feedQueue.addFeed(currentFeed);
// If failed, set the feed to invalid and save to Redis.
feedQueue.on('failed', (job, err) => {
currentFeed.setInvalid(err.message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have a callback in an event handler that is synchronous, and you need to invoke an async function, you need to add a .catch() so a failed Promise doesn't blow things up. Also, you shouldn't hold a reference to the feed in a closure like this. Use the job.data to recreate a new Feed object:

async function invalidateFeed(feedData) {
  const feed = Feed.parse(feedData);
  await feed.setInvalid(feedData.reason || 'unknown reason');
}

feedQueue.on('failed', (job, err) => invalidateFeed(job.data).catch(error => logger.error({ error }, 'Unable to invalidate feed in database.')));

NOTE: we'll need to attach the reason to the job.data before we fail it. I'm not 100% sure where/how to do this without doing it myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried your above code, it does work... just like you said all of them have a value of 'unknown reason'

Another side effect of it being failed, I'm not sure if its a bug. Bull can't differentiate between feeds failing and posts failing, it adds both to Redis

test/storage.test.js Outdated Show resolved Hide resolved
@humphd
Copy link
Contributor

humphd commented Feb 4, 2020

I think you need to rebase to get the code where I fix the posts not failing.

@c3ho
Copy link
Contributor Author

c3ho commented Feb 4, 2020

Nice, that did the trick.
image

Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Amazing how compact this code is now. That's fantastic. A few more things.

src/backend/index.js Show resolved Hide resolved
src/backend/index.js Outdated Show resolved Hide resolved
src/backend/utils/storage.js Show resolved Hide resolved
Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing, and let's take this. Great work.

src/backend/index.js Outdated Show resolved Hide resolved
humphd
humphd previously approved these changes Feb 6, 2020
Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try this, and fix bugs as we go.

@c3ho
Copy link
Contributor Author

c3ho commented Feb 6, 2020

Testing this on windows dev environment, I didn't get all those errors popping up unlike the demo this morning when shutting down the service with ctrl + c

@c3ho c3ho linked an issue Feb 6, 2020 that may be closed by this pull request
@c3ho
Copy link
Contributor Author

c3ho commented Feb 7, 2020

Going to just merge this once it passes CI, since I'm just rebasing stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate inactive blog url and include logic to filter inactive feeds
4 participants