Skip to content

Commit

Permalink
chore: 📦️ add common packages
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Ruck <[email protected]>
  • Loading branch information
Manuel Ruck committed Oct 21, 2023
1 parent dc71ec5 commit 0c19f68
Show file tree
Hide file tree
Showing 44 changed files with 711 additions and 2,966 deletions.
21 changes: 11 additions & 10 deletions common/bundestagio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"private": true,
"scripts": {
"build": "tsc",
"lint": "yarn lint:ts && yarn lint:exports",
"lint": "pnpm lint:ts",
"lint:ts": "tsc --noEmit",
"lint:exports": "ts-unused-exports ./tsconfig.json --ignoreFiles=index",
"prepublishOnly": "yarn build"
"lint:exports": "ts-unused-exports ./tsconfig.json --ignoreFiles=*.*",
"prepublishOnly": "pnpm build"
},
"devDependencies": {
"@types/jsonwebtoken": "^8.5.0",
"ts-unused-exports": "^7.0.3",
"typescript": "^4.4.4"
"@types/jsonwebtoken": "^9.0.4",
"ts-unused-exports": "^10.0.1",
"typescript": "^5.2.2"
},
"dependencies": {
"@democracy-deutschland/bundestag.io-definitions": "^1.0.2",
"@types/cron": "^1.7.2",
"cron": "^1.8.2",
"jsonwebtoken": "^8.5.1",
"@types/cron": "^2.4.0",
"cron": "^3.1.3",
"jsonwebtoken": "^9.0.2",
"mongoosastic": "^4.6.0",
"mongoose": "^6.0.12",
"mongoose": "6.0.12",
"mongoose-diff-history": "mimani/mongoose-diff-history#master",
"omit-deep": "^0.3.0",
"ts-mongoose": "^0.0.24"
Expand Down
24 changes: 11 additions & 13 deletions common/bundestagio/src/utils/tools.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CronJobModel, ICronJob } from "../models";
import { CronTime } from "cron";
import { CronJobModel, ICronJob } from '../models';
import { CronTime } from 'cron';

export const testCronTime = (time: string) => {
try {
const p = new CronTime(time); // eslint-disable-line no-unused-vars
const p = new CronTime(time);
console.log(`[Cronjob] Test CronTime:`, time, p);
} catch (e) {
return false;
}
Expand Down Expand Up @@ -39,7 +40,7 @@ export const setCronStart = async ({
await CronJobModel.findOneAndUpdate(
{ name },
{ lastStartDate: startDate, running },
{ upsert: true, new: true, runValidators: true, setDefaultsOnInsert: true }
{ upsert: true, new: true, runValidators: true, setDefaultsOnInsert: true },
);
};

Expand All @@ -54,11 +55,9 @@ export const setCronSuccess = async ({
successDate?: Date;
successStartDate: Date;
running?: boolean;
data?: ICronJob["data"];
data?: ICronJob['data'];
}) => {
console.info(
`[Cronjob][${name}] finished: ${successStartDate} - ${successDate}`
);
console.info(`[Cronjob][${name}] finished: ${successStartDate} - ${successDate}`);
await CronJobModel.findOneAndUpdate(
{ name },
{
Expand All @@ -67,7 +66,7 @@ export const setCronSuccess = async ({
running,
data,
},
{ upsert: true, new: true, runValidators: true, setDefaultsOnInsert: true }
{ upsert: true, new: true, runValidators: true, setDefaultsOnInsert: true },
);
};

Expand All @@ -80,15 +79,14 @@ export const setCronError = async ({
name: string;
errorDate?: Date;
running?: boolean;
error: any;
error: string;
}) => {
console.error(`[Cronjob][${name}] errored: ${error}`);
await CronJobModel.findOneAndUpdate(
{ name },
{ lastErrorDate: errorDate, running, lastError: error },
{ upsert: true, new: true, runValidators: true, setDefaultsOnInsert: true }
{ upsert: true, new: true, runValidators: true, setDefaultsOnInsert: true },
);
};

export const resetCronRunningState = async () =>
CronJobModel.updateMany({}, { running: false });
export const resetCronRunningState = async (): Promise<unknown> => CronJobModel.updateMany({}, { running: false });
Loading

0 comments on commit 0c19f68

Please sign in to comment.