mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 16:57:51 +08:00
GRA-1298: License check changes, free tier limits for saas (#2418)
* set free tier limits through config * add host limit to config * check for host limit on free tier * fix license validation, replace node limit with hosts * add hosts to telemetry data * debug init * validate license every 1hr * hook manager, api to fetch server usage * hook manager, server usage api * encode json server usage api * update ngork url * update license validation endpoint * avoid setting limits on eer * adding hotfix * correct users limits env var * add comments to exported funcs --------- Co-authored-by: afeiszli <alex.feiszli@gmail.com>
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gravitl/netmaker/logger"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
)
|
||||
|
||||
// == Constants ==
|
||||
@@ -12,6 +15,9 @@ import (
|
||||
// How long to wait before sending telemetry to server (24 hours)
|
||||
const timer_hours_between_runs = 24
|
||||
|
||||
// HookManagerCh - channel to add any new hooks
|
||||
var HookManagerCh = make(chan models.HookDetails, 2)
|
||||
|
||||
// == Public ==
|
||||
|
||||
// TimerCheckpoint - Checks if 24 hours has passed since telemetry was last sent. If so, sends telemetry data to posthog
|
||||
@@ -40,6 +46,36 @@ func AddHook(ifaceToAdd interface{}) {
|
||||
timeHooks = append(timeHooks, ifaceToAdd)
|
||||
}
|
||||
|
||||
// StartHookManager - listens on `HookManagerCh` to run any hook
|
||||
func StartHookManager(ctx context.Context, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
logger.Log(0, "## Stopping Hook Manager")
|
||||
return
|
||||
case newhook := <-HookManagerCh:
|
||||
wg.Add(1)
|
||||
go addHookWithInterval(ctx, wg, newhook.Hook, newhook.Interval)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func addHookWithInterval(ctx context.Context, wg *sync.WaitGroup, hook func() error, interval time.Duration) {
|
||||
defer wg.Done()
|
||||
ticker := time.NewTicker(interval)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
hook()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// == private ==
|
||||
|
||||
// timeHooks - functions to run once a day, functions must take no parameters
|
||||
|
Reference in New Issue
Block a user