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

[#176068662] Enable check on EmailValidation Orchestrator #132

Merged
merged 10 commits into from
Dec 14, 2020

Conversation

AleDore
Copy link
Contributor

@AleDore AleDore commented Dec 10, 2020

This PR allow to check if there is already a running orchestrator for the id composed by fiscalCode-email, in order to avoid multiple running for emailValidationProcess on the same email.

context.log.error(`${logPrefix}|ERROR=${String(err)}`);
throw new Error(String(err));
})
.fold<ReturnTypes>(identity, identity)
Copy link
Contributor

Choose a reason for hiding this comment

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

you can fold here to ResponseSuccessAccepted() so you do it once

@codecov
Copy link

codecov bot commented Dec 11, 2020

Codecov Report

Merging #132 (466578b) into master (ff1aabe) will increase coverage by 0.28%.
The diff coverage is 84.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #132      +/-   ##
==========================================
+ Coverage   82.25%   82.53%   +0.28%     
==========================================
  Files          28       29       +1     
  Lines         817      853      +36     
  Branches       82       86       +4     
==========================================
+ Hits          672      704      +32     
- Misses        140      145       +5     
+ Partials        5        4       -1     
Impacted Files Coverage Δ
utils/config.ts 77.77% <50.00%> (-3.48%) ⬇️
StartEmailValidationProcess/orchestrators.ts 78.57% <78.57%> (ø)
UpsertedProfileOrchestrator/handler.ts 80.00% <80.43%> (+0.68%) ⬆️
StartEmailValidationProcess/handler.ts 82.92% <90.90%> (+1.10%) ⬆️
HandleNHNotificationCallActivity/handler.ts 90.00% <100.00%> (+0.41%) ⬆️
utils/notification.ts 93.65% <100.00%> (+0.92%) ⬆️
utils/appinsights.ts 100.00% <0.00%> (+10.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 704cb0d...466578b. Read the comment docs.

@AleDore AleDore marked this pull request as ready for review December 11, 2020 09:43
@AleDore AleDore requested a review from gunzip December 11, 2020 09:44
export const makeStartEmailValidationProcessOrchestratorId = (
fiscalCode: FiscalCode,
email: EmailAddress
) => hashCreator(`${fiscalCode}-${email}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

what about adding the day (dd/mm/yyyy) to the hash ? in this way if the orchestrator stucks the user can retry the day after cc @balanza

Copy link
Contributor

@balanza balanza Dec 11, 2020

Choose a reason for hiding this comment

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

The idea is good, I'm just a little reluctant in introducing time assumptions without make them parametrisable.
We can have troubles testing the feature if we hardcode such behaviour.

(this is a comment of https://github.com/pagopa/io-functions-app/pull/132/files#r540826663, github doesn't make it clear)

Copy link
Contributor

Choose a reason for hiding this comment

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

you can pass a parameter with the date having a default value of Date.now() if you're worried about testing.

)
.mapLeft(err => {
context.log.error(`${logPrefix}|ERROR=${String(err)}`);
throw new Error(String(err));
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big fan of this throw... We should return a response error here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep... but API specs does not provide 500 at the moment. For instance, if we add 500 to API specs we must modify also io-backend and io-app.

Copy link
Contributor

Choose a reason for hiding this comment

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

we must add 500 to fn-app API specs, the backend seems to alreaady handle it here:
https://github.com/pagopa/io-backend/blob/master/api_backend.yaml#L345

Comment on lines 113 to 116
isOrchestratorRunning(dfClient, orchId).foldTaskEither<
Error,
IResponseSuccessAccepted
>(fromLeft, _ =>
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to cast the left type, we can just use chain here:

Suggested change
isOrchestratorRunning(dfClient, orchId).foldTaskEither<
Error,
IResponseSuccessAccepted
>(fromLeft, _ =>
isOrchestratorRunning(dfClient, orchId).chain(_ =>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

export const makeStartEmailValidationProcessOrchestratorId = (
fiscalCode: FiscalCode,
email: EmailAddress
) => hashCreator(`${fiscalCode}-${email}`);
Copy link
Contributor

@balanza balanza Dec 11, 2020

Choose a reason for hiding this comment

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

The idea is good, I'm just a little reluctant in introducing time assumptions without make them parametrisable.
We can have troubles testing the feature if we hardcode such behaviour.

(this is a comment of https://github.com/pagopa/io-functions-app/pull/132/files#r540826663, github doesn't make it clear)

Comment on lines 127 to 129
.mapLeft(err => {
context.log.error(`${logPrefix}|ERROR=${String(err)}`);
throw new Error(String(err));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd remove this part since any error here is already logged with the function name

Comment on lines 113 to 114
_.isRunning
? taskEither.of(void 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

that would be better to chain fromPredicate here instead of using taskEither.of(void 0)

Copy link
Contributor

@gunzip gunzip left a comment

Choose a reason for hiding this comment

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

lgtm, if this is tested locally we can merge and deploy @AleDore

@AleDore
Copy link
Contributor Author

AleDore commented Dec 14, 2020

lgtm, if this is tested locally we can merge and deploy @AleDore

I'm on it :)

@AleDore
Copy link
Contributor Author

AleDore commented Dec 14, 2020

lgtm, if this is tested locally we can merge and deploy @AleDore

I'm on it :)

It works! It can be merged :)

@AleDore AleDore requested a review from gunzip December 14, 2020 13:13
@gunzip gunzip merged commit bba1cf3 into master Dec 14, 2020
@gunzip gunzip deleted the 176068662_email_validation_orchestrator_lock branch December 14, 2020 13:30
This pull request was closed.
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.

3 participants