-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cancelling multiple tasks (#84)
- Loading branch information
Showing
16 changed files
with
249 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
# in foreground, continously run app | ||
while true; do | ||
_build/pug -w ./demo/configs -d | ||
_build/pug -w ./demo -d | ||
done |
This file contains 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 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,11 @@ | ||
terraform { | ||
backend "local" {} | ||
} | ||
|
||
// Requires that an http server be setup locally on $url - if the server | ||
// doesn't respond to the request then this should hang indefinitely. | ||
data "http" "forever" { | ||
url = var.url | ||
} | ||
|
||
variable "url" {} |
Empty file.
This file contains 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,11 @@ | ||
terraform { | ||
backend "local" {} | ||
} | ||
|
||
// Requires that an http server be setup locally on $url - if the server | ||
// doesn't respond to the request then this should hang indefinitely. | ||
data "http" "forever" { | ||
url = var.url | ||
} | ||
|
||
variable "url" {} |
Empty file.
This file contains 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,11 @@ | ||
terraform { | ||
backend "local" {} | ||
} | ||
|
||
// Requires that an http server be setup locally on $url - if the server | ||
// doesn't respond to the request then this should hang indefinitely. | ||
data "http" "forever" { | ||
url = var.url | ||
} | ||
|
||
variable "url" {} |
Empty file.
This file contains 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,11 @@ | ||
terraform { | ||
backend "local" {} | ||
} | ||
|
||
// Requires that an http server be setup locally on $url - if the server | ||
// doesn't respond to the request then this should hang indefinitely. | ||
data "http" "forever" { | ||
url = var.url | ||
} | ||
|
||
variable "url" {} |
Empty file.
This file contains 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 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 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,45 @@ | ||
package task | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/leg100/pug/internal/resource" | ||
"github.com/leg100/pug/internal/tui" | ||
) | ||
|
||
// cancel task(s) | ||
func cancel(svc tui.TaskService, taskIDs ...resource.ID) tea.Cmd { | ||
var ( | ||
prompt string | ||
cmd tea.Cmd | ||
) | ||
switch len(taskIDs) { | ||
case 0: | ||
return nil | ||
case 1: | ||
prompt = "Cancel task?" | ||
cmd = func() tea.Msg { | ||
if _, err := svc.Cancel(taskIDs[0]); err != nil { | ||
return tui.ErrorMsg(fmt.Errorf("cancelling task: %w", err)) | ||
} | ||
return tui.InfoMsg("sent cancel signal to task") | ||
} | ||
default: | ||
prompt = fmt.Sprintf("Cancel %d tasks?", len(taskIDs)) | ||
cmd = func() tea.Msg { | ||
var errored bool | ||
for _, id := range taskIDs { | ||
if _, err := svc.Cancel(id); err != nil { | ||
errored = true | ||
} | ||
} | ||
if errored { | ||
return tui.ErrorMsg(errors.New("one or more cancel requests failed; see logs")) | ||
} | ||
return tui.InfoMsg(fmt.Sprintf("sent cancel signal to %d tasks", len(taskIDs))) | ||
} | ||
} | ||
return tui.YesNoPrompt(prompt, cmd) | ||
} |
This file contains 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 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 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 |
---|---|---|
|
@@ -6,5 +6,8 @@ terraform { | |
time = { | ||
version = "= 0.11.1" | ||
} | ||
http = { | ||
version = "= 3.4.3" | ||
} | ||
} | ||
} |