Skip to content

Commit 76a61fb

Browse files
committed
Respect GRANIAN_HOST/PORT env vars
1 parent bfd5598 commit 76a61fb

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "django-dbtasks"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
description = "Database task backend and runner for Django tasks."
55
readme = "README.md"
66
authors = [

src/dbtasks/contrib/serve/management/commands/serve.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def add_arguments(self, parser):
9393
parser.add_argument(
9494
"addrport",
9595
nargs="?",
96-
default="127.0.0.1:8000",
96+
default="",
9797
help="Optional port number, or ipaddr:port [default=`127.0.0.1:8000`]",
9898
)
9999

@@ -122,18 +122,26 @@ def handle(self, *args, **options):
122122
init_periodic=options["periodic"],
123123
)
124124

125-
# With no argument, bind to 127.0.0.1 to match runserver, gunicorn, etc.
126-
# If specifying a port (but no address), bind to 0.0.0.0.
125+
# With no argument, bind to 127.0.0.1:8000 to match runserver, gunicorn, etc.
127126
address = "127.0.0.1"
128127
port = 8000
128+
# Default to the GRANIAN_ environment variables if set.
129+
if p := os.getenv("GRANIAN_PORT"):
130+
# Match gunicorn's behavior of binding to 0.0.0.0 when port is in the env.
131+
address = "0.0.0.0"
132+
port = int(p)
133+
if a := os.getenv("GRANIAN_HOST"):
134+
address = a
135+
# Then check to see if an address/port was specified on the command line.
129136
if options["addrport"].isdigit():
137+
# If specifying a port (but no address), bind to 0.0.0.0.
130138
address = "0.0.0.0"
131139
port = int(options["addrport"])
132140
elif ":" in options["addrport"]:
133141
a, p = options["addrport"].rsplit(":", 1)
134142
address = a or "0.0.0.0"
135143
port = int(p)
136-
else:
144+
elif options["addrport"]:
137145
address = options["addrport"]
138146

139147
reload_paths = []

0 commit comments

Comments
 (0)