-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runner): implement runner registration with gocast
- Loading branch information
1 parent
3e075f4
commit b806347
Showing
15 changed files
with
409 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 id. | ||
Delete(context.Context, uint) 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"}, {Name: "hostname"}}, // key column | ||
DoUpdates: clause.AssignmentColumns([]string{"port"}), // column needed to be updated | ||
}).Create(it).Error | ||
} | ||
|
||
// Delete a Runner by id. | ||
func (d runnerDao) Delete(c context.Context, id uint) error { | ||
return d.db.WithContext(c).Delete(&model.Runner{}, id).Error | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package model | ||
|
||
import "gorm.io/gorm" | ||
|
||
// Runner represents a runner handling streams, converting videos, | ||
// extracting silence from audios, creating thumbnails, etc. | ||
type Runner struct { | ||
Hostname string `gorm:"column:hostname;primaryKey;unique;not null"` | ||
Port uint32 `gorm:"column:port;not null"` | ||
} | ||
|
||
// TableName returns the name of the table for the Runner model in the database. | ||
func (*Runner) TableName() string { | ||
return "runners" // todo | ||
} | ||
|
||
// BeforeCreate returns an error, if Runner r is invalid | ||
func (r *Runner) BeforeCreate(tx *gorm.DB) (err error) { | ||
// this method currently is a noop | ||
return nil | ||
} | ||
|
||
// AfterFind runs after the Runner is fetched from the db | ||
func (r *Runner) AfterFind(tx *gorm.DB) (err error) { | ||
// this method currently is a noop | ||
return nil | ||
} |
Oops, something went wrong.