Skip to content

Commit

Permalink
Make default 'unstarted' state explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Davies committed Apr 16, 2020
1 parent 46ba173 commit e767b75
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion core/services/run_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ func TestRunManager_ResumeAllConnecting(t *testing.T) {

job, err := store.FindJob(run.JobSpecID)
require.NoError(t, err)
run.TaskRuns = []models.TaskRun{models.TaskRun{ID: models.NewID(), TaskSpecID: job.Tasks[0].ID}}
run.TaskRuns = []models.TaskRun{models.TaskRun{ID: models.NewID(), TaskSpecID: job.Tasks[0].ID, Status: models.RunStatusUnstarted}}

require.NoError(t, store.CreateJobRun(&run))
err = runManager.ResumeAllConnecting()
assert.NoError(t, err)
Expand Down
12 changes: 6 additions & 6 deletions core/store/migrations/migration1587027516/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ func Migrate(tx *gorm.DB) error {
// one type in the code but may have different meanings in future and
// arguably should be split up
return tx.Exec(`
CREATE TYPE job_run_status AS ENUM ('', 'in_progress', 'pending_confirmations', 'pending_connection', 'pending_bridge', 'pending_sleep', 'errored', 'completed', 'cancelled');
CREATE TYPE task_run_status AS ENUM ('', 'in_progress', 'pending_confirmations', 'pending_connection', 'pending_bridge', 'pending_sleep', 'errored', 'completed', 'cancelled');
CREATE TYPE job_run_status AS ENUM ('unstarted', 'in_progress', 'pending_confirmations', 'pending_connection', 'pending_bridge', 'pending_sleep', 'errored', 'completed', 'cancelled');
CREATE TYPE task_run_status AS ENUM ('unstarted', 'in_progress', 'pending_confirmations', 'pending_connection', 'pending_bridge', 'pending_sleep', 'errored', 'completed', 'cancelled');
-- It's no longer used as of deb84dbfc
ALTER TABLE run_results DROP COLUMN status;
UPDATE job_runs SET status = '' WHERE status IS NULL;
UPDATE task_runs SET status = '' WHERE status IS NULL;
UPDATE job_runs SET status = 'unstarted' WHERE status = '' OR status IS NULL;
UPDATE task_runs SET status = 'unstarted' WHERE status = '' OR status IS NULL;
DROP INDEX idx_job_runs_status;
ALTER TABLE job_runs ALTER COLUMN status TYPE job_run_status USING status::job_run_status, ALTER COLUMN status SET DEFAULT ''::job_run_status, ALTER COLUMN status SET NOT NULL;
ALTER TABLE job_runs ALTER COLUMN status TYPE job_run_status USING status::job_run_status, ALTER COLUMN status SET DEFAULT 'unstarted'::job_run_status, ALTER COLUMN status SET NOT NULL;
CREATE INDEX idx_job_runs_status ON job_runs (status) WHERE status != 'completed'::job_run_status;
ALTER TABLE task_runs ALTER COLUMN status TYPE task_run_status USING status::task_run_status, ALTER COLUMN status SET DEFAULT ''::task_run_status, ALTER COLUMN status SET NOT NULL;
ALTER TABLE task_runs ALTER COLUMN status TYPE task_run_status USING status::task_run_status, ALTER COLUMN status SET DEFAULT 'unstarted'::task_run_status, ALTER COLUMN status SET NOT NULL;
CREATE INDEX idx_task_runs_status ON task_runs (status) WHERE status != 'completed'::task_run_status;
`).Error
}
2 changes: 1 addition & 1 deletion core/store/models/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type RunStatus string

const (
// RunStatusUnstarted is the default state of any run status.
RunStatusUnstarted = RunStatus("")
RunStatusUnstarted = RunStatus("unstarted")
// RunStatusInProgress is used for when a run is actively being executed.
RunStatusInProgress = RunStatus("in_progress")
// RunStatusPendingConfirmations is used for when a run is awaiting for block confirmations.
Expand Down
4 changes: 2 additions & 2 deletions core/store/models/job_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type JobRun struct {
ResultID clnull.Uint32 `json:"-"`
RunRequest RunRequest `json:"-" gorm:"foreignkey:RunRequestID;association_autoupdate:true;association_autocreate:true"`
RunRequestID clnull.Uint32 `json:"-"`
Status RunStatus `json:"status"`
Status RunStatus `json:"status" gorm:"default:'unstarted'"`
TaskRuns []TaskRun `json:"taskRuns"`
CreatedAt time.Time `json:"createdAt"`
FinishedAt null.Time `json:"finishedAt"`
Expand Down Expand Up @@ -243,7 +243,7 @@ type TaskRun struct {
JobRunID *ID `json:"-"`
Result RunResult `json:"result"`
ResultID clnull.Uint32 `json:"-"`
Status RunStatus `json:"status"`
Status RunStatus `json:"status" gorm:"default:'unstarted'"`
TaskSpec TaskSpec `json:"task" gorm:"association_autoupdate:false;association_autocreate:false"`
TaskSpecID uint `json:"-"`
MinimumConfirmations clnull.Uint32 `json:"minimumConfirmations"`
Expand Down
2 changes: 1 addition & 1 deletion core/store/orm/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (orm *ORM) SaveJobRun(run *models.JobRun) error {
// CreateJobRun inserts a new JobRun
func (orm *ORM) CreateJobRun(run *models.JobRun) error {
orm.MustEnsureAdvisoryLock()
return orm.db.Debug().Create(run).Error
return orm.db.Create(run).Error
}

// LinkEarnedFor shows the total link earnings for a job
Expand Down

0 comments on commit e767b75

Please sign in to comment.