aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/tasks/consumer.py
blob: c24a883e15f3b0b2be09c47894de91acc6529caf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me>
#
# 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.

    :returns: Configured Huey instance.
    """
    app = create_app()

    for config_key, task in (
        ("SOURCE_SCAN_SCHEDULE", scanner.scan_sources),
        ("VERIFICATION_RECOVERY_SCHEDULE", receiver.recover_stale_verifications),
        ("DIGEST_SCHEDULE", notifications.send_webmention_digest),
        ("RECEIVED_RETENTION_SCHEDULE", retention.purge_old_received_webmentions),
    ):
        schedule = crontab(*app.config[config_key].split(), strict=True)
        queue.periodic_task(schedule)(task)

    return queue.huey


huey = create_consumer()