From c20bd649814d0708dd879383fd952d59f3f3087c Mon Sep 17 00:00:00 2001 From: Mac Deluca Date: Mon, 18 Nov 2024 14:37:55 -0800 Subject: [PATCH] feat: added env variable for cronjob schedule --- api/.pipeline/config.js | 7 +++++++ api/.pipeline/lib/api.deploy.js | 2 ++ api/.pipeline/templates/api.dc.yaml | 18 ++++++++++-------- .../templates/prereqs/biohubbc-telemetry.yaml | 8 ++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 api/.pipeline/templates/prereqs/biohubbc-telemetry.yaml diff --git a/api/.pipeline/config.js b/api/.pipeline/config.js index ac506c9645..b858f4c077 100644 --- a/api/.pipeline/config.js +++ b/api/.pipeline/config.js @@ -21,6 +21,9 @@ const deployChangeId = (isStaticDeployment && 'deploy') || changeId; const branch = (isStaticDeployment && options.branch) || null; const tag = (branch && `build-${version}-${changeId}-${branch}`) || `build-${version}-${changeId}`; +// The telemetry cronjob schedule - dev/test/prod runs at midnight, PR's NEVER run +const telemetryCronjobSchedule = (isStaticDeployment && '0 0 * * *') || '0 0 0 * *'; + const staticUrlsAPI = config.staticUrlsAPI; const staticUrls = config.staticUrls; @@ -71,6 +74,7 @@ const phases = { dbName: `${dbName}`, phase: 'dev', changeId: deployChangeId, + telemetryCronjobSchedule: telemetryCronjobSchedule, suffix: `-dev-${deployChangeId}`, instance: `${name}-dev-${deployChangeId}`, version: `${deployChangeId}-${changeId}`, @@ -114,6 +118,7 @@ const phases = { dbName: `${dbName}`, phase: 'test', changeId: deployChangeId, + telemetryCronjobSchedule: telemetryCronjobSchedule, suffix: `-test`, instance: `${name}-test`, version: `${version}`, @@ -157,6 +162,7 @@ const phases = { dbName: `${dbName}-spi`, phase: 'test-spi', changeId: deployChangeId, + telemetryCronjobSchedule: telemetryCronjobSchedule, suffix: `-test-spi`, instance: `${name}-spi-test-spi`, version: `${version}`, @@ -200,6 +206,7 @@ const phases = { dbName: `${dbName}`, phase: 'prod', changeId: deployChangeId, + telemetryCronjobSchedule: telemetryCronjobSchedule, suffix: `-prod`, instance: `${name}-prod`, version: `${version}`, diff --git a/api/.pipeline/lib/api.deploy.js b/api/.pipeline/lib/api.deploy.js index 620856623f..0670265d75 100644 --- a/api/.pipeline/lib/api.deploy.js +++ b/api/.pipeline/lib/api.deploy.js @@ -32,6 +32,8 @@ const apiDeploy = async (settings) => { HOST: phases[phase].host, APP_HOST: phases[phase].appHost, CHANGE_ID: phases.build.changeId || changeId, + // Cronjobs + TELEMETRY_CRONJOB_SCHEDULE: phases[phase].telemetryCronjobSchedule, // Node NODE_ENV: phases[phase].nodeEnv, NODE_OPTIONS: phases[phase].nodeOptions, diff --git a/api/.pipeline/templates/api.dc.yaml b/api/.pipeline/templates/api.dc.yaml index 97ff41e8bd..72adc0d478 100644 --- a/api/.pipeline/templates/api.dc.yaml +++ b/api/.pipeline/templates/api.dc.yaml @@ -27,6 +27,9 @@ parameters: - name: CHANGE_ID description: Change id of the project. This will help to pull image stream required: true + - name: CRONJOB_SCHEDULE + description: The + required: true value: '0' - name: NODE_ENV description: Application Environment type variable @@ -206,6 +209,9 @@ parameters: - name: REPLICAS_MAX value: '1' # Telemetry + - name: TELEMETRY_CRONJOB_SCHEDULE + description: The schedule for the telemetry cronjob + value: '0 0 0 * *' # This will never run - see `config.js` - Phase injects valid schedules for static deployments only - name: TELEMETRY_SECRET description: The name of the Openshift Biohubbc telemetry secret value: biohubbc-telemetry @@ -564,8 +570,8 @@ objects: labels: role: telemetry-cronjob spec: - schedule: '0 0 * * *' # Runs every day at 12:00am - concurrencyPolicy: "Replace" + schedule: ${TELEMETRY_CRONJOB_SCHEDULE} + concurrencyPolicy: "Forbid" successfulJobsHistoryLimit: 1 failedJobsHistoryLimit: 1 jobTemplate: @@ -577,10 +583,6 @@ objects: image: ${BASE_IMAGE_REGISTRY_URL}/${NAMESPACE}/${NAME}:${VERSION} imagePullPolicy: Always env: - - name: VERSION - value: ${VERSION} - - name: CHANGE_VERSION - value: ${CHANGE_ID} - name: NODE_ENV value: ${NODE_ENV} - name: NODE_OPTIONS @@ -627,10 +629,10 @@ objects: value: ${LOG_LEVEL} - name: LOG_LEVEL_FILE value: ${LOG_LEVEL_FILE} - - name: LOG_FILE_DIR + - name: data/cronjob-logs value: ${LOG_FILE_DIR} - name: LOG_FILE_NAME - value: ${LOG_FILE_NAME} + value: sims-telemetry-cronjob-%DATE%.log - name: LOG_FILE_DATE_PATTERN value: ${LOG_FILE_DATE_PATTERN} - name: LOG_FILE_MAX_SIZE diff --git a/api/.pipeline/templates/prereqs/biohubbc-telemetry.yaml b/api/.pipeline/templates/prereqs/biohubbc-telemetry.yaml new file mode 100644 index 0000000000..85e80f199a --- /dev/null +++ b/api/.pipeline/templates/prereqs/biohubbc-telemetry.yaml @@ -0,0 +1,8 @@ +kind: Secret +apiVersion: v1 +metadata: + name: biohubbc-telemetry +data: + lotek_acount_username: + lotek_acount_password: +type: Opaque