Compare commits

..

2 Commits

Author SHA1 Message Date
cuddle-please
6d27dce63c chore(release): 0.1.0
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2025-01-06 21:41:19 +00:00
fe02e0ac79
add orbis demo
All checks were successful
continuous-integration/drone/push Build is passing
2025-01-06 22:40:54 +01:00
5 changed files with 53 additions and 3 deletions

View File

@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- add default - add default
### Other ### Other
- add orbis demo
- add basic scheduler - add basic scheduler
- add utility scripts - add utility scripts

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

View File

@ -18,10 +18,20 @@ func NewScheduler(logger *slog.Logger) *Scheduler {
} }
func (s *Scheduler) Execute(ctx context.Context) error { 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 { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
s.logger.Info("gracefully shutting down scheduler") s.logger.Info("gracefully shutting down elected scheduler")
return nil return nil
default: default:
if err := s.process(ctx); err != nil { 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 { func (s *Scheduler) process(ctx context.Context) error {
s.logger.Debug("scheduler processing items") s.logger.Debug("scheduler processing items")
// FIXME: simulate work // FIXME: simulate work
time.Sleep(time.Second * 5) time.Sleep(time.Second * 2)
return nil return nil
} }