-
Notifications
You must be signed in to change notification settings - Fork 60
Add Job and Action tracking for runner with GRPC notifications #1714
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
Draft
Copilot
wants to merge
7
commits into
dev
Choose a base branch
from
copilot/implement-grpc-notifications
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9444305
Initial plan
Copilot 8549dcc
Add Job model, DAO, migration, and GRPC notifications for job tracking
Copilot 693afbc
Fix stream version bounds check and add Jobs relation to Runner/Strea…
Copilot c1c0a2a
Address PR review feedback: remove migration, rename ErrorMessage to …
Copilot b772718
fixup
joschahenningsen 7deec80
Unify JobStatus and ActionStatus into WorkState type
Copilot 750ad42
Remove lastError from Job model; errors are tracked per-action only
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -114,3 +114,6 @@ tumlive.service | |
|
|
||
| # osx | ||
| .DS_Store | ||
|
|
||
| # downloaded protoc binary | ||
| protoc-*.zip | ||
This file contains hidden or 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 hidden or 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,99 @@ | ||
| package dao | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "gorm.io/gorm" | ||
|
|
||
| "github.com/TUM-Dev/gocast/model" | ||
| ) | ||
|
|
||
| //go:generate go tool mockgen -source=job.go -destination ../mock_dao/job.go | ||
|
|
||
| // JobDao interface defines methods for job data access | ||
| type JobDao interface { | ||
| // Create creates a new job in the database | ||
| Create(context.Context, *model.Job) error | ||
|
|
||
| // Update updates an existing job in the database | ||
| Update(context.Context, *model.Job) error | ||
|
|
||
| // GetByJobID retrieves a job by its unique job ID | ||
| GetByJobID(context.Context, string) (model.Job, error) | ||
|
|
||
| // GetByStreamID retrieves all jobs for a given stream ID | ||
| GetByStreamID(context.Context, uint) ([]model.Job, error) | ||
|
|
||
| // GetByRunnerHostname retrieves all active jobs for a given runner | ||
| GetByRunnerHostname(context.Context, string) ([]model.Job, error) | ||
|
|
||
| // GetActiveJobs retrieves all active jobs (created or running) | ||
| GetActiveJobs(context.Context) ([]model.Job, error) | ||
|
|
||
| // Delete deletes a job by its job ID | ||
| Delete(context.Context, string) error | ||
|
|
||
| // DeleteByStreamID deletes all jobs for a given stream ID | ||
| DeleteByStreamID(context.Context, uint) error | ||
| } | ||
|
|
||
| type jobDao struct { | ||
| db *gorm.DB | ||
| } | ||
|
|
||
| // NewJobDao creates a new JobDao instance | ||
| func NewJobDao() JobDao { | ||
| return jobDao{db: DB} | ||
| } | ||
|
|
||
| // Create creates a new job in the database | ||
| func (d jobDao) Create(ctx context.Context, job *model.Job) error { | ||
| return d.db.WithContext(ctx).Create(job).Error | ||
| } | ||
|
|
||
| // Update updates an existing job in the database | ||
| func (d jobDao) Update(ctx context.Context, job *model.Job) error { | ||
| return d.db.WithContext(ctx).Save(job).Error | ||
| } | ||
|
|
||
| // GetByJobID retrieves a job by its unique job ID | ||
| func (d jobDao) GetByJobID(ctx context.Context, jobID string) (model.Job, error) { | ||
| var job model.Job | ||
| err := d.db.WithContext(ctx).Where("job_id = ?", jobID).First(&job).Error | ||
| return job, err | ||
| } | ||
|
|
||
| // GetByStreamID retrieves all jobs for a given stream ID | ||
| func (d jobDao) GetByStreamID(ctx context.Context, streamID uint) ([]model.Job, error) { | ||
| var jobs []model.Job | ||
| err := d.db.WithContext(ctx).Where("stream_id = ?", streamID).Find(&jobs).Error | ||
| return jobs, err | ||
| } | ||
|
|
||
| // GetByRunnerHostname retrieves all active jobs for a given runner | ||
| func (d jobDao) GetByRunnerHostname(ctx context.Context, hostname string) ([]model.Job, error) { | ||
| var jobs []model.Job | ||
| err := d.db.WithContext(ctx). | ||
| Where("runner_hostname = ? AND status IN ?", hostname, []model.JobStatus{model.JobStatusCreated, model.JobStatusRunning}). | ||
| Find(&jobs).Error | ||
| return jobs, err | ||
| } | ||
|
|
||
| // GetActiveJobs retrieves all active jobs (created or running) | ||
| func (d jobDao) GetActiveJobs(ctx context.Context) ([]model.Job, error) { | ||
| var jobs []model.Job | ||
| err := d.db.WithContext(ctx). | ||
| Where("status IN ?", []model.JobStatus{model.JobStatusCreated, model.JobStatusRunning}). | ||
| Find(&jobs).Error | ||
| return jobs, err | ||
| } | ||
|
|
||
| // Delete deletes a job by its job ID | ||
| func (d jobDao) Delete(ctx context.Context, jobID string) error { | ||
| return d.db.WithContext(ctx).Where("job_id = ?", jobID).Delete(&model.Job{}).Error | ||
| } | ||
|
|
||
| // DeleteByStreamID deletes all jobs for a given stream ID | ||
| func (d jobDao) DeleteByStreamID(ctx context.Context, streamID uint) error { | ||
| return d.db.WithContext(ctx).Where("stream_id = ?", streamID).Delete(&model.Job{}).Error | ||
| } |
This file contains hidden or 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,21 @@ | ||
| package migrations | ||
|
|
||
| import ( | ||
| "github.com/go-gormigrate/gormigrate/v2" | ||
| "gorm.io/gorm" | ||
|
|
||
| "github.com/TUM-Dev/gocast/model" | ||
| ) | ||
|
|
||
| // Migrate202412050 creates the jobs table for tracking runner job status. | ||
| func Migrate202412050() *gormigrate.Migration { | ||
| return &gormigrate.Migration{ | ||
| ID: "202412050", | ||
| Migrate: func(tx *gorm.DB) error { | ||
| return tx.AutoMigrate(&model.Job{}) | ||
| }, | ||
| Rollback: func(tx *gorm.DB) error { | ||
| return tx.Migrator().DropTable("jobs") | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ func newMigrator() *migrator { | |
| migrations.Migrate202212010(), | ||
| migrations.Migrate202212020(), | ||
| migrations.Migrate202301006(), | ||
| migrations.Migrate202412050(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot remove this as well
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed in c1c0a2a - reverted migrator.go to its original state. |
||
| }, | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot remove this, migrations happen automatically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the migration file in c1c0a2a.