From 354a61f1ce310dcb8b9ca03a877051cb6f5ec5b0 Mon Sep 17 00:00:00 2001 From: Matthew Bystedt Date: Tue, 20 Aug 2024 09:02:22 -0700 Subject: [PATCH] chore: cleanup schedules (#43) --- .github/workflows/knox-pipeline.yml | 5 ---- .github/workflows/opensearch-pipeline.yml | 5 ---- .github/workflows/polaris-pipeline.yml | 5 ---- src/controller/auth-monitor.controller.ts | 29 ++++++++++++++++------- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/.github/workflows/knox-pipeline.yml b/.github/workflows/knox-pipeline.yml index fbe31be..92dd312 100644 --- a/.github/workflows/knox-pipeline.yml +++ b/.github/workflows/knox-pipeline.yml @@ -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: diff --git a/.github/workflows/opensearch-pipeline.yml b/.github/workflows/opensearch-pipeline.yml index d85a17f..fff9100 100644 --- a/.github/workflows/opensearch-pipeline.yml +++ b/.github/workflows/opensearch-pipeline.yml @@ -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: diff --git a/.github/workflows/polaris-pipeline.yml b/.github/workflows/polaris-pipeline.yml index 0deb9d4..5b2d33b 100644 --- a/.github/workflows/polaris-pipeline.yml +++ b/.github/workflows/polaris-pipeline.yml @@ -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: diff --git a/src/controller/auth-monitor.controller.ts b/src/controller/auth-monitor.controller.ts index aa94c06..9eb66e6 100644 --- a/src/controller/auth-monitor.controller.ts +++ b/src/controller/auth-monitor.controller.ts @@ -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 @@ -28,16 +33,20 @@ export class AuthMonitorController { * @returns */ public async monitor(): Promise { - 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); @@ -45,6 +54,8 @@ export class AuthMonitorController { 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();