Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runner): implement runner registration with gocast #1490

Merged
merged 7 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions cmd/tumlive/tumlive.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"log/slog"
log "log/slog"
"net"
"net/http"
_ "net/http/pprof"
Expand All @@ -13,13 +13,6 @@ import (

"github.com/soheilhy/cmux"

"github.com/TUM-Dev/gocast/api"
apiv2 "github.com/TUM-Dev/gocast/apiv2/server"
"github.com/TUM-Dev/gocast/dao"
"github.com/TUM-Dev/gocast/model"
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/tum"
"github.com/TUM-Dev/gocast/web"
"github.com/dgraph-io/ristretto"
"github.com/getsentry/sentry-go"
sentrygin "github.com/getsentry/sentry-go/gin"
Expand All @@ -29,14 +22,23 @@ import (
"github.com/pkg/profile"
"gorm.io/driver/mysql"
"gorm.io/gorm"

"github.com/TUM-Dev/gocast/api"
apiv2 "github.com/TUM-Dev/gocast/apiv2/server"
"github.com/TUM-Dev/gocast/dao"
"github.com/TUM-Dev/gocast/model"
"github.com/TUM-Dev/gocast/pkg/runner_manager"
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/tum"
"github.com/TUM-Dev/gocast/web"
)

var VersionTag = "development"

type initializer func()

var logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
var logger = log.New(log.NewJSONHandler(os.Stdout, &log.HandlerOptions{
Level: log.LevelDebug,
})).With("service", "main")

var initializers = []initializer{
Expand Down Expand Up @@ -209,6 +211,7 @@ func main() {
&model.Subtitles{},
&model.TranscodingFailure{},
&model.Email{},
&model.Runner{},
)
if err != nil {
sentry.CaptureException(err)
Expand All @@ -234,6 +237,13 @@ func main() {
}
dao.Cache = *cache

m := runner_manager.New(dao.NewDaoWrapper())
log.Info("running runner manager")
err = m.Run()
if err != nil {
log.Error("Failed to start runner manager", "err", err)
}

// init meili search index settings
go tools.NewMeiliExporter(dao.NewDaoWrapper()).SetIndexSettings()

Expand Down
2 changes: 2 additions & 0 deletions dao/dao_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type DaoWrapper struct {
SubtitlesDao
TranscodingFailureDao
EmailDao
RunnerDao RunnerDao
}

func NewDaoWrapper() DaoWrapper {
Expand Down Expand Up @@ -63,5 +64,6 @@ func NewDaoWrapper() DaoWrapper {
SubtitlesDao: NewSubtitlesDao(),
TranscodingFailureDao: NewTranscodingFailureDao(),
EmailDao: NewEmailDao(),
RunnerDao: NewRunnerDao(),
}
}
49 changes: 49 additions & 0 deletions dao/runner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package dao

import (
"context"

"gorm.io/gorm"
"gorm.io/gorm/clause"

"github.com/TUM-Dev/gocast/model"
)

//go:generate mockgen -source=runner.go -destination ../mock_dao/runner.go

type RunnerDao interface {
// Get Runner by ID
Get(context.Context, uint) (model.Runner, error)

// Create a new Runner for the database
Create(context.Context, *model.Runner) error

// Delete a Runner by hostname.
Delete(context.Context, string) error
}

type runnerDao struct {
db *gorm.DB
}

func NewRunnerDao() RunnerDao {
return runnerDao{db: DB}
}

// Get a Runner by id.
func (d runnerDao) Get(c context.Context, id uint) (res model.Runner, err error) {
return res, d.db.WithContext(c).First(&res, id).Error
}

// Create a Runner.
func (d runnerDao) Create(c context.Context, it *model.Runner) error {
return d.db.WithContext(c).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "hostname"}}, // key column
DoUpdates: clause.AssignmentColumns([]string{"port"}), // column needed to be updated
}).Create(it).Error
}

// Delete a Runner by hostname.
func (d runnerDao) Delete(c context.Context, hostname string) error {
return d.db.WithContext(c).Where("hostname = ?", hostname).Delete(&model.Runner{}).Error
}
79 changes: 79 additions & 0 deletions mock_dao/runner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 17 additions & 22 deletions mock_dao/statistics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading