Commit Graph

32 Commits

Author SHA1 Message Date
liuyx
39255faa9a feat(grace): 测试多进程监听同一个 fd 2024-04-18 14:09:13 +08:00
Ben Tyler
4afe952a37 Add option for 'StartupHook' (#35)
* Add ServeWithOptions

This adds support for options to be added to 'Serve' and the app struct.
Options are implemented following the 'functional options' pattern
(https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis and
https://commandcenter.blogspot.co.uk/2014/01/self-referential-functions-and-design.html).

Future options can be added by creating an exported func that returns a closure
modifying the app struct, like the following:

    func HaltAndCatchFire(literallyCatchFire bool) option {
        return func(a *app) {
            a.haltAndCatchFire = literallyCatchFire
        }
    }

then in user code:

    gracehttp.ServeWithOptions(
        []*http.Server{ &myServer },
        gracehttp.HaltAndCatchFire(true),
    )

* Add 'StartupHook' option

This option attaches a callback to the application. This callback is triggered
directly before the new process is started during a graceful restart. This
allows the old process to release its hold on any resources that the new
process will need.

For example:

    gracehttp.ServeWithOptions(
        []*http.Server{ &myServer },
        gracehttp.StartupHook(func () error {
            // release port that new process will need to start up successfully
            return nil
        }
    )

* Rename 'StartupHook' to 'PreStartProcess'

This better indicates the timing of the callback by using terms already present
in the codebase. As part of the rename, the related constants in the tests were
fixed to follow the naming convention.
2017-02-18 14:52:39 -08:00
Maksim N
5b49dc98ff Expose logger (#34)
This closes #13 and gives ability to set your own logger with your custom prefixes and other logic.

Done:
- New function `SetLogger` added to be able to set logger
- Flag `gracehttp.log` removed just not to confuse people with logs from nowhere
2017-02-16 14:22:40 -08:00
Alexandre Fiori
5729e48447 Add support for SIGINT (#30)
Closes #28.
2016-09-26 16:17:15 -07:00
Naitik Shah
d2d22699f1 use TestMain and remove external binary 2015-06-15 20:27:40 +00:00
Naitik Shah
f506214ae8 gracenet and a new version of http.ConnState enabled gracehttp 2014-12-01 12:19:05 -08:00
Naitik Shah
39959e963b more elaborate travis setup 2014-07-10 23:02:29 -07:00
Naitik Shah
eca73f0096 internal sync, license update, 1.2 on travis etc 2014-04-02 14:59:39 -07:00
Naitik Shah
0a7f677b4a repo move + timeout 2014-04-02 11:52:43 -07:00
Naitik Shah
ae84a7ab31 fix lint issues 2013-11-07 10:01:43 -08:00
Naitik Shah
fea22b9055 license and readme updates 2013-11-05 17:07:08 -08:00
Naitik Shah
d2b7f5f03a sigh. add sleep for now to avoid connection reset by peer issues 2013-10-24 15:22:03 -07:00
Naitik Shah
e79c66960f doc nit 2013-10-24 12:33:05 -07:00
Naitik Shah
d1f693d1d4 refactor gracehttp for readability 2013-10-15 11:54:28 -07:00
Naitik Shah
e3a666a3f1 more testing and resiliency 2013-10-06 10:38:28 -07:00
Naitik Shah
d69b13103f wait after stop 2013-10-06 10:01:17 -07:00
Naitik Shah
9a444d2674 move build out for shared builds 2013-10-06 09:58:50 -07:00
Naitik Shah
72ccd60490 fix bugs pointed out by go vet 2013-09-18 17:58:04 -07:00
Naitik Shah
267d243f26 ensure correct pid when waiting for server 2013-08-20 13:28:03 -07:00
Naitik Shah
eb6bada57c connection refused errors are expectede 2013-08-20 13:15:00 -07:00
Naitik Shah
8060336110 https support in gracehttp 2013-08-20 11:38:19 -07:00
Naitik Shah
8711fea1ad remove last sleep in test path 2013-08-19 23:12:26 -07:00
Naitik Shah
a4481adb67 remove most unnecessary sleeps from tests 2013-08-19 22:51:32 -07:00
Naitik Shah
2024e37361 flag for debug logging rather than const 2013-08-19 15:39:03 -07:00
Naitik Shah
0b607a2494 mutex for h.Process mutation to prevent data races 2013-08-19 15:37:41 -07:00
Naitik Shah
792bc8817c replace gracehttp.Handler with http.Server for maximum control
this is a backward incompatible change as such. http.Server is a
superset of what gracehttp.Handler was and the fix is trivial.
2013-05-09 09:28:09 -07:00
Naitik Shah
991a4f1f05 fix bug introduced with systemd compatibility 2013-03-25 13:33:16 -07:00
Naitik Shah
5540a9b5d3 systemd socket activation compatibility 2012-09-02 21:21:19 -07:00
Naitik Shah
9e606e1ce8 reckless username change 2012-07-07 14:38:18 -07:00
Naitik Shah
7aa612785a docs and api cleanup 2012-06-04 21:56:51 -07:00
Naitik Shah
13afde4bc1 return errors instead of fataling
probably still need to cleanup coroutines
2012-06-04 21:32:44 -07:00
Naitik Shah
a98138a3e6 clean repo 2012-06-04 22:21:10 +00:00