Skip to content

Commit

Permalink
almost completed
Browse files Browse the repository at this point in the history
  • Loading branch information
c3ho committed Dec 2, 2019
1 parent ed365b8 commit 8747a68
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/backend/feed/worker.js
@@ -1,7 +1,8 @@
const feedQueue = require('./queue');
const feedParser = require('./parser');
const extractUrls = require('../utils/extract-urls');
const logger = require('./../utils/logger');
const storage = require('../utils/storage');
// const logger = require('./../utils/logger');

exports.workerCallback = async function(job) {
const { url } = job.data;
Expand All @@ -23,11 +24,8 @@ exports.workerCallback = async function(job) {
});
return processedPosts;
}
<<<<<<< HEAD
return processedPosts;
=======
// return processedPosts;
>>>>>>> still working
} catch (err) {
return err;
}
Expand All @@ -36,8 +34,15 @@ exports.workerCallback = async function(job) {
// eslint-disable-next-line prettier/prettier
exports.start = function() {
// Start processing jobs from the feed queue...
feedQueue.process(this.workerCallback);
feedQueue.on('completed', (job, result) => {
console.log(`Job ${job.id} completed! Result: ${result.processedPosts[0].author}`);
feedQueue.process(exports.workerCallback);
feedQueue.on('completed', (job, results) => {
if (results.length > 0) {
results.forEach(result => {
console.log(`Result: ${result.title}`);
// We have an issure here, addPost is an async function. Should we make the start
// function an async one too..?
storage.addPost(result);
});
}
});
};

0 comments on commit 8747a68

Please sign in to comment.