Skip to content

Commit bcdccd5

Browse files
authored
Merge pull request #998 from Acuspeedster/main
feat: add task scheduler for repitetive tasks
2 parents d97bd1d + b43c482 commit bcdccd5

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

task_scheduler/README.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
# Automated Task Scheduler for Repetitive Tasks
3+
4+
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.
5+
6+
## Functionalities
7+
8+
- Schedule and automate repetitive tasks.
9+
- Log task execution to a file for monitoring and debugging.
10+
- Customizable task functions to fit user needs.
11+
12+
## Setup Instructions
13+
14+
1. **Clone the repository:**
15+
```bash
16+
git clone <repo-link>
17+
```
18+
19+
2. **Navigate to the project directory:**
20+
```bash
21+
cd automated-task-scheduler
22+
```
23+
24+
3. **Install the required dependencies:**
25+
```bash
26+
pip install -r requirements.txt
27+
```
28+
29+
4. **Run the script:**
30+
```bash
31+
python task_scheduler.py
32+
```
33+
34+
## Detailed Explanation of Script
35+
36+
- **Task Functions:** `task_one` and `task_two` are sample tasks. You can modify these functions to suit your automation needs.
37+
38+
- **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.
39+
40+
- **Logging:** Each task's execution is logged in the `task_scheduler.log` file with timestamps, providing visibility into when tasks were run.
41+
42+
- **Main Loop:** The script continuously runs in an infinite loop (`run_scheduler()`), checking for pending tasks and executing them at the scheduled times.
43+
44+
## Output
45+
46+
The script generates a `task_scheduler.log` file, which logs the execution of tasks like this:
47+
48+
```
49+
2024-10-13 12:00:00 - Task 1 is running
50+
2024-10-13 12:10:00 - Task 1 is running
51+
2024-10-13 13:00:00 - Task 2 is running
52+
```
53+
54+
## Author(s)
55+
56+
- ARNAV RAJ
57+
58+
## Disclaimers
59+
60+
- Ensure that the script is running continuously in the background for tasks to execute as scheduled.
61+
- 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.

task_scheduler/requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
schedule==1.1.0
2+
pandas==1.2.0

task_scheduler/task_scheduler.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import time
2+
import schedule
3+
4+
5+
def task():
6+
print("Task is being executed")
7+
8+
9+
def task2():
10+
print("Another task is being executed")
11+
12+
13+
def run_tasks():
14+
schedule.every(1).minutes.do(task)
15+
schedule.every(2).minutes.do(task2)
16+
17+
while True:
18+
schedule.run_pending()
19+
time.sleep(1)
20+
21+
22+
if __name__ == "__main__":
23+
run_tasks()

0 commit comments

Comments
 (0)