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

Fix bug in worker.js #118

Merged
merged 2 commits into from Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 11 additions & 10 deletions 6-pubsub/worker.js
Expand Up @@ -68,9 +68,9 @@ function subscribe () {
if (err) {
throw err;
}
if (message.action === 'processBook') {
logging.info(`Received request to process book ${message.bookId}`);
processBook(message.bookId);
if (message.data.action === 'processBook') {
logging.info(`Received request to process book ${message.data.bookId}`);
processBook(message.data.bookId);
} else {
logging.warn('Unknown request', message);
}
Expand All @@ -87,9 +87,6 @@ if (module === require.main) {
// more information, and updating the database with the new information.
// [START process]
function processBook (bookId, callback) {
if (!callback) {
callback = logging.error;
}
waterfall([
// Load the current data
(cb) => {
Expand All @@ -104,12 +101,16 @@ function processBook (bookId, callback) {
], (err) => {
if (err) {
logging.error('Error occurred', err);
callback(err);
if (callback) {
callback(err);
}
return;
}
logging.info(`Updated book ${bookId}`);
bookCount += 1;
callback();
if (callback) {
callback();
}
});
}
// [END process]
Expand Down Expand Up @@ -180,7 +181,7 @@ app.mocks = {
processBook: processBook,
findBookInfo: findBookInfo,
queryBooksApi: queryBooksApi
}
};

// Proxyquire requires this *exact* line, hence the "app.mocks" above
module.exports = app
module.exports = app;
21 changes: 11 additions & 10 deletions 7-gce/worker.js
Expand Up @@ -58,9 +58,9 @@ function subscribe () {
if (err) {
throw err;
}
if (message.action === 'processBook') {
logging.info(`Received request to process book ${message.bookId}`);
processBook(message.bookId);
if (message.data.action === 'processBook') {
logging.info(`Received request to process book ${message.data.bookId}`);
processBook(message.data.bookId);
} else {
logging.warn('Unknown request', message);
}
Expand All @@ -78,9 +78,6 @@ if (module === require.main) {
// Processes a book by reading its existing data, attempting to find
// more information, and updating the database with the new information.
function processBook (bookId, callback) {
if (!callback) {
callback = logging.error;
}
waterfall([
// Load the current data
(cb) => {
Expand All @@ -95,12 +92,16 @@ function processBook (bookId, callback) {
], (err) => {
if (err) {
logging.error('Error occurred', err);
callback(err);
if (callback) {
callback(err);
}
return;
}
logging.info(`Updated book ${bookId}`);
bookCount += 1;
callback();
if (callback) {
callback();
}
});
}

Expand Down Expand Up @@ -165,7 +166,7 @@ app.mocks = {
processBook: processBook,
findBookInfo: findBookInfo,
queryBooksApi: queryBooksApi
}
};

// Proxyquire requires this *exact* line, hence the "app.mocks" above
module.exports = app
module.exports = app;
21 changes: 11 additions & 10 deletions optional-container-engine/worker.js
Expand Up @@ -58,9 +58,9 @@ function subscribe () {
if (err) {
throw err;
}
if (message.action === 'processBook') {
logging.info(`Received request to process book ${message.bookId}`);
processBook(message.bookId);
if (message.data.action === 'processBook') {
logging.info(`Received request to process book ${message.data.bookId}`);
processBook(message.data.bookId);
} else {
logging.warn('Unknown request', message);
}
Expand All @@ -78,9 +78,6 @@ if (module === require.main) {
// Processes a book by reading its existing data, attempting to find
// more information, and updating the database with the new information.
function processBook (bookId, callback) {
if (!callback) {
callback = logging.error;
}
waterfall([
// Load the current data
(cb) => {
Expand All @@ -95,12 +92,16 @@ function processBook (bookId, callback) {
], (err) => {
if (err) {
logging.error(`Error occurred`, err);
callback(err);
if (callback) {
callback(err);
}
return;
}
logging.info(`Updated book ${bookId}`);
bookCount += 1;
callback();
if (callback) {
callback();
}
});
}

Expand Down Expand Up @@ -164,7 +165,7 @@ app.mocks = {
processBook: processBook,
findBookInfo: findBookInfo,
queryBooksApi: queryBooksApi
}
};

// Proxyquire requires this *exact* line, hence the "app.mocks" above
module.exports = app
module.exports = app;