From e48b4ae6ce17d504179493d64abc108066d37d9e Mon Sep 17 00:00:00 2001 From: Sahil Omkumar Dhillon <118592065+SahilDhillon21@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:11:43 +0530 Subject: [PATCH] Add schedule management commands (#3237) --- website/management/commands/run_daily.py | 23 ++++++++++++++++++++++ website/management/commands/run_hourly.py | 23 ++++++++++++++++++++++ website/management/commands/run_monthly.py | 23 ++++++++++++++++++++++ website/management/commands/run_weekly.py | 23 ++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 website/management/commands/run_daily.py create mode 100644 website/management/commands/run_hourly.py create mode 100644 website/management/commands/run_monthly.py create mode 100644 website/management/commands/run_weekly.py diff --git a/website/management/commands/run_daily.py b/website/management/commands/run_daily.py new file mode 100644 index 000000000..fa3859797 --- /dev/null +++ b/website/management/commands/run_daily.py @@ -0,0 +1,23 @@ +import logging + +from django.core.management.base import BaseCommand + +# from django.core import management +from django.utils import timezone + +logger = logging.getLogger(__name__) + + +class Command(BaseCommand): + help = "Runs commands scheduled to execute daily" + + def handle(self, *args, **options): + try: + logger.info(f"Starting daily scheduled tasks at {timezone.now()}") + + # Add commands to be executed daily + # management.call_command('daily_command1') + # management.call_command('daily_command2') + except Exception as e: + logger.error(f"Error in daily tasks: {str(e)}") + raise diff --git a/website/management/commands/run_hourly.py b/website/management/commands/run_hourly.py new file mode 100644 index 000000000..137b49cde --- /dev/null +++ b/website/management/commands/run_hourly.py @@ -0,0 +1,23 @@ +import logging + +from django.core.management.base import BaseCommand + +# from django.core import management +from django.utils import timezone + +logger = logging.getLogger(__name__) + + +class Command(BaseCommand): + help = "Runs commands scheduled to execute hourly" + + def handle(self, *args, **options): + try: + logger.info(f"Starting hourly scheduled tasks at {timezone.now()}") + + # We can add hourly commands here + # management.call_command('hourly_command1') + # management.call_command('hourly_command2') + except Exception as e: + logger.error(f"Error in hourly tasks: {str(e)}") + raise diff --git a/website/management/commands/run_monthly.py b/website/management/commands/run_monthly.py new file mode 100644 index 000000000..92adf6f73 --- /dev/null +++ b/website/management/commands/run_monthly.py @@ -0,0 +1,23 @@ +import logging + +from django.core.management.base import BaseCommand + +# from django.core import management +from django.utils import timezone + +logger = logging.getLogger(__name__) + + +class Command(BaseCommand): + help = "Runs commands scheduled to execute monthly" + + def handle(self, *args, **options): + try: + logger.info(f"Starting monthly scheduled tasks at {timezone.now()}") + + # Add commands to be executed monthly + # management.call_command('monthly_command1') + # management.call_command('monthly_command2') + except Exception as e: + logger.error(f"Error in monthly tasks: {str(e)}") + raise diff --git a/website/management/commands/run_weekly.py b/website/management/commands/run_weekly.py new file mode 100644 index 000000000..f0221cddb --- /dev/null +++ b/website/management/commands/run_weekly.py @@ -0,0 +1,23 @@ +import logging + +from django.core.management.base import BaseCommand + +# from django.core import management +from django.utils import timezone + +logger = logging.getLogger(__name__) + + +class Command(BaseCommand): + help = "Runs commands scheduled to execute weekly" + + def handle(self, *args, **options): + try: + logger.info(f"Starting weekly scheduled tasks at {timezone.now()}") + + # Add commands to be executed weekly + # management.call_command('weekly_command1') + # management.call_command('weekly_command2') + except Exception as e: + logger.error(f"Error in weekly tasks: {str(e)}") + raise