Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 4381dec

Browse files
authored
Make ServerState.shutting_down into an enum (#594)
This is more extensible and should've been done all along.
1 parent c4a815d commit 4381dec

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

baseplate/server/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
import argparse
77
import configparser
8+
import enum
89
import fcntl
910
import gc
1011
import importlib
@@ -20,6 +21,7 @@
2021
import warnings
2122

2223
from dataclasses import dataclass
24+
from enum import Enum
2325
from types import FrameType
2426
from typing import Any
2527
from typing import Callable
@@ -34,6 +36,7 @@
3436
from gevent.server import StreamServer
3537

3638
from baseplate import Baseplate
39+
from baseplate.lib import warn_deprecated
3740
from baseplate.lib.config import Endpoint
3841
from baseplate.lib.config import EndpointConfiguration
3942
from baseplate.lib.config import Optional as OptionalConfig
@@ -47,9 +50,19 @@
4750
logger = logging.getLogger(__name__)
4851

4952

53+
class ServerLifecycle(Enum):
54+
RUNNING = enum.auto()
55+
SHUTTING_DOWN = enum.auto()
56+
57+
5058
@dataclass
5159
class ServerState:
52-
shutting_down: bool = False
60+
state: ServerLifecycle = ServerLifecycle.RUNNING
61+
62+
@property
63+
def shutting_down(self) -> bool:
64+
warn_deprecated("SERVER_STATE.shutting_down is deprecated in favor of SERVER_STATE.state")
65+
return self.state == ServerLifecycle.SHUTTING_DOWN
5366

5467

5568
SERVER_STATE = ServerState()
@@ -266,7 +279,7 @@ def load_app_and_run_server() -> None:
266279
try:
267280
shutdown_event.wait()
268281

269-
SERVER_STATE.shutting_down = True
282+
SERVER_STATE.state = ServerLifecycle.SHUTTING_DOWN
270283

271284
if cfg.drain_time:
272285
logger.debug("Draining inbound requests...")

0 commit comments

Comments
 (0)