-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#176068662] Enable check on EmailValidation Orchestrator (#132)
* [#176068662] Enable check on orchestrators running * [#176068662] Fold refactor * [#176068662] Fix tests * [#176068662] insert chain instead of foldTaskEither * [#176068662] fix lint * [#176068662] Remove error log * [#176068662] Refactor over review * [#176068662] Add date on orchestrator id Co-authored-by: Danilo Spinelli <gunzip@users.noreply.github.com> Co-authored-by: Emanuele De Cupis <ema.decu@gmail.com>
- Loading branch information
1 parent
704cb0d
commit bba1cf3
Showing
4 changed files
with
143 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as crypto from "crypto"; | ||
import * as df from "durable-functions"; | ||
import { DurableOrchestrationClient } from "durable-functions/lib/src/durableorchestrationclient"; | ||
|
||
import * as dateFns from "date-fns"; | ||
import { toError } from "fp-ts/lib/Either"; | ||
import { TaskEither, tryCatch } from "fp-ts/lib/TaskEither"; | ||
|
||
import { FiscalCode } from "italia-ts-commons/lib/strings"; | ||
import { PromiseType } from "italia-ts-commons/lib/types"; | ||
import { EmailAddress } from "../generated/backend/EmailAddress"; | ||
|
||
const hashCreator = (value: string) => | ||
crypto | ||
.createHash("sha256") | ||
.update(value) | ||
.digest("hex"); | ||
|
||
/** | ||
* The identifier for EmailValidationProcessOrchestrator | ||
* @param fiscalCode the id of the requesting user | ||
* @param email the user's email | ||
*/ | ||
export const makeStartEmailValidationProcessOrchestratorId = ( | ||
fiscalCode: FiscalCode, | ||
email: EmailAddress, | ||
creationDate: Date = new Date() | ||
) => | ||
hashCreator( | ||
`${dateFns.format(creationDate, "dd/MM/yyyy")}-${fiscalCode}-${email}` | ||
); | ||
|
||
/** | ||
* Returns the status of the orchestrator augmented with an isRunning attribute | ||
*/ | ||
export const isOrchestratorRunning = ( | ||
client: DurableOrchestrationClient, | ||
orchestratorId: string | ||
): TaskEither< | ||
Error, | ||
PromiseType<ReturnType<typeof client["getStatus"]>> & { | ||
isRunning: boolean; | ||
} | ||
> => | ||
tryCatch(() => client.getStatus(orchestratorId), toError).map(status => ({ | ||
...status, | ||
isRunning: | ||
status.runtimeStatus === df.OrchestrationRuntimeStatus.Running || | ||
status.runtimeStatus === df.OrchestrationRuntimeStatus.Pending | ||
})); |
This file contains 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