mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
add worker jobs
This commit is contained in:
parent
526963b694
commit
e0692ad649
24
.github/workflows/compile.workers.yaml
vendored
Normal file
24
.github/workflows/compile.workers.yaml
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
name: Compile Workers
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches-ignore:
|
||||
- 'hotfix-*'
|
||||
- 'release'
|
||||
- 'staging-release'
|
||||
|
||||
jobs:
|
||||
compile:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
check-latest: true
|
||||
- run: cd Common && npm install
|
||||
- run: cd Model && npm install
|
||||
- run: cd CommonServer && npm install
|
||||
- run: cd CommonUI && npm install --force
|
||||
- run: cd Workers && npm install && npm run compile
|
||||
|
21
.github/workflows/docker-build.workers.yaml
vendored
Normal file
21
.github/workflows/docker-build.workers.yaml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
name: Workers Docker Build
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches-ignore:
|
||||
- 'hotfix-*'
|
||||
- 'release'
|
||||
- 'staging-release'
|
||||
|
||||
jobs:
|
||||
# define jobs to build docker imag
|
||||
docker-build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# build image for home
|
||||
- name: build docker image
|
||||
run: npm run build-ci workers
|
@ -49,42 +49,29 @@ export class Service extends DatabaseService<Model> {
|
||||
return { createBy, carryForward: null };
|
||||
}
|
||||
|
||||
protected override async onCreateSuccess(
|
||||
onCreate: OnCreate<Model>,
|
||||
createdItem: Model
|
||||
): Promise<Model> {
|
||||
if (!createdItem.projectId) {
|
||||
public async changeAttachedMonitorStates(
|
||||
item: Model,
|
||||
props: DatabaseCommonInteractionProps
|
||||
): Promise<void> {
|
||||
if (!item.projectId) {
|
||||
throw new BadDataException('projectId is required');
|
||||
}
|
||||
|
||||
if (!createdItem.id) {
|
||||
if (!item.id) {
|
||||
throw new BadDataException('id is required');
|
||||
}
|
||||
|
||||
if (!createdItem.currentScheduledMaintenanceStateId) {
|
||||
throw new BadDataException('currentScheduledMaintenanceStateId is required');
|
||||
}
|
||||
|
||||
if (createdItem.changeMonitorStatusToId && createdItem.projectId) {
|
||||
if (item.changeMonitorStatusToId && item.projectId) {
|
||||
// change status of all the monitors.
|
||||
await MonitorService.changeMonitorStatus(
|
||||
createdItem.projectId,
|
||||
createdItem.monitors?.map((monitor: Monitor) => {
|
||||
item.projectId,
|
||||
item.monitors?.map((monitor: Monitor) => {
|
||||
return new ObjectID(monitor._id || '');
|
||||
}) || [],
|
||||
createdItem.changeMonitorStatusToId,
|
||||
onCreate.createBy.props
|
||||
item.changeMonitorStatusToId,
|
||||
props
|
||||
);
|
||||
}
|
||||
|
||||
await this.changeScheduledMaintenanceState(
|
||||
createdItem.projectId,
|
||||
createdItem.id,
|
||||
createdItem.currentScheduledMaintenanceStateId,
|
||||
onCreate.createBy.props
|
||||
);
|
||||
|
||||
return createdItem;
|
||||
}
|
||||
|
||||
public async changeScheduledMaintenanceState(
|
||||
@ -93,6 +80,19 @@ export class Service extends DatabaseService<Model> {
|
||||
scheduledMaintenanceStateId: ObjectID,
|
||||
props: DatabaseCommonInteractionProps
|
||||
): Promise<void> {
|
||||
|
||||
await this.updateBy({
|
||||
data: {
|
||||
currentScheduledMaintenanceStateId: scheduledMaintenanceStateId.id
|
||||
},
|
||||
query: {
|
||||
_id: scheduledMaintenanceId.toString()!
|
||||
},
|
||||
props: {
|
||||
isRoot: true
|
||||
}
|
||||
});
|
||||
|
||||
const statusTimeline: ScheduledMaintenanceStateTimeline =
|
||||
new ScheduledMaintenanceStateTimeline();
|
||||
|
||||
|
@ -0,0 +1,73 @@
|
||||
import logger from 'CommonServer/Utils/Logger';
|
||||
import cron from 'node-cron';
|
||||
import { EVERY_MINUTE } from '../../Utils/CronTime';
|
||||
import ScheduledMaintenanceService from 'CommonServer/Services/ScheduledMaintenanceService'
|
||||
import QueryHelper from 'CommonServer/Types/Database/QueryHelper';
|
||||
import OneUptimeDate from 'Common/Types/Date';
|
||||
import LIMIT_MAX from 'Common/Types/Database/LimitMax';
|
||||
import ScheduledMaintenance from 'Model/Models/ScheduledMaintenance';
|
||||
import ScheduledMaintenanceState from 'Model/Models/ScheduledMaintenanceState';
|
||||
import ScheduledMaintenanceStateService from 'CommonServer/Services/ScheduledMaintenanceStateService';
|
||||
|
||||
cron.schedule(EVERY_MINUTE, async () => {
|
||||
try {
|
||||
|
||||
// get all scheduled events of all the projects.
|
||||
const events: Array<ScheduledMaintenance> = await ScheduledMaintenanceService.findBy({
|
||||
query: {
|
||||
currentScheduledMaintenanceState: {
|
||||
isScheduledState: true,
|
||||
} as any,
|
||||
startsAt: QueryHelper.lessThan(OneUptimeDate.getCurrentDate())
|
||||
},
|
||||
props: {
|
||||
isRoot: true
|
||||
},
|
||||
limit: LIMIT_MAX,
|
||||
skip: 0,
|
||||
select: {
|
||||
_id: true,
|
||||
projectId: true,
|
||||
changeMonitorStatusToId: true
|
||||
},
|
||||
populate: {
|
||||
monitors: {
|
||||
_id: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// change their state to Ongoing.
|
||||
|
||||
for (const event of events) {
|
||||
const scheduledMaintenanceState: ScheduledMaintenanceState | null =
|
||||
await ScheduledMaintenanceStateService.findOneBy({
|
||||
query: {
|
||||
projectId: event.projectId!,
|
||||
isScheduledState: true,
|
||||
},
|
||||
select: {
|
||||
_id: true,
|
||||
},
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!scheduledMaintenanceState || !scheduledMaintenanceState.id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
await ScheduledMaintenanceService.changeScheduledMaintenanceState(event.projectId!, event.id!, scheduledMaintenanceState.id, {
|
||||
isRoot: true
|
||||
})
|
||||
|
||||
// change attached monitor states.
|
||||
await ScheduledMaintenanceService.changeAttachedMonitorStates(event, { isRoot: true })
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
}
|
||||
});
|
1
Workers/Utils/CronTime.ts
Normal file
1
Workers/Utils/CronTime.ts
Normal file
@ -0,0 +1 @@
|
||||
export const EVERY_MINUTE: string = '* * * * *';
|
6936
Workers/package-lock.json
generated
6936
Workers/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,14 +4,26 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"start": "ts-node Index.ts",
|
||||
"compile": "tsc",
|
||||
"dev": "nodemon",
|
||||
"audit": "npm audit --audit-level=low",
|
||||
"dep-check": "depcheck ./ --skip-missing=true",
|
||||
"test": "jest"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"node-cron": "^3.0.2",
|
||||
"@types/node-cron": "^3.0.4",
|
||||
"Common": "file:../Common",
|
||||
"CommonServer": "file:../CommonServer",
|
||||
"Model": "file:../Model",
|
||||
"CommonServer": "file:../CommonServer"
|
||||
"node-cron": "^3.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.5.0",
|
||||
"@types/node": "^17.0.31",
|
||||
"jest": "^28.1.0",
|
||||
"ts-jest": "^28.0.2"
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,21 @@ services:
|
||||
- redis
|
||||
- postgres
|
||||
|
||||
workers:
|
||||
ports:
|
||||
- '3452:3452'
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./Workers/Dockerfile
|
||||
env_file:
|
||||
- ./Common/.env
|
||||
- ./CommonServer/.env
|
||||
- ./Workers/.env
|
||||
environment: *common-variables
|
||||
depends_on:
|
||||
- postgres
|
||||
- mail
|
||||
|
||||
file:
|
||||
ports:
|
||||
- '3125:3125'
|
||||
|
@ -217,11 +217,9 @@ services:
|
||||
- ./Workers/.env
|
||||
environment: *common-variables
|
||||
depends_on:
|
||||
- redis
|
||||
- postgres
|
||||
- mail
|
||||
links:
|
||||
- redis
|
||||
- postgres
|
||||
- mail
|
||||
volumes:
|
||||
|
Loading…
Reference in New Issue
Block a user