Skip to content

Commit

Permalink
PRIME-2410 Add cron job template (#2487)
Browse files Browse the repository at this point in the history
* add cron job template

* add timeout
  • Loading branch information
bergomi02 authored Apr 17, 2024
1 parent 5f18df4 commit 30b61ff
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
88 changes: 88 additions & 0 deletions infrastructure/cron-jobs/populate-transaction-log-temp.cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
apiVersion: template.openshift.io/v1
kind: Template
metadata:
annotations:
description: Template for job that activates api to populate pharmanet transaction log temp
tags: cronjob
name: populate-transaction-log-temp-cronjob-template
objects:
- apiVersion: batch/v1
kind: CronJob
metadata:
name: '${CRON_NAME}'
spec:
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
containers:
- command:
- bash
- '-c'
- >-
echo -e "-------- STARTING CRON --------\n"
echo -e "-------- Getting access_token --------\n"
TOKEN=$(curl -X POST
"${KEYCLOAK_URL}/realms/${KEYCLOAK_REALM}/protocol/openid-connect/token"
\
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=${KEYCLOAK_CLIENT_ID}" \
-d "client_secret=${KEYCLOAK_CLIENT_SECRET}" | jq -r '.access_token')
echo -e ${TOKEN}
echo -e "-------- Calling PRIME API --------\n"
curl -v -X POST
http://${ENV_NAME}-webapi:8080/api/jobs/populate/transaction-log-temp?numberOfDays=15
\
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Length: 0"
echo -e "-------- CRON COMPLETE --------\n"
env:
- name: KEYCLOAK_CLIENT_SECRET
valueFrom:
secretKeyRef:
key: prime_service_account_client_secret
name: prime-service-account
- name: KEYCLOAK_CLIENT_ID
valueFrom:
secretKeyRef:
key: prime_service_account_client_id
name: prime-service-account
- name: KEYCLOAK_URL
valueFrom:
configMapKeyRef:
name: keycloak
key: KEYCLOAK_URL
- name: KEYCLOAK_REALM
valueFrom:
configMapKeyRef:
name: keycloak
key: KEYCLOAK_REALM
image: >-
public.ecr.aws/h0h9t7p1/alpine-bash-curl-jq:latest
limits:
cpu: 500m
memory: 2Gi
name: '${CRON_NAME}'
requests:
cpu: 100m
memory: 512Mi
resources: null
restartPolicy: Never
schedule: '${CRON_SCHEDULE}'
parameters:
- description: 'Cron-like schedule expression. Default: Once a day at 4 AM'
name: CRON_SCHEDULE
value: '0 10 * * *'
- name: CRON_NAME
value: prod-populate-transaction-log-temp-cronjob
- description: 'Environment name'
name: ENV_NAME
required: true
1 change: 1 addition & 0 deletions prime-dotnet-webapi/Services/ReportingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public async Task<int> PopulateTransactionLogTempAsync(int numberInDays)
copySql.Append($"and \"TransactionId\" > '{maxTransactionId}' ");
}

_context.Database.SetCommandTimeout(180);
int result = await _context.Database.ExecuteSqlRawAsync(copySql.ToString());

return result;
Expand Down

0 comments on commit 30b61ff

Please sign in to comment.