Compare commits
1 Commits
6d27dce63c
...
61820ed77f
Author | SHA1 | Date | |
---|---|---|---|
|
61820ed77f |
@ -13,8 +13,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- add default
|
||||
|
||||
### Other
|
||||
- add orbis demo
|
||||
|
||||
- add basic scheduler
|
||||
|
||||
- add utility scripts
|
||||
|
BIN
assets/demo.gif
BIN
assets/demo.gif
Binary file not shown.
Before Width: | Height: | Size: 85 KiB |
@ -1,12 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/orbis/internal/app"
|
||||
"github.com/joho/godotenv"
|
||||
@ -21,23 +17,7 @@ func main() {
|
||||
|
||||
app := app.NewApp()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
stop := make(chan os.Signal, 1)
|
||||
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
<-stop
|
||||
|
||||
app.Logger().Info("stop signal received: shutting down orbis")
|
||||
cancel()
|
||||
|
||||
// Start timer for hard stop
|
||||
time.Sleep(time.Second * 10)
|
||||
fmt.Println("orbis failed to stop in time, forced to hard cancel")
|
||||
os.Exit(1)
|
||||
}()
|
||||
|
||||
if err := newRoot(app).ExecuteContext(ctx); err != nil {
|
||||
if err := newRoot(app).Execute(); err != nil {
|
||||
fmt.Printf("%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -18,20 +18,10 @@ func NewScheduler(logger *slog.Logger) *Scheduler {
|
||||
}
|
||||
|
||||
func (s *Scheduler) Execute(ctx context.Context) error {
|
||||
acquiredLeader, err := s.acquireLeader(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !acquiredLeader {
|
||||
s.logger.Info("gracefully shutting down non-elected scheduler")
|
||||
return nil
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
s.logger.Info("gracefully shutting down elected scheduler")
|
||||
s.logger.Info("gracefully shutting down scheduler")
|
||||
return nil
|
||||
default:
|
||||
if err := s.process(ctx); err != nil {
|
||||
@ -41,26 +31,11 @@ func (s *Scheduler) Execute(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Scheduler) acquireLeader(ctx context.Context) (bool, error) {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return false, nil
|
||||
|
||||
default:
|
||||
// Attempt to acquire leader
|
||||
//
|
||||
return true, nil
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Scheduler) process(ctx context.Context) error {
|
||||
s.logger.Debug("scheduler processing items")
|
||||
|
||||
// FIXME: simulate work
|
||||
time.Sleep(time.Second * 2)
|
||||
time.Sleep(time.Second * 5)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user