fix sql.ErrNoRows when watching for canceled builds

This commit is contained in:
Brad Rydzewski 2020-06-08 15:36:08 -04:00
parent 840f58dc7f
commit 4a1c639452
6 changed files with 65 additions and 12 deletions

View file

@ -9,12 +9,12 @@ platform:
steps: steps:
- name: test - name: test
image: golang:1.13.0 image: golang:1.14.4
commands: commands:
- go test ./... - go test ./...
- name: build - name: build
image: golang:1.13.0 image: golang:1.14.4
commands: commands:
- sh scripts/build.sh - sh scripts/build.sh
environment: environment:
@ -48,7 +48,7 @@ platform:
steps: steps:
- name: build - name: build
image: golang:1.13.0 image: golang:1.14.4
commands: commands:
- sh scripts/build.sh - sh scripts/build.sh
environment: environment:
@ -86,7 +86,7 @@ platform:
steps: steps:
- name: build - name: build
image: golang:1.13.0 image: golang:1.14.4
commands: commands:
- sh scripts/build.sh - sh scripts/build.sh
environment: environment:

View file

@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Added
- re-assigned repository ownership when deactivating a user.
- re-assigned repository ownership when deleting a user.
- de-activate a repository when deleting a user if re-assignment fails.
- de-activate a repository when deactivating a user if re-assignment fails.
- routine to cleanup builds stuck in a pending state.
- routine to cleanup builds stuck in a running state.
- private mode setting requires authentication to view public repositories.
### Fixed
- issue with sq.ErrNoRows error when canceling a build.
### Changed
- upgraded Go toolchain to version 1.14.4.
## [1.7.0] - 2020-03-27 ## [1.7.0] - 2020-03-27
### Added ### Added
- endpoint to display the latest build by branch. [#2940](https://github.com/drone/drone/pull/2940). - endpoint to display the latest build by branch. [#2940](https://github.com/drone/drone/pull/2940).

View file

@ -115,3 +115,28 @@ type BuildStore interface {
// Count returns a count of builds. // Count returns a count of builds.
Count(context.Context) (int64, error) Count(context.Context) (int64, error)
} }
// IsDone returns true if the build has a completed state.
func (b *Build) IsDone() bool {
switch b.Status {
case StatusWaiting,
StatusPending,
StatusRunning,
StatusBlocked:
return false
default:
return true
}
}
// IsFailed returns true if the build has failed
func (b *Build) IsFailed() bool {
switch b.Status {
case StatusFailing,
StatusKilled,
StatusError:
return true
default:
return false
}
}

View file

@ -473,21 +473,33 @@ func (m *Manager) Netrc(ctx context.Context, id int64) (*core.Netrc, error) {
// Watch watches for build cancellation requests. // Watch watches for build cancellation requests.
func (m *Manager) Watch(ctx context.Context, id int64) (bool, error) { func (m *Manager) Watch(ctx context.Context, id int64) (bool, error) {
ok, err := m.Scheduler.Cancelled(ctx, id) ok, err := m.Scheduler.Cancelled(ctx, id)
// we expect a context cancel error here which
// indicates a polling timeout. The subscribing
// client should look for the context cancel error
// and resume polling.
if err != nil { if err != nil {
return ok, err return ok, err
} }
// if a not found error is returned we should check // // TODO (bradrydzewski) we should be able to return
// the database to see if the stage is complete. If // // immediately if Cancelled returns true. This requires
// // some more testing but would avoid the extra database
// // call.
// if ok {
// return ok, err
// }
// if no error is returned we should check
// the database to see if the build is complete. If
// complete, return true. // complete, return true.
stage, err := m.Stages.Find(ctx, id) build, err := m.Builds.Find(ctx, id)
if err != nil { if err != nil {
logger := logrus.WithError(err) logger := logrus.WithError(err)
logger = logger.WithField("step-id", id) logger = logger.WithField("build-id", id)
logger.Warnln("manager: cannot find stage") logger.Warnln("manager: cannot find build")
return ok, err return ok, err
} }
return stage.IsDone(), nil return build.IsDone(), nil
} }
// Write writes a line to the build logs. // Write writes a line to the build logs.

View file

@ -25,7 +25,7 @@ var (
// VersionMajor is for an API incompatible changes. // VersionMajor is for an API incompatible changes.
VersionMajor int64 = 1 VersionMajor int64 = 1
// VersionMinor is for functionality in a backwards-compatible manner. // VersionMinor is for functionality in a backwards-compatible manner.
VersionMinor int64 = 7 VersionMinor int64 = 8
// VersionPatch is for backwards-compatible bug fixes. // VersionPatch is for backwards-compatible bug fixes.
VersionPatch int64 VersionPatch int64
// VersionPre indicates prerelease. // VersionPre indicates prerelease.

View file

@ -9,7 +9,7 @@ package version
import "testing" import "testing"
func TestVersion(t *testing.T) { func TestVersion(t *testing.T) {
if got, want := Version.String(), "1.7.0"; got != want { if got, want := Version.String(), "1.8.0"; got != want {
t.Errorf("Want version %s, got %s", want, got) t.Errorf("Want version %s, got %s", want, got)
} }
} }