-
Notifications
You must be signed in to change notification settings - Fork 0
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
23 changed files
with
488 additions
and
86 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
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,44 @@ | ||
package scheduler | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/cufee/aftermath/cmds/core" | ||
"github.com/go-co-op/gocron" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
func StartCronJobs(client core.Client) { | ||
log.Info().Msg("starting cron jobs") | ||
|
||
c := gocron.NewScheduler(time.UTC) | ||
// Tasks | ||
c.Cron("* * * * *").Do(runTasksWorker(client)) | ||
c.Cron("0 * * * *").Do(restartTasksWorker(client)) | ||
|
||
// Glossary - Do it around the same time WG releases game updates | ||
c.Cron("0 10 * * *").Do(UpdateGlossaryWorker(client)) | ||
c.Cron("0 12 * * *").Do(UpdateGlossaryWorker(client)) | ||
// c.AddFunc("40 9 * * 0", updateAchievementsWorker) | ||
|
||
// Averages - Update averages shortly after session refreshes | ||
c.Cron("0 10 * * *").Do(UpdateAveragesWorker(client)) | ||
c.Cron("0 2 * * *").Do(UpdateAveragesWorker(client)) | ||
c.Cron("0 19 * * *").Do(UpdateAveragesWorker(client)) | ||
|
||
// Sessions | ||
c.Cron("0 9 * * *").Do(createSessionTasksWorker(client, "NA")) // NA | ||
c.Cron("0 1 * * *").Do(createSessionTasksWorker(client, "EU")) // EU | ||
c.Cron("0 18 * * *").Do(createSessionTasksWorker(client, "AS")) // Asia | ||
|
||
// Refresh WN8 | ||
// "45 9 * * *" // NA | ||
// "45 1 * * *" // EU | ||
// "45 18 * * *" // Asia | ||
|
||
// Configurations | ||
c.Cron("0 0 */7 * *").Do(rotateBackgroundPresetsWorker(client)) | ||
|
||
// Start the Cron job scheduler | ||
c.StartAsync() | ||
} |
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,48 @@ | ||
package scheduler | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/cufee/aftermath/cmds/core" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
// CurrentTankAverages | ||
|
||
func UpdateAveragesWorker(client core.Client) func() { | ||
return func() { | ||
log.Info().Msg("updating tank averages cache") | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*1) | ||
defer cancel() | ||
|
||
// we just run the logic directly as it's not a heavy task and it doesn't matter if it fails | ||
averages, err := client.Fetch().CurrentTankAverages(ctx) | ||
if err != nil { | ||
log.Err(err).Msg("failed to update averages cache") | ||
return | ||
} | ||
|
||
err = client.Database().UpsertVehicleAverages(ctx, averages) | ||
if err != nil { | ||
log.Err(err).Msg("failed to update averages cache") | ||
return | ||
} | ||
|
||
log.Info().Msg("averages cache updated") | ||
} | ||
} | ||
|
||
func UpdateGlossaryWorker(client core.Client) func() { | ||
return func() { | ||
// // We just run the logic directly as it's not a heavy task and it doesn't matter if it fails due to the app failing | ||
// log.Info().Msg("updating glossary cache") | ||
// err := cache.UpdateGlossaryCache() | ||
// if err != nil { | ||
// log.Err(err).Msg("failed to update glossary cache") | ||
// } else { | ||
// log.Info().Msg("glossary cache updated") | ||
// } | ||
} | ||
} |
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,68 @@ | ||
package scheduler | ||
|
||
import ( | ||
"github.com/cufee/aftermath/cmds/core" | ||
) | ||
|
||
func rotateBackgroundPresetsWorker(client core.Client) func() { | ||
return func() { | ||
// // We just run the logic directly as it's not a heavy task and it doesn't matter if it fails due to the app failing | ||
// log.Info().Msg("rotating background presets") | ||
// images, err := content.PickRandomBackgroundImages(3) | ||
// if err != nil { | ||
// log.Err(err).Msg("failed to pick random background images") | ||
// return | ||
// } | ||
// err = database.UpdateAppConfiguration[[]string]("backgroundImagesSelection", images, nil, true) | ||
// if err != nil { | ||
// log.Err(err).Msg("failed to update background images selection") | ||
// } | ||
} | ||
} | ||
|
||
func createSessionTasksWorker(client core.Client, realm string) func() { | ||
return func() { | ||
// err := tasks.CreateSessionUpdateTasks(realm) | ||
// if err != nil { | ||
// log.Err(err).Msg("failed to create session update tasks") | ||
// } | ||
} | ||
} | ||
|
||
func runTasksWorker(client core.Client) func() { | ||
return func() { | ||
// if tasks.DefaultQueue.ActiveWorkers() > 0 { | ||
// return | ||
// } | ||
|
||
// activeTasks, err := tasks.StartScheduledTasks(nil, 50) | ||
// if err != nil { | ||
// log.Err(err).Msg("failed to start scheduled tasks") | ||
// return | ||
// } | ||
// if len(activeTasks) == 0 { | ||
// return | ||
// } | ||
|
||
// tasks.DefaultQueue.Process(func(err error) { | ||
// if err != nil { | ||
// log.Err(err).Msg("failed to process tasks") | ||
// return | ||
// } | ||
|
||
// // If the queue is now empty, we can run the next batch of tasks right away | ||
// runTasksWorker() | ||
|
||
// }, activeTasks...) | ||
} | ||
} | ||
|
||
func restartTasksWorker(client core.Client) func() { | ||
return func() { | ||
// _, err := tasks.RestartAbandonedTasks(nil) | ||
// if err != nil { | ||
// log.Err(err).Msg("failed to start scheduled tasks") | ||
// 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
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
Oops, something went wrong.