Skip to content

Commit

Permalink
feat: CE-792 Adjust webEOC Poll Interval (#470)
Browse files Browse the repository at this point in the history
Co-authored-by: afwilcox <[email protected]>
  • Loading branch information
barrfalk and afwilcox authored Jun 18, 2024
1 parent b5ecb0b commit 5210f0b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions webeoc/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ objects:
secretKeyRef:
name: webeoc
key: webeoc-url
- name: WEBEOC_COMPLAINT_HISTORY_DAYS
- name: WEBEOC_COMPLAINT_HISTORY_SECONDS
valueFrom:
secretKeyRef:
name: webeoc
key: webeoc-complaint-history-days
key: webeoc-complaint-history-seconds
- name: WEBEOC_CRON_EXPRESSION
valueFrom:
secretKeyRef:
Expand Down
9 changes: 9 additions & 0 deletions webeoc/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions webeoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@nestjs/schedule": "^4.0.0",
"cron": "^3.1.6",
"date-fns": "^3.6.0",
"date-fns-tz": "^3.1.3",
"dotenv": "^16.3.1",
"nats": "^2.23.0",
"reflect-metadata": "^0.1.13",
Expand Down
1 change: 1 addition & 0 deletions webeoc/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as express from "express";
import { ExpressAdapter } from "@nestjs/platform-express";

async function bootstrap() {
process.env.TZ = "UTC"; // this application runs on UTC time in OpenShift, so let's do the same locally as well. Useful to test polling periods.
console.log("Starting WebEOC Connection Container");
dotenv.config();
const server = express();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { ComplaintsPublisherService } from "../complaints-publisher/complaints-p
import { Complaint } from "src/types/complaint-type";
import axios, { AxiosRequestConfig } from "axios";
import { CronJob } from "cron";
import { format } from "date-fns";
import { WEBEOC_API_COMPLAINTS_LIST_PATH, WEBEOC_API_COMPLAINTS_UPDATE_PATH } from "src/common/constants";
import { ComplaintUpdate } from "src/types/complaint-update-type";
import { toZonedTime, format } from "date-fns-tz";

@Injectable()
export class WebEOCComplaintsScheduler {
Expand Down Expand Up @@ -113,13 +113,21 @@ export class WebEOCComplaintsScheduler {
}

private getDateFilter() {
const complaintsAsOfDate = new Date();
const complaintHistoryDays = parseInt(process.env.WEBEOC_COMPLAINT_HISTORY_DAYS || "1", 10);
const timeZone = "America/Los_Angeles"; // This timezone automatically handles PDT/PST

if (isNaN(complaintHistoryDays)) {
throw new Error("WEBEOC_COMPLAINT_HISTORY_DAYS is not a valid number");
// Get the current date in UTC
const currentUtcDate = new Date();
// Convert the current date in UTC to the appropriate Pacific Time (PDT/PST)
const complaintsAsOfDate = toZonedTime(currentUtcDate, timeZone);
const complaintHistorySeconds = parseInt(process.env.WEBEOC_COMPLAINT_HISTORY_SECONDS || "600"); // default to 10 minutes (600 seconds)

if (isNaN(complaintHistorySeconds)) {
throw new Error("WEBEOC_COMPLAINT_HISTORY_SECONDS is not a valid number");
}
complaintsAsOfDate.setDate(complaintsAsOfDate.getDate() - complaintHistoryDays);
this.logger.debug(`Finding complaints less than ${complaintHistorySeconds} seconds old`);

complaintsAsOfDate.setSeconds(complaintsAsOfDate.getSeconds() - complaintHistorySeconds);
this.logger.debug(`Finding complaints greater than ${complaintsAsOfDate.toISOString()}`);

const formattedDate = this.formatDate(complaintsAsOfDate);
return {
Expand Down

0 comments on commit 5210f0b

Please sign in to comment.