Skip to content

Commit

Permalink
Merge pull request #998 from Acuspeedster/main
Browse files Browse the repository at this point in the history
feat: add task scheduler for repitetive tasks
  • Loading branch information
pawangeek authored Oct 14, 2024
2 parents d97bd1d + b43c482 commit bcdccd5
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
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()

0 comments on commit bcdccd5

Please sign in to comment.