feat: made requested changes for integration sync

This commit is contained in:
=
2024-08-15 23:38:16 +05:30
parent 6cab7504fc
commit cc94a3366a
2 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ export const KeyStorePrefixes = {
SyncSecretIntegrationLock: (projectId: string, environmentSlug: string, secretPath: string) => SyncSecretIntegrationLock: (projectId: string, environmentSlug: string, secretPath: string) =>
`sync-integration-mutex-${projectId}-${environmentSlug}-${secretPath}` as const, `sync-integration-mutex-${projectId}-${environmentSlug}-${secretPath}` as const,
SetSyncSecretIntegrationLastRunTimestamp: (projectId: string, environmentSlug: string, secretPath: string) => SyncSecretIntegrationLastRunTimestamp: (projectId: string, environmentSlug: string, secretPath: string) =>
`sync-integration-last-run-${projectId}-${environmentSlug}-${secretPath}` as const `sync-integration-last-run-${projectId}-${environmentSlug}-${secretPath}` as const
}; };
+5 -3
View File
@@ -654,10 +654,12 @@ export const secretQueueFactory = ({
const lockAcquiredTime = new Date(); const lockAcquiredTime = new Date();
const lastRunSyncIntegrationTimestamp = await keyStore.getItem( const lastRunSyncIntegrationTimestamp = await keyStore.getItem(
KeyStorePrefixes.SetSyncSecretIntegrationLastRunTimestamp(projectId, environment, secretPath) KeyStorePrefixes.SyncSecretIntegrationLastRunTimestamp(projectId, environment, secretPath)
); );
// check whether the integration should wait or not
if (lastRunSyncIntegrationTimestamp) { if (lastRunSyncIntegrationTimestamp) {
const INTEGRATION_INTERVAL = 2000;
const isStaleSyncIntegration = new Date(job.timestamp) < new Date(lastRunSyncIntegrationTimestamp); const isStaleSyncIntegration = new Date(job.timestamp) < new Date(lastRunSyncIntegrationTimestamp);
if (isStaleSyncIntegration) { if (isStaleSyncIntegration) {
logger.info( logger.info(
@@ -670,7 +672,7 @@ export const secretQueueFactory = ({
lockAcquiredTime.toISOString(), lockAcquiredTime.toISOString(),
lastRunSyncIntegrationTimestamp lastRunSyncIntegrationTimestamp
); );
if (timeDifferenceWithLastIntegration < 2000 && timeDifferenceWithLastIntegration > 0) if (timeDifferenceWithLastIntegration < INTEGRATION_INTERVAL && timeDifferenceWithLastIntegration > 0)
await new Promise((resolve) => { await new Promise((resolve) => {
setTimeout(resolve, 2000 - timeDifferenceWithLastIntegration * 1000); setTimeout(resolve, 2000 - timeDifferenceWithLastIntegration * 1000);
}); });
@@ -788,7 +790,7 @@ export const secretQueueFactory = ({
} }
await keyStore.setItemWithExpiry( await keyStore.setItemWithExpiry(
KeyStorePrefixes.SetSyncSecretIntegrationLastRunTimestamp(projectId, environment, secretPath), KeyStorePrefixes.SyncSecretIntegrationLastRunTimestamp(projectId, environment, secretPath),
KeyStoreTtls.SetSyncSecretIntegrationLastRunTimestampInSeconds, KeyStoreTtls.SetSyncSecretIntegrationLastRunTimestampInSeconds,
lockAcquiredTime.toISOString() lockAcquiredTime.toISOString()
); );