Skip to content

Commit 023645c

Browse files
committed
Improve logging and fix unit test (BL-12568))
1 parent af0c128 commit 023645c

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

bookCleanup/bookCleanup.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ describe("bookCleanup", () => {
110110
Environment.UNITTEST
111111
);
112112

113-
await bookCleanupInternal(Environment.UNITTEST);
113+
// eslint-disable-next-line @typescript-eslint/no-empty-function
114+
await bookCleanupInternal(Environment.UNITTEST, () => {});
114115
});
116+
// eslint-disable-next-line @typescript-eslint/no-empty-function
115117
beforeEach(async function () {});
116118
afterAll(async () => {
117119
await cleanupParse();

bookCleanup/bookCleanup.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Context } from "@azure/functions";
21
import BloomParseServer from "../common/BloomParseServer";
32
import { deleteFilesByPrefix } from "../common/s3";
43
import { Environment } from "../common/utils";
54

6-
export async function bookCleanupInternal(env: Environment, context: Context) {
5+
export async function bookCleanupInternal(env: Environment, log: Function) {
76
const parseServer = new BloomParseServer(env);
87

98
const runInSafeMode = env === Environment.PRODUCTION;
@@ -19,7 +18,7 @@ export async function bookCleanupInternal(env: Environment, context: Context) {
1918
// Delete files from S3 for partial upload.
2019
await deleteFilesByPrefix(bookPrefixToDelete, env);
2120
}
22-
context.log(
21+
log(
2322
`${
2423
runInSafeMode ? "Safe Mode. Would have deleted" : "Deleted"
2524
} files with prefix ${bookPrefixToDelete} from S3.`
@@ -30,7 +29,7 @@ export async function bookCleanupInternal(env: Environment, context: Context) {
3029
// Delete new book record which was never fully created.
3130
await parseServer.deleteBookRecord(book.objectId, sessionToken);
3231
}
33-
context.log(
32+
log(
3433
`${
3534
runInSafeMode ? "Safe Mode. Would have deleted" : "Deleted"
3635
} book record with ID ${book.objectId}.`
@@ -46,7 +45,7 @@ export async function bookCleanupInternal(env: Environment, context: Context) {
4645
sessionToken
4746
);
4847
}
49-
context.log(
48+
log(
5049
`${
5150
runInSafeMode ? "Safe Mode. Would have updated" : "Updated"
5251
} book record with ID ${

bookCleanup/index.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@ const runEvenIfLocal: boolean = false;
77
// See README for schedule of time triggered tasks
88
const timerTrigger: AzureFunction = async function (
99
context: Context,
10-
dailyTimer: any
10+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11+
timer: any
1112
): Promise<void> {
1213
// By default, we don't want to run this if we are running the functions locally.
1314
if (!runEvenIfLocal && isLocalEnvironment()) return;
1415

1516
context.log("bookCleanup trigger function started", new Date().toISOString());
1617

17-
if (dailyTimer.isPastDue) {
18+
if (timer.isPastDue) {
1819
context.log("bookCleanup trigger function is running late");
1920
}
2021

2122
try {
22-
await bookCleanupInternal(Environment.DEVELOPMENT, context);
23-
await bookCleanupInternal(Environment.PRODUCTION, context);
23+
context.log("running book cleanup for development");
24+
await bookCleanupInternal(Environment.DEVELOPMENT, context.log);
25+
context.log("running book cleanup for production");
26+
await bookCleanupInternal(Environment.PRODUCTION, context.log);
2427
context.log("book cleanup succeeded");
2528
} catch (e) {
2629
context.log("book cleanup failed", e);

0 commit comments

Comments
 (0)