-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package lsps2 | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"time" | ||
) | ||
|
||
type CleanupService struct { | ||
store Lsps2Store | ||
} | ||
|
||
// The interval to clean unused promises and buy registrations. | ||
var CleanupInterval time.Duration = time.Hour | ||
|
||
// The relax period is a period where expired promises may still be valid, if | ||
// the current chainfees are cheaper than the fees in the promise itself. It is | ||
// set to ~two weeks. | ||
var RelaxPeriod time.Duration = time.Hour * 24 * 14 | ||
|
||
func NewCleanupService(store Lsps2Store) *CleanupService { | ||
return &CleanupService{ | ||
store: store, | ||
} | ||
} | ||
|
||
// Periodically cleans up unused buy registrations and promises that have | ||
// expired before the relax interval. | ||
func (c *CleanupService) Start(ctx context.Context) { | ||
for { | ||
before := time.Now().UTC().Add(-RelaxPeriod) | ||
err := c.store.RemoveUnusedExpired(ctx, before) | ||
if err != nil { | ||
log.Printf("Failed to remove unused expired registrations before %v: %v", before, err) | ||
} | ||
select { | ||
case <-time.After(CleanupInterval): | ||
continue | ||
case <-ctx.Done(): | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters