mirror of
https://github.com/getAlby/hub.git
synced 2026-08-13 12:33:39 +02:00
fix: ensure auto-swap blocks until swap is completed, fix interval between auto swaps (#1608)
This commit is contained in:
parent
8340496ded
commit
2c69cd9f5d
1 changed files with 8 additions and 3 deletions
|
|
@ -191,10 +191,9 @@ func (svc *swapsService) EnableAutoSwapOut() error {
|
|||
logger.Logger.Info("Starting auto swap workflow")
|
||||
|
||||
go func() {
|
||||
ticker := time.NewTicker(1 * time.Hour)
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
case <-time.After(1 * time.Hour):
|
||||
logger.Logger.Debug("Checking to see if we can swap")
|
||||
balance, err := svc.lnClient.GetBalances(ctx, false)
|
||||
if err != nil {
|
||||
|
|
@ -347,7 +346,13 @@ func (svc *swapsService) SwapOut(amount uint64, destination string, autoSwap boo
|
|||
|
||||
logger.Logger.WithField("swapId", swap.Id).Info("Swap created")
|
||||
|
||||
go svc.startSwapOutListener(&dbSwap)
|
||||
if autoSwap {
|
||||
// block until the swap finishes to ensure we can't do multiple concurrent auto swaps
|
||||
svc.startSwapOutListener(&dbSwap)
|
||||
} else {
|
||||
// run in parallel as we need to return the swap ID in the HTTP response
|
||||
go svc.startSwapOutListener(&dbSwap)
|
||||
}
|
||||
|
||||
return &SwapResponse{
|
||||
SwapId: swap.Id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue