Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/utils/logs/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,6 +80,10 @@ const logs = {
DETECT_FILE_TRIGGERED: 'Deidentify file triggered.',
GET_DETECT_RUN_TRIGGERED: 'Get detect run triggered.',
VALIDATE_GET_DETECT_RUN_INPUT: 'Validating get detect run input.',
POLL_DETECT_FILE_STATUS: 'Polling deidentify file run %s1. Received status: %s2.',
POLL_DETECT_FILE_RETRY: 'Deidentify file run %s1 is in progress. Retrying in %s2 seconds.',
POLL_DETECT_FILE_TIMEOUT: 'Deidentify file run %s1 is still in progress after reaching max wait time of %s2 seconds. Returning IN_PROGRESS.',
POLL_DETECT_FILE_SUCCESS: 'Deidentify file run %s1 completed successfully.',
},
errorLogs: {
VAULT_CONFIG_KEY_MISSING: "Invalid skyflow config. Vaults configs key missing in skyflow config.",
Expand DownExpand Up@@ -176,6 +180,9 @@ const logs = {
INVALID_TOKEN_URI: "Invalid credentials. Token URI must be a string and a valid URL.",
DETECT_REQUEST_RESOLVED: 'Detect request is resolved.',
DEIDENTIFY_FILE_REQUEST_REJECTED: 'Deidentify file resulted in failure.',
POLL_DETECT_FILE_FAILED: 'Deidentify file run %s1 failed. Reason: %s2.',
POLL_DETECT_FILE_UNEXPECTED_STATUS: 'Deidentify file run %s1 returned unexpected status: %s2. Message: %s3.',
POLL_DETECT_FILE_API_ERROR: 'Polling for deidentify file run %s1 failed with an API error: %s2.',
DETECT_RUN_REQUEST_REJECTED: 'Detect get run resulted in failure.',
DEIDENTIFY_TEXT_REQUEST_REJECTED: 'Deidentify text resulted in failure.',
REIDENTIFY_TEXT_REQUEST_REJECTED: 'Reidentify text resulted in failure.',
Expand Down
36 changes: 35 additions & 1 deletion src/vault/controller/detect/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -341,10 +341,19 @@ class DetectController {
const poll = () => {
this.client.filesAPI.getRun(runId, req)
.then((response: DeidentifyStatusResponse) => {
printLog(
parameterizedString(logs.infoLogs.POLL_DETECT_FILE_STATUS, runId, response.status),
MessageType.LOG,
this.client.getLogLevel(),
);
if (response.status?.toUpperCase() === DETECT_STATUS.IN_PROGRESS
) {
if (currentWaitTime >= maxWaitTime) {
resolve({ data: { status: 'IN_PROGRESS' }, runId });
printLog(
parameterizedString(logs.infoLogs.POLL_DETECT_FILE_TIMEOUT, runId, String(maxWaitTime)),
MessageType.WARN,
this.client.getLogLevel(),
);
resolve({ data: { status: 'IN_PROGRESS' }, runId });
} else {
const nextWaitTime = currentWaitTime * 2;
Expand All@@ -356,20 +365,45 @@ class DetectController {
waitTime = nextWaitTime;
currentWaitTime = nextWaitTime;
}
printLog(
parameterizedString(logs.infoLogs.POLL_DETECT_FILE_RETRY, runId, String(waitTime)),
MessageType.LOG,
this.client.getLogLevel(),
);
setTimeout(() => {
poll();
}, waitTime * 1000);
}
} else if (response.status?.toUpperCase() === DETECT_STATUS.SUCCESS) {
printLog(
parameterizedString(logs.infoLogs.POLL_DETECT_FILE_SUCCESS, runId),
MessageType.LOG,
this.client.getLogLevel(),
);
resolve({ data: response, runId });
}
else if (response.status?.toUpperCase() === DETECT_STATUS.FAILED) {
printLog(
parameterizedString(logs.errorLogs.POLL_DETECT_FILE_FAILED, runId, response.message ?? 'No failure reason provided by the server.'),
MessageType.ERROR,
this.client.getLogLevel(),
);
reject(new SkyflowError(SKYFLOW_ERROR_CODE.INTERNAL_SERVER_ERROR, [response.message]));
} else {
printLog(
parameterizedString(logs.errorLogs.POLL_DETECT_FILE_UNEXPECTED_STATUS, runId, response.status ?? 'undefined', response.message ?? 'No message provided by the server.'),
MessageType.ERROR,
this.client.getLogLevel(),
);
reject(new SkyflowError(SKYFLOW_ERROR_CODE.INTERNAL_SERVER_ERROR, [response.message]));
}
})
.catch((error) => {
printLog(
parameterizedString(logs.errorLogs.POLL_DETECT_FILE_API_ERROR, runId, error?.message ?? String(error)),
MessageType.ERROR,
this.client.getLogLevel(),
);
reject(error);
});
};
Expand Down
Loading