-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capture OS signals while steps executed and perform cleanups as grace…
…ful shutdown Summary: Here is my ~~first~~ new attempt to use channels to keep track of step results, errors or OS signals. # Design overview We could use channels to communicate results and errors produced from TTP steps executed. Having this, we might also check additional channel to check if an OS signal was received. This requires changes in the following parts: 0. Steps execution 0. Step results retrieving 0. Clean up execution for steps completed only 0. Sub-TTP processing 0. Proper setup of execution context object per sub-ttp 0. Postponing clean up execution till all steps of root TTP are completed or an error encountered Resolves #476 Reviewed By: d3sch41n Differential Revision: D54117726 fbshipit-source-id: aed5abe03534679f0c74c542e0607607ac149a45
- Loading branch information
1 parent
ff176b6
commit 9d547bf
Showing
15 changed files
with
285 additions
and
117 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
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
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
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,61 @@ | ||
/* | ||
Copyright © 2023-present, Meta Platforms, Inc. and affiliates | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
package blocks | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
"sync" | ||
"syscall" | ||
|
||
"github.com/facebookincubator/ttpforge/pkg/logging" | ||
) | ||
|
||
var signalHandlerInstalled bool | ||
var signalHandlerLock = sync.Mutex{} | ||
var shutdownChan chan bool | ||
|
||
// SetupSignalHandler sets up SIGINT and SIGTERM handlers for graceful shutdown | ||
func SetupSignalHandler() chan bool { | ||
// setup signal handling only once | ||
signalHandlerLock.Lock() | ||
if signalHandlerInstalled { | ||
signalHandlerLock.Unlock() | ||
return shutdownChan | ||
} | ||
sigs := make(chan os.Signal, 2) | ||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | ||
shutdownChan = make(chan bool, 1) | ||
signalHandlerInstalled = true | ||
signalHandlerLock.Unlock() | ||
|
||
go func() { | ||
var sig os.Signal | ||
var counter int | ||
for { | ||
sig = <-sigs | ||
logging.L().Infof("[%v] Received signal %v, shutting down now", counter, sig) | ||
shutdownChan <- true | ||
counter++ | ||
} | ||
}() | ||
|
||
return shutdownChan | ||
} |
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
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
Oops, something went wrong.