Skip to content

Commit 6117e87

Browse files
committed
Fix job cancelation override
1 parent 2dda551 commit 6117e87

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ 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()
52+
commitMessage, err := exec.Command("git", "log", "-1", "--pretty=format:%s").CombinedOutput()
5353
if err != nil {
5454
log.Fatalf("Get commit message: %s", err)
5555
}
@@ -63,7 +63,7 @@ func main() {
6363
"service": "coder",
6464
"_dd.cireport_version": "2",
6565

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

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

85-
"git.commit.message": strings.TrimSpace(string(commitMessage)),
85+
"git.commit.message": string(commitMessage),
8686
"git.commit.author.name": commitParts[0],
8787
"git.commit.author.email": commitParts[1],
8888
"git.commit.author.date": commitParts[2],
@@ -174,5 +174,11 @@ func main() {
174174
if err != nil {
175175
log.Fatalf("Pretty print: %s", err)
176176
}
177-
_, _ = fmt.Printf("Status code: %d\nResponse: %s\n", res.StatusCode, msg)
177+
_, _ = fmt.Println(string(msg))
178+
msg, err = json.MarshalIndent(tags, "", "\t")
179+
if err != nil {
180+
log.Fatalf("Marshal tags: %s", err)
181+
}
182+
_, _ = fmt.Println(string(msg))
183+
_, _ = fmt.Printf("Status: %d\n", res.StatusCode)
178184
}

0 commit comments

Comments
 (0)