Add persistent inventory scan job foundation

This commit is contained in:
Joren de Graaf
2026-10-26 01:00:17 +01:00
parent 5217c7f30c
commit a66ecd7c85
9 changed files with 1068 additions and 13 deletions
@@ -0,0 +1,27 @@
import time
from django.core.management.base import BaseCommand
from food.services.inventory_scanner import process_next_scan_item
class Command(BaseCommand):
help = 'Process due persisted kitchen inventory scan enrichment jobs.'
def add_arguments(self, parser):
parser.add_argument('--once', action='store_true', help='Process at most one job and exit.')
parser.add_argument('--poll-seconds', type=float, default=2.0)
parser.add_argument('--max-items', type=int, default=0, help='Stop after this many jobs; 0 runs continuously.')
def handle(self, *args, **options):
processed = 0
while True:
did_work = process_next_scan_item()
if did_work:
processed += 1
if options['once'] or (options['max_items'] and processed >= options['max_items']):
return
elif options['once']:
return
else:
time.sleep(max(0.25, options['poll_seconds']))