Skip to content

Commit 64ef5c5

Browse files
committed
feat: add task scheduler for repitetive tasks
1 parent 0d16d9d commit 64ef5c5

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

task_scheduler/task_scheduler.py

+9-29
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,19 @@
1-
import schedule
21
import time
3-
import logging
4-
5-
# Set up logging
6-
logging.basicConfig(
7-
filename='task_scheduler.log',
8-
level=logging.INFO,
9-
format='%(asctime)s - %(message)s',
10-
datefmt='%Y-%m-%d %H:%M:%S'
11-
)
2+
import schedule
123

13-
# Example task 1: Function to be scheduled
14-
def task_one():
15-
logging.info("Task 1 is running")
4+
def task():
5+
print("Task is being executed")
166

17-
# Example task 2: Another task to be scheduled
18-
def task_two():
19-
logging.info("Task 2 is running")
7+
def task2():
8+
print("Another task is being executed")
209

21-
# Schedule tasks
22-
def setup_schedule():
23-
# Schedule task_one every 10 minutes
24-
schedule.every(10).minutes.do(task_one)
25-
26-
# Schedule task_two every hour
27-
schedule.every().hour.do(task_two)
28-
29-
# Add more tasks here as needed
10+
def run_tasks():
11+
schedule.every(1).minutes.do(task)
12+
schedule.every(2).minutes.do(task2)
3013

31-
# Main loop to keep the scheduler running
32-
def run_scheduler():
33-
setup_schedule()
3414
while True:
3515
schedule.run_pending()
3616
time.sleep(1)
3717

3818
if __name__ == "__main__":
39-
run_scheduler()
19+
run_tasks()

0 commit comments

Comments
 (0)