Skip to content

feat: add task scheduler for repitetive tasks #998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions task_scheduler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

# Automated Task Scheduler for Repetitive Tasks

This script is designed to automate repetitive tasks by scheduling them at predefined intervals using Python's `schedule` library. It logs task execution, making it easy to track the status of scheduled jobs.

## Functionalities

- Schedule and automate repetitive tasks.
- Log task execution to a file for monitoring and debugging.
- Customizable task functions to fit user needs.

## Setup Instructions

1. **Clone the repository:**
```bash
git clone <repo-link>
```

2. **Navigate to the project directory:**
```bash
cd automated-task-scheduler
```

3. **Install the required dependencies:**
```bash
pip install -r requirements.txt
```

4. **Run the script:**
```bash
python task_scheduler.py
```

## Detailed Explanation of Script

- **Task Functions:** `task_one` and `task_two` are sample tasks. You can modify these functions to suit your automation needs.

- **Scheduling:** The script schedules `task_one` to run every 10 minutes and `task_two` to run every hour using the `schedule` library. You can adjust these intervals in the `setup_schedule()` function.

- **Logging:** Each task's execution is logged in the `task_scheduler.log` file with timestamps, providing visibility into when tasks were run.

- **Main Loop:** The script continuously runs in an infinite loop (`run_scheduler()`), checking for pending tasks and executing them at the scheduled times.

## Output

The script generates a `task_scheduler.log` file, which logs the execution of tasks like this:

```
2024-10-13 12:00:00 - Task 1 is running
2024-10-13 12:10:00 - Task 1 is running
2024-10-13 13:00:00 - Task 2 is running
```

## Author(s)

- ARNAV RAJ

## Disclaimers

- Ensure that the script is running continuously in the background for tasks to execute as scheduled.
- The `schedule` library is suitable for lightweight task scheduling. For more complex scheduling requirements, consider using a task queue like Celery or a cron job.
2 changes: 2 additions & 0 deletions task_scheduler/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schedule==1.1.0
pandas==1.2.0
23 changes: 23 additions & 0 deletions task_scheduler/task_scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import time
import schedule


def task():
print("Task is being executed")


def task2():
print("Another task is being executed")


def run_tasks():
schedule.every(1).minutes.do(task)
schedule.every(2).minutes.do(task2)

while True:
schedule.run_pending()
time.sleep(1)


if __name__ == "__main__":
run_tasks()