mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-05 04:37:14 +00:00
chore: implement runners
This commit is contained in:
47
server/runner/license/runner.go
Normal file
47
server/runner/license/runner.go
Normal file
@ -0,0 +1,47 @@
|
||||
package license
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/yourselfhosted/slash/server/service/license"
|
||||
"github.com/yourselfhosted/slash/store"
|
||||
)
|
||||
|
||||
type Runner struct {
|
||||
Store *store.Store
|
||||
|
||||
licenseService *license.LicenseService
|
||||
}
|
||||
|
||||
func NewRunner(store *store.Store, licenseService *license.LicenseService) *Runner {
|
||||
return &Runner{
|
||||
Store: store,
|
||||
licenseService: licenseService,
|
||||
}
|
||||
}
|
||||
|
||||
// Schedule runner every 12 hours.
|
||||
const runnerInterval = time.Hour * 12
|
||||
|
||||
func (r *Runner) Run(ctx context.Context) {
|
||||
ticker := time.NewTicker(runnerInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
r.RunOnce(ctx)
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Runner) RunOnce(ctx context.Context) {
|
||||
// Load subscription.
|
||||
if _, err := r.licenseService.LoadSubscription(ctx); err != nil {
|
||||
slog.Error("failed to load subscription", slog.Any("error", err))
|
||||
}
|
||||
}
|
43
server/runner/version/runner.go
Normal file
43
server/runner/version/runner.go
Normal file
@ -0,0 +1,43 @@
|
||||
// Package version provides a runner to check the latest version of the application.
|
||||
package version
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/yourselfhosted/slash/server/profile"
|
||||
"github.com/yourselfhosted/slash/store"
|
||||
)
|
||||
|
||||
type Runner struct {
|
||||
Store *store.Store
|
||||
Profile *profile.Profile
|
||||
}
|
||||
|
||||
func NewRunner(store *store.Store, profile *profile.Profile) *Runner {
|
||||
return &Runner{
|
||||
Store: store,
|
||||
Profile: profile,
|
||||
}
|
||||
}
|
||||
|
||||
// Schedule checker every 8 hours.
|
||||
const runnerInterval = time.Hour * 8
|
||||
|
||||
func (r *Runner) Run(ctx context.Context) {
|
||||
ticker := time.NewTicker(runnerInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
r.RunOnce(ctx)
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (*Runner) RunOnce(_ context.Context) {
|
||||
// Implement me.
|
||||
}
|
Reference in New Issue
Block a user