Skip to content

Commit

Permalink
chore: cleanup schedules (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbystedt authored Aug 20, 2024
1 parent 5e3ca3b commit 354a61f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/knox-pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Knox Pipeline
# Run this workflow every time a new commit pushed to your main repository or manually
on:
schedule:
- cron: "0 23 * * *"
push:
branches:
- main
workflow_dispatch:

jobs:
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/opensearch-pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Opensearch Pipeline
# Run this workflow every time a new commit pushed to your main repository or manually
on:
schedule:
- cron: "0 23 * * *"
push:
branches:
- main
workflow_dispatch:

jobs:
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/polaris-pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Polaris Pipeline
# Run this workflow every time a new commit pushed to your main repository or manually
on:
schedule:
- cron: "0 23 * * *"
push:
branches:
- main
workflow_dispatch:

jobs:
Expand Down
29 changes: 20 additions & 9 deletions src/controller/auth-monitor.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { inject, injectable } from 'inversify';
import { TYPES } from '../inversify.types';
import { exhaustMap, filter, interval, timer } from 'rxjs';
import { delay, exhaustMap, filter, interval, timer } from 'rxjs';
import { GenerateController } from './generate.contoller';
import { AuthRoleSyncController } from './auth-role-sync.controller';
import { AuthMemberSyncController } from './auth-member-sync.controller';
import { TargetService } from '../services/target.service';

const MONITOR_INTERVAL_MS = 60 * 60 * 1000;
const MONITOR_STARTUP_DELAY_MS = 5000;
const MONITOR_CACHE_RESET_INTERVAL_MS = 6 * 60 * 60 * 1000;
const MONITOR_CACHE_RESET_FULL_NTH = 4;

@injectable()
/**
* Auth monitor controller
Expand All @@ -28,23 +33,29 @@ export class AuthMonitorController {
* @returns
*/
public async monitor(): Promise<void> {
const source$ = timer(0, 30 * 60 * 1000);
const resetCacheInterval$ = interval(6 * 60 * 60 * 1000);
const resetAllCacheInterval$ = interval(12 * 60 * 60 * 1000);
const source$ = timer(MONITOR_INTERVAL_MS);
const resetCacheInterval$ = interval(MONITOR_CACHE_RESET_INTERVAL_MS);
const resetAllCacheInterval$ = interval(
MONITOR_CACHE_RESET_INTERVAL_MS * MONITOR_CACHE_RESET_FULL_NTH,
);
console.log(`>>> Monitor - start`);

// Skip every 2nd because it is a full reset
resetCacheInterval$.pipe(filter((cnt) => cnt % 2 === 0)).subscribe(() => {
console.log(`---- Reset user cache`);
this.targetService.resetUserCache(false);
});
// Skip every MONITOR_CACHE_RESET_FULL_NTH because it is a full reset
resetCacheInterval$
.pipe(filter((cnt) => cnt % MONITOR_CACHE_RESET_FULL_NTH === 0))
.subscribe(() => {
console.log(`---- Reset user cache`);
this.targetService.resetUserCache(false);
});
resetAllCacheInterval$.subscribe(() => {
console.log(`---- Reset user cache (all)`);
this.targetService.resetUserCache(true);
});

source$
.pipe(
// Delay a bit so cach reset runs first
delay(MONITOR_STARTUP_DELAY_MS),
exhaustMap(async () => {
const startMs = Date.now();
const integrationConfigs = await this.generate.generate();
Expand Down

0 comments on commit 354a61f

Please sign in to comment.