Compare commits

..

1 Commits

Author SHA1 Message Date
cuddle-please
61820ed77f 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:25:54 +00:00
5 changed files with 3 additions and 53 deletions

View File

@ -13,8 +13,6 @@ 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

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

View File

@ -1,12 +1,8 @@
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"
@ -21,23 +17,7 @@ func main() {
app := app.NewApp() app := app.NewApp()
ctx, cancel := context.WithCancel(context.Background()) if err := newRoot(app).Execute(); err != nil {
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,20 +18,10 @@ 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 elected scheduler") s.logger.Info("gracefully shutting down scheduler")
return nil return nil
default: default:
if err := s.process(ctx); err != nil { 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 { 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 * 2) time.Sleep(time.Second * 5)
return nil return nil
} }