Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Improve account update schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Oct 17, 2023
1 parent 0ab6976 commit 9e4bf33
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions access/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ func start() error {
accountUpdateTask = module.NewTask(
"update account",
UpdateAccount,
).Repeat(24 * time.Hour)
// First execution is done by the client manager in the captain module.
).Repeat(24 * time.Hour).Schedule(time.Now().Add(1 * time.Minute))
}

return nil
Expand Down Expand Up @@ -102,7 +101,16 @@ func UpdateAccount(_ context.Context, task *modules.Task) error {
}
}()

u, _, err := UpdateUser()
// Get current user.
u, err := GetUser()
if err == nil {
// Do not update if we just updated.
if time.Since(time.Unix(u.Meta().Modified, 0)) < 2*time.Minute {
return nil
}
}

u, _, err = UpdateUser()
if err != nil {
return fmt.Errorf("failed to update user profile: %w", err)
}
Expand Down

0 comments on commit 9e4bf33

Please sign in to comment.