Skip to content

Commit

Permalink
hotfix: fix download user data script
Browse files Browse the repository at this point in the history
  • Loading branch information
danilo spinelli committed May 18, 2020
1 parent 8b490e3 commit 5ed0e05
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
33 changes: 13 additions & 20 deletions ExtractUserDataActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,22 +249,18 @@ export const getAllMessageContents = (
fromQueryEither(
() =>
messageModel.getContentFromBlob(messageContentBlobService, messageId),
"messageModel.getContentFromBlob (1)"
`messageModel.getContentFromBlob ${messageId} (1)`
).foldTaskEither<ActivityResultQueryFailure, MessageContentWithId>(
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<MessageContentWithId>(
(content: MessageContent) => ({
content,
messageId
})
maybeContent.foldL(
() => right({ messageId } as MessageContentWithId),
(content: MessageContent) =>
right({
content,
messageId
})
)
)
)
Expand All @@ -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)
)
)
)
)
Expand Down
22 changes: 15 additions & 7 deletions UserDataDownloadOrchestrator/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Expand All @@ -32,6 +32,7 @@ import { documentClient } from "../utils/cosmosdb";

const context = ({
log: {
error: console.error,
info: console.log,
verbose: console.log
}
Expand Down Expand Up @@ -84,9 +85,10 @@ async function run(): Promise<any> {
);

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, {
Expand All @@ -110,7 +112,7 @@ async function run(): Promise<any> {
password: bundle.value.password
});
} else {
throw new Error(bundle.kind);
throw new Error(toString(bundle));
}
})
.then(() =>
Expand All @@ -119,7 +121,13 @@ async function run(): Promise<any> {
nextStatus: UserDataProcessingStatusEnum.CLOSED
})
)
.catch(console.error);
.catch(err => {
console.error(err);
return setUserDataProcessingStatusActivity(context, {
currentRecord: currentUserDataProcessing,
nextStatus: UserDataProcessingStatusEnum.FAILED
});
});
}

run()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 5ed0e05

Please sign in to comment.