Skip to content

scheduled_tasks

Module with functions used to execute scheduled tasks.

See https://panel.holoviz.org/how_to/callbacks/schedule.html for details.

Modules:

Name Description
cloud

Module with functions to interact with GCP storage service.

core
models

Module with database tables definitions.

Functions:

Name Description
clean_files_db

Return a callable object for cleaning temporary tables and files.

reset_guest_user_password

Return a callable object for resetting guest user password.

upload_db_to_gcp_storage

Return a callable object for uploading database to google cloud storage.

Attributes:

Name Type Description
log Logger

Module logger.

log module-attribute

log: Logger = getLogger(__name__)

Module logger.

clean_files_db

clean_files_db(config: DictConfig) -> callable

Return a callable object for cleaning temporary tables and files.

Parameters:

Name Type Description Default
config DictConfig

Hydra configuration dictionary.

required

Returns:

Type Description
callable

function to be scheduled.

Source code in dlunch/scheduled_tasks.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def clean_files_db(config: DictConfig) -> callable:
    """Return a callable object for cleaning temporary tables and files.

    Args:
        config (DictConfig): Hydra configuration dictionary.

    Returns:
        callable: function to be scheduled.
    """

    async def scheduled_function() -> None:
        """Clean menu, orders, users and flags tables. Delete also local files."""
        log.info(f"clean task (files and db) executed at {dt.datetime.now()}")
        # Delete files
        core.delete_files(config)
        # Clean tables
        core.clean_tables(config)

    return scheduled_function

reset_guest_user_password

reset_guest_user_password(config: DictConfig) -> callable

Return a callable object for resetting guest user password.

Parameters:

Name Type Description Default
config DictConfig

Hydra configuration dictionary.

required

Returns:

Type Description
callable

function to be scheduled.

Source code in dlunch/scheduled_tasks.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def reset_guest_user_password(config: DictConfig) -> callable:
    """Return a callable object for resetting guest user password.

    Args:
        config (DictConfig): Hydra configuration dictionary.

    Returns:
        callable: function to be scheduled.
    """

    async def scheduled_function() -> None:
        """Reset guest user password."""
        log.info(f"reset guest user password executed at {dt.datetime.now()}")
        # Change reset flag
        models.set_flag(
            config=config, id="reset_guest_user_password", value=True
        )
        # Reset password
        core.set_guest_user_password(config)

    return scheduled_function

upload_db_to_gcp_storage

upload_db_to_gcp_storage(
    config: DictConfig, **kwargs
) -> callable

Return a callable object for uploading database to google cloud storage.

Parameters:

Name Type Description Default
config DictConfig

Hydra configuration dictionary.

required

Returns:

Type Description
callable

function to be scheduled.

Source code in dlunch/scheduled_tasks.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def upload_db_to_gcp_storage(config: DictConfig, **kwargs) -> callable:
    """Return a callable object for uploading database to google cloud storage.

    Args:
        config (DictConfig): Hydra configuration dictionary.

    Returns:
        callable: function to be scheduled.
    """

    async def scheduled_function() -> None:
        """Upload database to GCP storage."""
        log.info(
            f"upload database to gcp storage executed at {dt.datetime.now()}"
        )
        # Upload database
        cloud.upload_to_gcloud(**kwargs)

    return scheduled_function