Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: regulation-worker changes for oauth destinations #2730

Merged
merged 9 commits into from
Nov 28, 2022
20 changes: 13 additions & 7 deletions regulation-worker/internal/delete/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ func (*APIManager) GetSupportedDestinations() []string {
return supportedDestinations
}

// prepares payload based on (job,destDetail) & make an API call to transformer.
// gets (status, failure_reason) which is converted to appropriate model.Error & returned to caller.
func (api *APIManager) Delete(ctx context.Context, job model.Job, destination model.Destination) model.JobStatus {
func (api *APIManager) delete(ctx context.Context, job model.Job, destination model.Destination, attempts int) model.JobStatus {
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved

pkgLogger.Debugf("deleting: %v", job, " from API destination: %v", destination.Name)
method := http.MethodPost
endpoint := "/deleteUsers"
Expand Down Expand Up @@ -106,22 +105,29 @@ func (api *APIManager) Delete(ctx context.Context, job model.Job, destination mo
return model.JobStatusFailed
}
jobStatus := getJobStatus(resp.StatusCode, jobResp)
pkgLogger.Debugf("[%v] JobStatus for %v: %v", destination.Name, destination.DestinationID, jobStatus)
pkgLogger.Debugf("[%v] JobStatus for %v: %v", destination.Name, job.DestinationID, jobStatus)

if isOAuthEnabled && isTokenExpired(jobResp) {
if isOAuthEnabled && isTokenExpired(jobResp) && attempts < 1 {
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
err = api.refreshOAuthToken(destination.Name, job.WorkspaceID, oAuthDetail)
if err != nil {
pkgLogger.Error(err)
return model.JobStatusFailed
}
// retry the request
pkgLogger.Debug("Retrying deleteRequest job for the whole batch")
return api.Delete(ctx, job, destination)
pkgLogger.Debugf("Retrying deleteRequest job for the whole batch: %v", job.DestinationID)
attempts++
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
return api.delete(ctx, job, destination, attempts)
}

return jobStatus
}

// prepares payload based on (job,destDetail) & make an API call to transformer.
// gets (status, failure_reason) which is converted to appropriate model.Error & returned to caller.
func (api *APIManager) Delete(ctx context.Context, job model.Job, destination model.Destination) model.JobStatus {
koladilip marked this conversation as resolved.
Show resolved Hide resolved
return api.delete(ctx, job, destination, 0)
}

func getJobStatus(statusCode int, jobResp []JobRespSchema) model.JobStatus {
switch statusCode {

Expand Down