Skip to content

Commit

Permalink
Make sure to be in end state on any transfer failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoon Prins committed Sep 16, 2021
1 parent 200db48 commit 20d05eb
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/datatx/manager/rclone/rclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ func (driver *rclone) startJob(ctx context.Context, transferID string, srcRemote
transfer.TransferStatus = datatx.Status_STATUS_INVALID
if err := driver.pDriver.model.saveTransfer(nil); err != nil {
logger.Error().Err(err).Msgf("rclone driver: save transfer failed: %v", err)
break
}
break
}
Expand All @@ -466,6 +465,10 @@ func (driver *rclone) startJob(ctx context.Context, transferID string, srcRemote
u, err := url.Parse(driver.config.Endpoint)
if err != nil {
logger.Error().Err(err).Msgf("rclone driver: could not parse driver endpoint: %v", err)
transfer.TransferStatus = datatx.Status_STATUS_INVALID
if err := driver.pDriver.model.saveTransfer(nil); err != nil {
logger.Error().Err(err).Msgf("rclone driver: save transfer failed: %v", err)
}
break
}
u.Path = path.Join(u.Path, transferFileMethod)
Expand All @@ -474,13 +477,21 @@ func (driver *rclone) startJob(ctx context.Context, transferID string, srcRemote
req, err := http.NewRequest("POST", requestURL, bytes.NewReader(data))
if err != nil {
logger.Error().Err(err).Msgf("rclone driver: error framing post request: %v", err)
transfer.TransferStatus = datatx.Status_STATUS_INVALID
if err := driver.pDriver.model.saveTransfer(nil); err != nil {
logger.Error().Err(err).Msgf("rclone driver: save transfer failed: %v", err)
}
break
}
req.Header.Set("Content-Type", "application/json")
req.SetBasicAuth(driver.config.AuthUser, driver.config.AuthPass)
res, err := driver.client.Do(req)
if err != nil {
logger.Error().Err(err).Msgf("rclone driver: error sending post request: %v", err)
transfer.TransferStatus = datatx.Status_STATUS_INVALID
if err := driver.pDriver.model.saveTransfer(nil); err != nil {
logger.Error().Err(err).Msgf("rclone driver: save transfer failed: %v", err)
}
break
}

Expand All @@ -493,6 +504,10 @@ func (driver *rclone) startJob(ctx context.Context, transferID string, srcRemote
logger.Error().Err(err).Msgf("rclone driver: error reading response body: %v", err)
}
logger.Error().Err(err).Msgf("rclone driver: rclone request responded with error, status: %v, error: %v", errorResData.Status, errorResData.Error)
transfer.TransferStatus = datatx.Status_STATUS_INVALID
if err := driver.pDriver.model.saveTransfer(nil); err != nil {
logger.Error().Err(err).Msgf("rclone driver: save transfer failed: %v", err)
}
break
}

Expand Down

0 comments on commit 20d05eb

Please sign in to comment.