mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 05:27:48 +00:00
feat: made requested changes for integration sync
This commit is contained in:
@@ -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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user