From 5ed0e058e06e5b7d5112e58e49939bd2670934cb Mon Sep 17 00:00:00 2001 From: danilo spinelli Date: Mon, 18 May 2020 17:49:11 +0200 Subject: [PATCH] hotfix: fix download user data script --- ExtractUserDataActivity/handler.ts | 33 ++++++++++++----------------- UserDataDownloadOrchestrator/cli.ts | 22 +++++++++++++------ package.json | 2 +- yarn.lock | 8 +++---- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/ExtractUserDataActivity/handler.ts b/ExtractUserDataActivity/handler.ts index f7925a91..e6f9d2b1 100644 --- a/ExtractUserDataActivity/handler.ts +++ b/ExtractUserDataActivity/handler.ts @@ -249,22 +249,18 @@ export const getAllMessageContents = ( fromQueryEither( () => messageModel.getContentFromBlob(messageContentBlobService, messageId), - "messageModel.getContentFromBlob (1)" + `messageModel.getContentFromBlob ${messageId} (1)` ).foldTaskEither( - failure => fromEither(left(failure)), + _ => fromEither(right({ messageId } as MessageContentWithId)), maybeContent => fromEither( - fromOption( - ActivityResultQueryFailure.encode({ - kind: "QUERY_FAILURE", - query: "messageModel.getContentFromBlob (2)", - reason: `Cannot find content for message ${messageId}` - }) - )(maybeContent).map( - (content: MessageContent) => ({ - content, - messageId - }) + maybeContent.foldL( + () => right({ messageId } as MessageContentWithId), + (content: MessageContent) => + right({ + content, + messageId + }) ) ) ) @@ -287,13 +283,10 @@ export const getAllMessagesStatuses = ( failure => fromEither(left(failure)), maybeContent => fromEither( - fromOption( - ActivityResultQueryFailure.encode({ - kind: "QUERY_FAILURE", - query: "messageModel.getContentFromBlob", - reason: `Cannot find content for message ${messageId}` - }) - )(maybeContent) + maybeContent.foldL( + () => right({ messageId } as MessageStatus), + content => right(content) + ) ) ) ) diff --git a/UserDataDownloadOrchestrator/cli.ts b/UserDataDownloadOrchestrator/cli.ts index 0fd6ee26..e16cfed1 100644 --- a/UserDataDownloadOrchestrator/cli.ts +++ b/UserDataDownloadOrchestrator/cli.ts @@ -5,9 +5,7 @@ // tslint:disable: no-console no-any import * as dotenv from "dotenv"; -dotenv.config({ - path: ".env.test" -}); +dotenv.config(); import { Context } from "@azure/functions"; import { readableReport } from "italia-ts-commons/lib/reporters"; @@ -16,6 +14,8 @@ import extractUserDataActivity from "../ExtractUserDataActivity"; import sendUserDataDownloadMessageActivity from "../SendUserDataDownloadMessageActivity"; import setUserDataProcessingStatusActivity from "../SetUserDataProcessingStatusActivity"; +import { toString } from "fp-ts/lib/function"; + import { UserDataProcessingStatusEnum } from "io-functions-commons/dist/generated/definitions/UserDataProcessingStatus"; import { makeUserDataProcessingId, @@ -32,6 +32,7 @@ import { documentClient } from "../utils/cosmosdb"; const context = ({ log: { + error: console.error, info: console.log, verbose: console.log } @@ -84,9 +85,10 @@ async function run(): Promise { ); if ( - currentUserDataProcessing.status !== UserDataProcessingStatusEnum.PENDING + currentUserDataProcessing.status !== UserDataProcessingStatusEnum.PENDING && + currentUserDataProcessing.status !== UserDataProcessingStatusEnum.FAILED ) { - throw new Error("User data processing status !== PENDING"); + throw new Error("User data processing status !== PENDING & != FAILED"); } return setUserDataProcessingStatusActivity(context, { @@ -110,7 +112,7 @@ async function run(): Promise { password: bundle.value.password }); } else { - throw new Error(bundle.kind); + throw new Error(toString(bundle)); } }) .then(() => @@ -119,7 +121,13 @@ async function run(): Promise { nextStatus: UserDataProcessingStatusEnum.CLOSED }) ) - .catch(console.error); + .catch(err => { + console.error(err); + return setUserDataProcessingStatusActivity(context, { + currentRecord: currentUserDataProcessing, + nextStatus: UserDataProcessingStatusEnum.FAILED + }); + }); } run() diff --git a/package.json b/package.json index e93b6405..8e59d380 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "durable-functions": "^1.2.4", "express": "^4.15.3", "fp-ts": "1.17.0", - "io-functions-commons": "^9.0.0", + "io-functions-commons": "^10.0.0", "io-functions-express": "^0.1.0", "io-ts": "1.8.5", "italia-ts-commons": "^8.1.0", diff --git a/yarn.lock b/yarn.lock index 393ec114..13e4c025 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4191,10 +4191,10 @@ invert-kv@^2.0.0: resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02" integrity sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA== -io-functions-commons@^9.0.0: - version "9.0.0" - resolved "https://registry.yarnpkg.com/io-functions-commons/-/io-functions-commons-9.0.0.tgz#34c8ca58a590fba87c972d6b738acd93c16f1cb6" - integrity sha512-I+7qASSdt85PtyQVFH7vmlkvfGf7oZ9dVwo6Ty2evjBlFk3VPbfFUQWsT+8ClJF3RieMV1vnyCy850s8xYzYTw== +io-functions-commons@^10.0.0: + version "10.1.0" + resolved "https://registry.yarnpkg.com/io-functions-commons/-/io-functions-commons-10.1.0.tgz#c65e819ce461051a2aa2689db8c2025758e78557" + integrity sha512-r9HO4/K/mjt/7GrEgiEv6nRRx8pmb8LYMnd40ERPzmeXJlEV2C0MGOmEGU3A+tb1JhK3ew6Irhb4uxNAWvbDgw== dependencies: "@types/node-fetch" "^2.5.6" applicationinsights "^1.7.3"