Skip to content

Commit 6ab61f3

Browse files
committed
Fix job cancelation override
1 parent 2dda551 commit 6ab61f3

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

.github/workflows/coder.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ jobs:
164164
env:
165165
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
166166
DD_DATABASE: fake
167+
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
167168
run: go run scripts/datadog-cireport/main.go gotests.xml
168169

169170
- name: Test with PostgreSQL Database
@@ -177,6 +178,7 @@ jobs:
177178
env:
178179
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
179180
DD_DATABASE: postgresql
181+
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
180182
run: go run scripts/datadog-cireport/main.go gotests.xml
181183

182184
- uses: codecov/codecov-action@v2

coderd/provisionerdaemons.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,13 @@ func (server *provisionerdServer) CancelJob(ctx context.Context, cancelJob *prot
377377
if err != nil {
378378
return nil, xerrors.Errorf("parse job id: %w", err)
379379
}
380+
job, err := server.Database.GetProvisionerJobByID(ctx, jobID)
381+
if err != nil {
382+
return nil, xerrors.Errorf("get provisioner job: %w", err)
383+
}
384+
if job.CompletedAt.Valid {
385+
return nil, xerrors.Errorf("job already completed")
386+
}
380387
err = server.Database.UpdateProvisionerJobWithCompleteByID(ctx, database.UpdateProvisionerJobWithCompleteByIDParams{
381388
ID: jobID,
382389
CompletedAt: sql.NullTime{

scripts/datadog-cireport/main.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ func main() {
4949
pipelineURL += fmt.Sprintf("/attempts/%s", os.Getenv("GITHUB_RUN_ATTEMPT"))
5050
}
5151

52-
commitMessage, err := exec.Command("git", "show", "-s", "--format=%s").CombinedOutput()
53-
if err != nil {
54-
log.Fatalf("Get commit message: %s", err)
55-
}
5652
commitData, err := exec.Command("git", "show", "-s", "--format=%an,%ae,%ad,%cn,%ce,%cd").CombinedOutput()
5753
if err != nil {
5854
log.Fatalf("Get commit data: %s", err)
@@ -63,7 +59,7 @@ func main() {
6359
"service": "coder",
6460
"_dd.cireport_version": "2",
6561

66-
"database": os.Getenv("DD_DATABASE"),
62+
"test.traits": fmt.Sprintf(`{"database":"%s"}`, os.Getenv("DD_DATABASE")),
6763

6864
// Additional tags found in DataDog docs. See:
6965
// https://docs.datadoghq.com/continuous_integration/setup_tests/junit_upload/#collecting-environment-configuration-metadata
@@ -82,7 +78,7 @@ func main() {
8278
"git.commit.sha": githubSHA,
8379
"git.repository_url": fmt.Sprintf("%s/%s.git", githubServerURL, githubRepository),
8480

85-
"git.commit.message": strings.TrimSpace(string(commitMessage)),
81+
"git.commit.message": os.Getenv("GIT_COMMIT_MESSAGE"),
8682
"git.commit.author.name": commitParts[0],
8783
"git.commit.author.email": commitParts[1],
8884
"git.commit.author.date": commitParts[2],
@@ -174,5 +170,11 @@ func main() {
174170
if err != nil {
175171
log.Fatalf("Pretty print: %s", err)
176172
}
177-
_, _ = fmt.Printf("Status code: %d\nResponse: %s\n", res.StatusCode, msg)
173+
_, _ = fmt.Println(string(msg))
174+
msg, err = json.MarshalIndent(tags, "", "\t")
175+
if err != nil {
176+
log.Fatalf("Marshal tags: %s", err)
177+
}
178+
_, _ = fmt.Println(string(msg))
179+
_, _ = fmt.Printf("Status: %d\n", res.StatusCode)
178180
}

0 commit comments

Comments
 (0)