Commit Graph

91 Commits

Author SHA1 Message Date
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
2fe6ef9ad6 use go-1.7 on travis 2016-09-26 16:11:18 -07:00
Naitik Shah
053ab5d254 Merge pull request #16 from tabalt/master
fixed a word spelling mistake: pacakge -> package
2015-08-07 14:49:31 -07:00
tabalt
cb0d6e3c43 fixed a word spelling mistake: pacakge -> package 2015-08-04 14:57:06 +08:00
Naitik Shah
91b9915447 fix readme godoc link 2015-06-15 20:35:34 +00:00
Naitik Shah
d683915fca grr. 1.4 import path changes 2015-06-15 20:34:53 +00:00
Naitik Shah
354cd19bcf requrie go 1.4 for TestMain support 2015-06-15 20:28:04 +00:00
Naitik Shah
d2d22699f1 use TestMain and remove external binary 2015-06-15 20:27:40 +00:00
Naitik Shah
2e2aaa0ab8 remove old grace implementation 2015-06-15 20:26:40 +00:00
Naitik Shah
c504619754 update to Additional Grant of Patent Rights Version 2 2015-06-12 18:29:25 +00:00
Naitik Shah
1b0609c25d require go 1.3 now 2014-12-01 12:19:52 -08:00
Naitik Shah
f506214ae8 gracenet and a new version of http.ConnState enabled gracehttp 2014-12-01 12:19:05 -08:00
Naitik Shah
5369e5af9d split cover & race for accurate line numbers 2014-07-10 23:14:31 -07:00
Naitik Shah
39959e963b more elaborate travis setup 2014-07-10 23:02:29 -07:00
Naitik Shah
feb0fe057f go get -t doesn't work on 1.1 2014-05-23 18:32:24 -07:00
Naitik Shah
3aed077b82 need to pull test deps on travis 2014-05-23 18:30:27 -07:00
Naitik Shah
b188da9bd5 use stock travis 2014-05-23 18:28:18 -07:00
Naitik Shah
eca73f0096 internal sync, license update, 1.2 on travis etc 2014-04-02 14:59:39 -07:00
Naitik Shah
ce06322e66 go.grace => grace 2014-04-02 11:53:15 -07:00
Naitik Shah
0a7f677b4a repo move + timeout 2014-04-02 11:52:43 -07:00
Naitik Shah
2d7fb4c06a detect init started on startup rather than when necessary to avoid re-parenting issues. fixes #7 2014-01-06 15:15:45 +05:30
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
bb439ce0e5 Merge pull request #6 from rubyist/master
Unexpected client disconnections can cause a panic and crash the server
2013-11-04 08:50:03 -08:00
rubyist
906a8cad55 Move defer outside the closure 2013-11-04 06:57:07 -05:00
rubyist
43ccb346c3 defer the Done() call 2013-11-03 13:47:47 -05:00
rubyist
c846d177f2 make conn a pointer again 2013-11-03 13:41:56 -05:00
rubyist
1d3eeaacf9 Use sync.Once instead of bool flag 2013-11-03 13:22:18 -05:00
rubyist
e068b65c78 Ensure that the WaitGroup isn't marked done twice when edgecase errors occurr 2013-11-03 13:03:01 -05: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
4636466d77 grace.Process for more options and control 2013-10-24 13:15:29 -07:00
Naitik Shah
e79c66960f doc nit 2013-10-24 12:33:05 -07:00
Naitik Shah
9aca7f00c4 stop signals before we start the graceful stop process 2013-10-15 11:55:48 -07:00
Naitik Shah
d1f693d1d4 refactor gracehttp for readability 2013-10-15 11:54:28 -07:00
Naitik Shah
aad68df4be stop signals once initial term has been processed. fixes #5 2013-10-15 10:50:08 -07:00
Naitik Shah
211c8342b3 use time.Now for timeInPast 2013-10-07 22:57:59 -07:00
Naitik Shah
60b34bd164 comments 2013-10-06 13:01:58 -07:00
Naitik Shah
f5295e5b81 use defer for wg.Done to ensure its called 2013-10-06 12:19:25 -07:00
Naitik Shah
ae3f6c71a7 remove old env variable on restart 2013-10-06 12:14:11 -07:00
Naitik Shah
c0e92551f5 wtf append nil? 2013-10-06 11:33:37 -07:00
Naitik Shah
f2bbd9297e dont need to be TCP specific 2013-10-06 11:25:24 -07:00
Naitik Shah
09bc4c424a dont throw away SetDeadline error 2013-10-06 11:07:31 -07:00
Naitik Shah
70bbce6ad2 dont use named return variables in a strange way 2013-10-06 11:05:27 -07:00
Naitik Shah
61aafa98f8 move inline interface out for readability 2013-10-06 11:00:22 -07:00
Naitik Shah
220ebb1f4f use defer in conn.Close 2013-10-06 10:54:16 -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