Skip to content

Commit fe03339

Browse files
committed
Hardcoded rate limit to recurly sync to potentially help with lag
1 parent d60ca11 commit fe03339

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/read-models/shared-state/async-apply-external-event-sources.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {extractTimestamp} from '../../google/util';
3737
const ROW_BATCH_SIZE = 200;
3838
const EXPECTED_TROUBLE_TICKET_RESPONSE_SHEET_NAME = 'Form Responses 1';
3939
const TROUBLE_TICKET_SYNC_INTERVAL = Duration.fromMillis(1000 * 60 * 20);
40+
const RECURLY_SYNC_INTERVAL = Duration.fromMillis(1000 * 60 * 20);
4041

4142
const pullNewEquipmentQuizResultsForSheet = async (
4243
logger: Logger,
@@ -451,12 +452,26 @@ async function asyncApplyGoogleEvents(
451452
logger.info('...done');
452453
}
453454

455+
let lastRecurlySync: O.Option<DateTime> = O.none;
454456
async function asyncApplyRecurlyEvents(
455457
logger: Logger,
456458
currentState: BetterSQLite3Database,
457459
updateState: (event: DomainEvent) => void,
458460
recurlyToken: string
459461
) {
462+
if (
463+
O.isSome(lastRecurlySync) &&
464+
lastRecurlySync.value.diffNow().negate() < RECURLY_SYNC_INTERVAL
465+
) {
466+
logger.info(
467+
'Skipping recurly sync, next sync in %s',
468+
RECURLY_SYNC_INTERVAL.minus(
469+
lastRecurlySync.value.diffNow().negate()
470+
).toHuman()
471+
);
472+
return;
473+
}
474+
lastRecurlySync = O.some(DateTime.now());
460475
logger.info('Fetching recurly events...');
461476
const client = new recurly.Client(recurlyToken);
462477

0 commit comments

Comments
 (0)