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

Commit 9e4bf33

Browse files
committed
Improve account update schedule
1 parent 0ab6976 commit 9e4bf33

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

access/module.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ func start() error {
7070
accountUpdateTask = module.NewTask(
7171
"update account",
7272
UpdateAccount,
73-
).Repeat(24 * time.Hour)
74-
// First execution is done by the client manager in the captain module.
73+
).Repeat(24 * time.Hour).Schedule(time.Now().Add(1 * time.Minute))
7574
}
7675

7776
return nil
@@ -102,7 +101,16 @@ func UpdateAccount(_ context.Context, task *modules.Task) error {
102101
}
103102
}()
104103

105-
u, _, err := UpdateUser()
104+
// Get current user.
105+
u, err := GetUser()
106+
if err == nil {
107+
// Do not update if we just updated.
108+
if time.Since(time.Unix(u.Meta().Modified, 0)) < 2*time.Minute {
109+
return nil
110+
}
111+
}
112+
113+
u, _, err = UpdateUser()
106114
if err != nil {
107115
return fmt.Errorf("failed to update user profile: %w", err)
108116
}

0 commit comments

Comments
 (0)