An open API service indexing awesome lists of open source software.

https://github.com/chainguard-dev/exitdir

Common packages.
https://github.com/chainguard-dev/exitdir

Last synced: 9 months ago
JSON representation

Common packages.

Awesome Lists containing this project

README

          

# ExitDir

ExitDir is a library to signal a process should exit via the filesystem.

## Usage

To use this library, on the leader process:

```go
package main

import "chainguard.dev/exitdir"

func main() {
// Signal the other processes should exit via a new file in `EXIT_DIR`.
defer exitdir.Exit();
// ...rest of implementation.
}
```

And then one or more follower processes:

```go
package main

import (
"context"

"chainguard.dev/exitdir"
)

func main() {
// Decorate a context with ExitDir awareness. ExitDir will cancel the
// returned context when a new file in `EXIT_DIR` is created.
ctx := exitdir.Aware(context.Background())
// ...rest of implementation using `ctx` for lifecycle control.
}
```

## Process Demo

This functionally is shown locally by using a temp directory and two processes:

```shell
export EXIT_DIR=`mktemp -d`
go run ./cmd/follower &
go run ./cmd/leader
```

Results in:

```shell
$ export EXIT_DIR=`mktemp -d`
$ go run ./cmd/follower &
[1] 83528
$ go run ./cmd/leader
[Leader] Doing work...
[Follower] Tick 0
[Follower] Tick 1
[Follower] Tick 2
[Follower] Tick 3
[Leader] Exiting...
[Follower] Exiting...
[1]+ Done go run ./cmd/follower
$
```

## Kubernetes Demo

Often in Kubernetes a job with multiple containers need to solve a problem of
signaling when to exit. If not coordinated, a resulting hung job looks like a
failure, but in-fact was successful except one container never exited.

```shell
ko apply -f - <