diff --git a/infrastructure/cron-jobs/populate-transaction-log-temp.cron.yml b/infrastructure/cron-jobs/populate-transaction-log-temp.cron.yml new file mode 100644 index 0000000000..28ec2ee3e6 --- /dev/null +++ b/infrastructure/cron-jobs/populate-transaction-log-temp.cron.yml @@ -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 diff --git a/prime-dotnet-webapi/Services/ReportingService.cs b/prime-dotnet-webapi/Services/ReportingService.cs index 79c59dd5dc..106a40f11d 100644 --- a/prime-dotnet-webapi/Services/ReportingService.cs +++ b/prime-dotnet-webapi/Services/ReportingService.cs @@ -156,6 +156,7 @@ public async Task PopulateTransactionLogTempAsync(int numberInDays) copySql.Append($"and \"TransactionId\" > '{maxTransactionId}' "); } + _context.Database.SetCommandTimeout(180); int result = await _context.Database.ExecuteSqlRawAsync(copySql.ToString()); return result;