add orbis demo
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kasper Juul Hermansen 2025-01-06 22:40:54 +01:00
parent ed2e15a3dd
commit fe02e0ac79
Signed by: kjuulh
SSH Key Fingerprint: SHA256:RjXh0p7U6opxnfd3ga/Y9TCo18FYlHFdSpRIV72S/QM
4 changed files with 51 additions and 3 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# Orbis
!(orbis demo)[assets/demo.gif]

BIN
assets/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

View File

@ -1,8 +1,12 @@
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"git.front.kjuulh.io/kjuulh/orbis/internal/app"
"github.com/joho/godotenv"
@ -17,7 +21,23 @@ func main() {
app := app.NewApp()
if err := newRoot(app).Execute(); err != nil {
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 {
fmt.Printf("%s\n", err)
os.Exit(1)
}

View File

@ -18,10 +18,20 @@ 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 scheduler")
s.logger.Info("gracefully shutting down elected scheduler")
return nil
default:
if err := s.process(ctx); err != nil {
@ -31,11 +41,26 @@ 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 * 5)
time.Sleep(time.Second * 2)
return nil
}