Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add common to workspace #520

Merged
merged 10 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ node_modules
git
infra
docker_volumes
democracy
data
configuration
common
bundestag.io
.vscode
.turbo
.github
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
20 changes: 19 additions & 1 deletion common/bundestagio/src/models/mongoose.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
import Mongoose from "mongoose";
import Mongoose from 'mongoose';
const mongoose = Mongoose;
export { mongoose };

export const mongoConnect = async () =>
new Promise(async (resolve) => {
// Mongo Debug
mongoose.set('debug', false);

mongoose.connect(process.env.DB_URL!);

mongoose.connection.once('connected', () => {
console.info('MongoDB is running');
resolve(true);
});
mongoose.connection.on('error', (e: Error) => {
// Unknown if this ends up in main - therefore we log here
console.error(e.stack);
throw e;
});
});
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