Created
December 4, 2018 21:56
-
-
Save joelbarbosa/c39e3de94f934e74b6357d3f8f2a00b1 to your computer and use it in GitHub Desktop.
questions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Questions: | |
* What do you think PFC.props is doing? | |
- Creating a Object with reference parameters, map your keys; | |
* What is the concurrency variable good for? | |
- Its as especifique option where limits the number of Promise created. | |
* sendOutStatusEmails ignores errors (except for logging them). | |
Let's say your task was to make sure the whole function fails as soon sending out any | |
email failed. How would you adjust the code? | |
- follows the code: | |
*/ | |
return Promise.map(updatedOrganizations, organization => { | |
// Inform the user at the start and end of the trial phase | |
if (organization.exceededDays === 1 || | |
organization.exceededDays === constants.maxExceededDays + 1) { | |
return OrganizationController | |
.sendOutOrganizationStatusEmail({ | |
req: params.req, | |
parentTrx: params.parentTrx, | |
organization | |
}) | |
.then(() => { | |
throw new Error("failed"); | |
}) | |
.catch(err => { | |
// We are ignoring errors here in order to at least inform the other users | |
_strucd.log.error(`updateExceededDays Cronjob: Error when sending out organization status email. OrganizationId: ${organization.id} Error message: ${err.message}`); | |
}); | |
} | |
}, {concurrency}); | |
/* | |
Questions: | |
* Do you think synchronizing the different resources could be done in parallel? | |
If so, would there be a downside to doing so? | |
- Yes, it could be, could use all function in .all; The problem is that | |
do not garant the chains of functions. | |
* Why use _.get(err, ['data', 'error', 'code']) if you could simply do err.data.error.code? | |
And can you think of a better name for err here? | |
- You can't, because the path Object is an Array; | |
- Could be error or ErrorRestAngularWithoutLoadingBar and referred others errors with an appropriate name and responsability. | |
Challenge: | |
Imagine we added the created_at and updated_at columns for "categorySortOrders" as the TODO suggests. | |
Please adjust the code in a way that prevents synchronizing this resource if there was no change. | |
- follows the code: | |
*/ | |
.then(function () { | |
// TODO: Add created_at, updated_at columns for category sort orders | |
var shouldSyncCategorySortOrders = timestamps.categorySortOrders === undefined || | |
_.isNil(_.get(synchronization, ['nextCategorySortOrdersWatermark', 'created_at'])) || | |
_.isNil(_.get(synchronization, ['nextCategorySortOrdersWatermark', 'updated_at'])) || | |
moment(timestamps.categorySortOrders).isAfter(moment(synchronization.nextCategorySortOrdersWatermark.created_at)) || | |
moment(timestamps.categorySortOrders).isAfter(moment(synchronization.nextCategorySortOrdersWatermark.updated_at)); | |
if (shouldSyncCategorySortOrders === false || timestamps.categorySortOrders === null) { | |
return; | |
} | |
return synchronizeCategorySortOrders(listId); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment