-
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 (#1490)
* feat(runner): implement runner registration with gocast * fix: use log/slog with import alias throughout cmd/tumlive/tumlive.go * fix(dao/runner): delete by hostname * fix(dao/runner): remove duplicate key column hostname in OnConflict clause * fix: lint protofile * feat: add lint target for runner proto files * fix: regen protos
- Loading branch information
1 parent
05b6366
commit 738c22a
Showing
16 changed files
with
450 additions
and
188 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 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 | ||
} |
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.
Oops, something went wrong.