Skip to content

Commit

Permalink
Fix contexts and timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
lwagner-getmomo committed Dec 14, 2023
1 parent d2be2e6 commit f72dd0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ func InitiatePaymentTask(config Config, client *atlar_client.Rest, transferID st
return err
}

ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

paymentSchemeType := "SCT" // SEPA Credit Transfer
remittanceInformationType := "UNSTRUCTURED"
remittanceInformationValue := transfer.Description
Expand Down Expand Up @@ -117,8 +114,10 @@ func InitiatePaymentTask(config Config, client *atlar_client.Rest, transferID st
},
}

requestCtx, cancel := contextutil.DetachedWithTimeout(ctx, 30*time.Second)
defer cancel()
postCreditTransfersParams := credit_transfers.PostV1CreditTransfersParams{
Context: ctx,
Context: requestCtx,
CreditTransfer: &createPaymentRequest,
}
postCreditTransferResponse, err := client.CreditTransfers.PostV1CreditTransfers(&postCreditTransfersParams)
Expand Down Expand Up @@ -148,7 +147,6 @@ func InitiatePaymentTask(config Config, client *atlar_client.Rest, transferID st
return err
}

ctx, _ = contextutil.DetachedWithTimeout(ctx, 10*time.Second)
err = scheduler.Schedule(ctx, taskDescriptor, models.TaskSchedulerOptions{
ScheduleOption: models.OPTIONS_RUN_NOW,
RestartOption: models.OPTIONS_RESTART_IF_NOT_ACTIVE,
Expand Down Expand Up @@ -215,7 +213,10 @@ func UpdatePaymentStatusTask(
}
}()

requestCtx, cancel := contextutil.DetachedWithTimeout(ctx, 30*time.Second)
defer cancel()
getCreditTransferParams := credit_transfers.GetV1CreditTransfersGetByExternalIDExternalIDParams{
Context: requestCtx,
ExternalID: serializeAtlarPaymentExternalID(transfer.ID.Reference, transfer.Attempts),
}
getCreditTransferResponse, err := client.CreditTransfers.GetV1CreditTransfersGetByExternalIDExternalID(&getCreditTransferParams)
Expand All @@ -238,9 +239,11 @@ func UpdatePaymentStatusTask(
return err
}

scheduleDuration := 2 * time.Minute
// ctx, _ = contextutil.Detached(ctx)
err = scheduler.Schedule(ctx, taskDescriptor, models.TaskSchedulerOptions{
ScheduleOption: models.OPTIONS_RUN_IN_DURATION,
Duration: 2 * time.Minute,
Duration: scheduleDuration,
RestartOption: models.OPTIONS_RESTART_IF_NOT_ACTIVE,
})
if err != nil && !errors.Is(err, task.ErrAlreadyScheduled) {
Expand Down

0 comments on commit f72dd0b

Please sign in to comment.