Skip to content

Conversation

@Codelax
Copy link
Member

@Codelax Codelax commented Nov 19, 2022

This is an helper library that allows to split a command in tasks and print the execution to the user, this also provides a way to cleanup after a failed task

Usage:

ts := tasks.Begin()
ts.AddWithCleanUp("Creating container namespace", func(i interface{}) (interface{}, interface{}, error) {
	time.Sleep(time.Second)
	return i, "data", nil
}, func(i interface{}) error {
	// i == "data"
	fmt.Println("clean " + i.(string)
	return nil
})
ts.Add("Creating container", func(i interface{}) (interface{}, error) {
	time.Sleep(time.Second * 2)
	return i, fmt.Errorf("error")
})
ts.Add("Pushing image", func(i interface{}) (interface{}, error) {
	time.Sleep(time.Second * 3)
	return i, nil
})
ts.Add("Deploying", func(i interface{}) (interface{}, error) {
	time.Sleep(time.Second * 3)
	return i, nil
})

Result:

[1/4] Creating container namespace
[2/4] Creating container
<cool interactive loading spinner>

then

[1/4] Creating container namespace
[2/4] Creating container
task failed, cleaning up created resources
[1/4] Cleaning task "Creating container namespace"
clean data
Task 2 "Creating container" failed: error

@codecov-commenter
Copy link

codecov-commenter commented Nov 19, 2022

Codecov Report

Merging #2596 (128eafe) into master (a04acb7) will increase coverage by 0.00%.
The diff coverage is 77.90%.

@@           Coverage Diff           @@
##           master    #2596   +/-   ##
=======================================
  Coverage   74.58%   74.59%           
=======================================
  Files         142      144    +2     
  Lines       28716    28802   +86     
=======================================
+ Hits        21417    21484   +67     
- Misses       6558     6576   +18     
- Partials      741      742    +1     
Impacted Files Coverage Δ
internal/tasks/tasks.go 75.64% <75.64%> (ø)
internal/tasks/loader.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@remyleone remyleone changed the title Task loading feat(core): add support for composite tasks Dec 1, 2022
@Codelax
Copy link
Member Author

Codelax commented Dec 14, 2022

Tasks states could be stored, this state could be exported to terraform state

quantumsheep
quantumsheep previously approved these changes Mar 9, 2023
@remyleone remyleone added this pull request to the merge queue Mar 10, 2023
Merged via the queue into scaleway:master with commit 12c3b1e Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants