Skip to content

Commit 3ca899d

Browse files
committed
Set default task threads, add --address/-a and --port/-p flags
1 parent 92ebbce commit 3ca899d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
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.1"
3+
version = "0.3.2"
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: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def add_arguments(self, parser):
6161
"--tasks",
6262
nargs="?",
6363
type=int,
64-
const=cpus() // 2,
64+
const=default_task_threads,
6565
default=0,
6666
help=f"Number of task runner threads [default={default_task_threads}]",
6767
)
@@ -90,6 +90,19 @@ def add_arguments(self, parser):
9090
dest="periodic",
9191
help="Do not schedule periodic tasks",
9292
)
93+
parser.add_argument(
94+
"-a",
95+
"--address",
96+
default=None,
97+
help="IP address to bind to [default=`127.0.0.1`]",
98+
)
99+
parser.add_argument(
100+
"-p",
101+
"--port",
102+
type=int,
103+
default=None,
104+
help="Port to listen on [default=8000]",
105+
)
93106
parser.add_argument(
94107
"addrport",
95108
nargs="?",
@@ -132,6 +145,7 @@ def handle(self, *args, **options):
132145
port = int(p)
133146
if a := os.getenv("GRANIAN_HOST"):
134147
address = a
148+
135149
# Then check to see if an address/port was specified on the command line.
136150
if options["addrport"].isdigit():
137151
# If specifying a port (but no address), bind to 0.0.0.0.
@@ -144,6 +158,13 @@ def handle(self, *args, **options):
144158
elif options["addrport"]:
145159
address = options["addrport"]
146160

161+
# Finally, override with --address/--port if specified. Necessary because
162+
# `serve -k 9000` will start 9000 workers instead of binding to port 9000.
163+
if a := options["address"]:
164+
address = a
165+
if p := options["port"]:
166+
port = p
167+
147168
reload_paths = []
148169
if path := options["reload"].strip():
149170
reload_paths.append(path)

0 commit comments

Comments
 (0)