This commit is contained in:
TypeScript Bot
2021-03-25 16:59:59 +00:00
parent 5061974f41
commit db6842c290
2 changed files with 17 additions and 14 deletions

View File

@@ -42,24 +42,27 @@ export default function main() {
});
}
type LockFileResult = { triggered: true } | { triggered: false, timestamp: string };
type LockFileResult = { triggered: true } | { triggered: false; timestamp: string };
async function withFileLock(lockFilePath: string, cb: () => Promise<void>): Promise<LockFileResult> {
if (await pathExists(lockFilePath)) {
return { triggered: false, timestamp: await readFile(lockFilePath, "utf8")};
return { triggered: false, timestamp: await readFile(lockFilePath, "utf8") };
} else {
await writeFile(lockFilePath, currentTimeStamp());
cb().then(() => remove(lockFilePath), async error => {
await removeLock();
applicationinsights.defaultClient.trackEvent({
name: "crash",
properties: {
error: String(error)
}
});
cb().then(
() => remove(lockFilePath),
async error => {
await removeLock();
applicationinsights.defaultClient.trackEvent({
name: "crash",
properties: {
error: String(error)
}
});
process.exit(1);
});
process.exit(1);
}
);
return { triggered: true };
}

View File

@@ -1,8 +1,8 @@
import { AzureFunction, Context } from "@azure/functions";
import main from "../main";
const httpTrigger: AzureFunction = async function (context: Context): Promise<void> {
context.log('HTTP trigger function processed a request.');
const httpTrigger: AzureFunction = async function(context: Context): Promise<void> {
context.log("HTTP trigger function processed a request.");
const res = await main();
context.log(res);
context.res = res;