Skip to content

Commit 4e49d3e

Browse files
Chore/DF-20673 superstate time (#3504)
* DF-20673 superstate time update * add changeset * review fix * update comment
1 parent ec6f4f2 commit 4e49d3e

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

.changeset/brown-ducks-beg.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/superstate-adapter': minor
3+
---
4+
5+
Update schedule times

packages/sources/superstate/src/transport/nav.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface ResponseSchema {
3131
}
3232

3333
const TZ = 'America/New_York'
34+
const START_TIME = '09:08:00'
35+
const END_TIME = '12:00:00'
3436

3537
type ReportValueType = typeof inputParameters.validated.reportValue
3638

@@ -78,11 +80,13 @@ export class NavTransport implements Transport<BaseEndpointTypes> {
7880
return this.execute(fundId, reportValue)
7981
}
8082

81-
// Runs 'execute' function every day at 9:09 AM ET (if fundIdsSet is not empty)
83+
// Runs 'execute' function every day at START_TIME (if fundIdsSet is not empty)
8284
runScheduler() {
8385
const rule = new schedule.RecurrenceRule()
84-
rule.hour = 9
85-
rule.minute = 9
86+
const startTimeSegments = START_TIME.split(':').map((s) => parseInt(s))
87+
rule.hour = startTimeSegments[0]
88+
rule.minute = startTimeSegments[1]
89+
rule.second = startTimeSegments[2]
8690
rule.tz = TZ
8791

8892
schedule.scheduleJob(rule, () => {
@@ -122,16 +126,16 @@ export class NavTransport implements Transport<BaseEndpointTypes> {
122126
result = Number(data.assets_under_management)
123127
}
124128

125-
// DP updates previous working day's price on the next working day at 9:09 AM ET
126-
// If there is no fresh price data, we try to re-fetch the API until 10:30 AM ET
129+
// DP updates previous working day's price on the next working day at START_TIME ET
130+
// If there is no fresh price data, we try to re-fetch the API until END_TIME ET
127131
// Skips checks and re-running on weekends
128132
if (this.shouldCheckForExpectedData()) {
129133
// At this point we know that conditions are met, and we should check for stale data and retry if it's not updated.
130134
// If the most recent update from DP is not from previous working day, the data might be stale
131135
const expectedDate = getPreviousNonWeekendDay(TZ)
132136
if (data.net_asset_value_date !== expectedDate) {
133-
// We should retry fetching DP until we get fresh data or the time is after 10:30 AM ET
134-
if (isBeforeTime('10:30:00', TZ)) {
137+
// We should retry fetching DP until we get fresh data or the time is after END_TIME ET
138+
if (isBeforeTime(END_TIME, TZ)) {
135139
logger.warn(
136140
`Expected last update - ${expectedDate}, actual ${
137141
data.net_asset_value_date
@@ -149,7 +153,7 @@ export class NavTransport implements Transport<BaseEndpointTypes> {
149153
// while it tries to get a fresh update.
150154
} else {
151155
logger.warn(
152-
`Max retires reached. Expected update - ${expectedDate}. Latest update - ${data.net_asset_value_date}.`,
156+
`Max retries reached. Expected update - ${expectedDate}. Latest update - ${data.net_asset_value_date}.`,
153157
)
154158
}
155159
}
@@ -202,10 +206,10 @@ export class NavTransport implements Transport<BaseEndpointTypes> {
202206
if (isWeekend(toTimezoneDate(new Date(), TZ))) return false
203207

204208
// If it's a business day we need to check for stale data only if the current ET time is within certain time range (retry period).
205-
// If it's before 09:09 AM we don't need to check as it's too soon and there will be no update from DP,
206-
// the scheduler will call the execute function once it's 09:09.
207-
// If it's after 10:30 AM, it's too late, and we won't update the value until the next business day.
209+
// If it's before START_TIME we don't need to check as it's too soon and there will be no update from DP,
210+
// the scheduler will call the execute function once it's START_TIME.
211+
// If it's after END_TIME, it's too late, and we won't update the value until the next business day.
208212
// This is needed for EA restarts as the EA still has to make retries during retry period
209-
return isInTimeRange('09:09:00', '10:30:00', TZ)
213+
return isInTimeRange(START_TIME, END_TIME, TZ)
210214
}
211215
}

0 commit comments

Comments
 (0)