diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2019-06-29 01:19:21 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2019-06-29 01:19:21 +0300 |
commit | 01eeeaf5e136928abe75f95d58f3f9cce11c6fe6 (patch) | |
tree | 700f9a5106a51ce1f8b35475c84a7bafac162313 /README.md | |
parent | 741cf397a9150a8f76b8f74289b1dde8aaa43d02 (diff) |
Release.v1.0.0
Auto listen OS signal (with mixin)
Policies: ...Fail -> ...Error
Diffstat (limited to 'README.md')
-rwxr-xr-x | README.md | 36 |
1 files changed, 26 insertions, 10 deletions
@@ -7,7 +7,7 @@ Package Rutina (russian "рутина" - ordinary boring everyday work) is routi It seems like https://godoc.org/golang.org/x/sync/errgroup with some different: 1) propagates context to every routines. So routine can check if context stopped (`ctx.Done()`). -2) has flexible run/stop policy. i.e. one routine restarts when it fails (useful on daemons) but if fails another - all routines will be cancelled +2) has flexible run/stop policy. i.e. one routine restarts when it errors (useful on daemons) but if errors another - all routines will be cancelled 3) already has optional signal handler `ListenOsSignals()` ## When it need? @@ -42,16 +42,16 @@ r.Go(func (ctx context.Context) error { Available options of run policy: -* `ShutdownIfFail` - Shutdown all routines if this routine fails -* `RestartIfFail` - Restart this routine if it fail -* `DoNothingIfFail` - Do nothing just stop this routine if it fail +* `ShutdownIfError` - Shutdown all routines if this routine returns error +* `RestartIfError` - Restart this routine if this routine returns error +* `DoNothingIfError` - Do nothing just stop this routine if this routine returns error * `ShutdownIfDone` - Shutdown all routines if this routine done without errors * `RestartIfDone` - Restart if this routine done without errors * `DoNothingIfDone` - Do nothing if this routine done without errors Default policy: -`ShutdownIfFail` && `ShutdownIfDone` +`ShutdownIfError` && `ShutdownIfDone` (just like [errgroup](https://godoc.org/golang.org/x/sync/errgroup)) @@ -61,17 +61,17 @@ Default policy: r.Go(func(ctx context.Context) error { // If this routine produce no error - it just restarts // If it returns error - all other routines will shutdown (because context cancels) -}, rutina.RestartIfDone, rutina.ShutdownIfFail) +}, rutina.RestartIfDone, rutina.ShutdownIfError) r.Go(func(ctx context.Context) error { // If this routine produce no error - it just completes // If it returns error - all other routines will shutdown (because context cancels) -}, rutina.DoNothingIfDone, rutina.ShutdownIfFail) +}, rutina.DoNothingIfDone, rutina.ShutdownIfError) r.Go(func(ctx context.Context) error { // If this routine produce no error - all other routines will shutdown (because context cancels) // If it returns error - it will be restarted -}, rutina.RestartIfFail) +}, rutina.RestartIfError) r.Go(func(ctx context.Context) error { // If this routine stopped by any case - all other routines will shutdown (because context cancels) @@ -103,10 +103,10 @@ Rutina has own simple lifecycle events: * `EventRoutineStart` - Fires when starts new routine * `EventRoutineStop` - Fires when routine stopped with any result * `EventRoutineComplete` - Fires when routine stopped without errors -* `EventRoutineFail` - Fires when routine stopped with error +* `EventRoutineError` - Fires when routine stopped with error * `EventAppStop` - Fires when all routines stopped with any result * `EventAppComplete` - Fires when all routines stopped with no errors -* `EventAppFail` - Fires when all routines stopped with error +* `EventAppError` - Fires when all routines stopped with error ## Mixins @@ -151,6 +151,22 @@ err := <- r.Errors() Turn on errors channel +### Lifecycle listener + +```go +r = r.With(rutina.WithLifecycleListener(func (event rutina.Event, rid int) { ... })) +``` + +Simple lifecycle listener + +### Auto listen OS signals + +```go +r = r.With(rutina.WithListenOsSignals()) +``` + +Automatically listen OS signals. There is no `r.ListenOsSignals()` needed. + ## Example HTTP server with graceful shutdown [`example/http_server.go`](https://github.com/NeonXP/rutina/blob/master/example/http_server.go) |