Support consumer threads

This commit is contained in:
tcely 2025-06-16 09:33:53 -04:00 committed by GitHub
parent f5a71592fc
commit 2817080d4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,4 @@
import os
from functools import wraps
@ -25,13 +26,21 @@ def h_q_tuple(q, /):
)
def sqlite_tasks(key, /, prefix=None):
def sqlite_tasks(key, /, prefix=None, thread=None, workers=None):
name_fmt = 'huey_{}'
if prefix is None:
prefix = ''
if prefix:
name_fmt = f'huey_{prefix}_' + '{}'
name = name_fmt.format(key)
thread = thread is True
try:
workers = int(workers)
except TypeError:
workers = 2
finally:
if 0 >= workers:
workers = os.cpu_count()
elif 1 == workers:
thread = False
return dict(
huey_class='huey.SqliteHuey',
name=name,
@ -46,8 +55,8 @@ def sqlite_tasks(key, /, prefix=None):
strict_fifo=True,
),
consumer=dict(
workers=1,
worker_type='process',
workers=workers if thread else 1,
worker_type='thread' if thread else 'process',
max_delay=20.0,
flush_locks=True,
scheduler_interval=10,