2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-10-21 09:36:12 +08:00

use sorted-set to release stale locks

This commit is contained in:
ajatprabha
2021-10-30 16:07:46 +05:30
parent cb720fc10b
commit 34cc2d8081
8 changed files with 283 additions and 54 deletions

View File

@@ -23,9 +23,14 @@ func ExampleNewSemaphore() {
// call sema.Close() when appropriate
_ = asynq.HandlerFunc(func(ctx context.Context, task *asynq.Task) error {
if !sema.Acquire(ctx) {
ok, err := sema.Acquire(ctx)
if err != nil {
return err
}
if !ok {
return &RateLimitError{RetryIn: 30 * time.Second}
}
// Make sure to release the token once we're done.
defer sema.Release(ctx)