sigterm/

directory
v6.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2023 License: MIT

README

Vostok/sigterm example

To go back to Vostok: here.


Introduction

The code here should show the implication of being able to handle "graceful shutdowns" of Vostok servers.

In particular, we want to make sure that all of these process types are gracefully stopped:

  • the server's children (handling http requests)
  • the server's scheduled job workers
  • the server's asynchronously running contexts (routines)
  • the server's scheduled batch jobs

Top


Building the project & starting the server

With, for example: GOMODDIR=$HOME/Git/GoModules, go into this example's directory:

cd $GOMODDIR/vostok/examples/sigterm

To build-run directly:

go run ./go

NB: its not recommended to use go run outside of quick testing a code or an example; for apps, its better to go build the go source, then launching the subsequent binary file.

Top


To test

To add new children that will do some work:

curl http://localhost:10101/sigtermexample?action=newSyncWork 

To add new routines :

curl http://localhost:10101/sigtermexample?action=newAsyncWork && ls -la $GOMODDIR/vostok/examples/sigterm/tmp

To add new batch works :

curl http://localhost:10101/sigtermexample?action=newBatchWork && ls -la $GOMODDIR/vostok/examples/sigterm/tmp

To add new geen batch works :

curl http://localhost:10101/sigtermexample/rest/exampleentity/create && ls -la $GOMODDIR/vostok/examples/sigterm/tmp

Each action (except the last one) creates a file in the ./tmp file, which is deleted once the action has correctly finished. So, a successful clean shutdown should lead to an empty ./tmp file.

To make a quick test, do run the following (all at once), and shut down the app right after that:

curl http://localhost:10101/sigtermexample?action=newAsyncWork && ls -la $GOMODDIR/vostok/examples/sigterm/tmp
curl http://localhost:10101/sigtermexample?action=newBatchWork && ls -la $GOMODDIR/vostok/examples/sigterm/tmp
curl http://localhost:10101/sigtermexample/rest/exampleentity/create && ls -la $GOMODDIR/vostok/examples/sigterm/tmp
nohup curl http://localhost:10101/sigtermexample?action=newSyncWork & ls -la $GOMODDIR/vostok/examples/sigterm/tmp

Top


Directories

Path Synopsis
------------------------------------------------------------------------------ Here, we put code that would normally be put into 3 seperate files ------------------------------------------------------------------------------
------------------------------------------------------------------------------ Here, we put code that would normally be put into 3 seperate files ------------------------------------------------------------------------------

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL