# SPDX-FileCopyrightText: 2026 Dennis Fink # # SPDX-License-Identifier: BSD-3-Clause """Configure the Huey worker and its scheduled background tasks.""" from huey import Huey, crontab from .. import create_app from ..extensions import huey as queue from . import notifications, receiver, retention, scanner def create_consumer() -> Huey: """Create and configure the Huey consumer. The application is initialized and the periodic scanner, notification, verification recovery and retention tasks are registered. :return: Configured Huey instance. """ app = create_app() schedule = crontab(*app.config["SCANNER_SCHEDULE"].split(), strict=True) queue.periodic_task(schedule)(scanner.scan_sources) recovery_schedule = crontab( *app.config["VERIFICATION_REAPER_SCHEDULE"].split(), strict=True ) queue.periodic_task(recovery_schedule)(receiver.recover_stale_webmentions) notification_schedule = crontab( *app.config["NOTIFICATION_SCHEDULE"].split(), strict=True ) queue.periodic_task(notification_schedule)(notifications.send_webmention_digest) retention_schedule = crontab( *app.config["RECEIVED_RETENTION_SCHEDULE"].split(), strict=True ) queue.periodic_task(retention_schedule)(retention.purge_old_received_webmentions) return queue.huey huey = create_consumer()