Random Task Execution Scheduler

  • Share this:

Code introduction


This code uses the Schedule library to randomly execute a task. Each task is a lambda function, including random number generation, checking system uptime, string word count, temperature conversion, and string reversal.


Technology Stack : The code uses the Schedule library, along with lambda functions, random number generation, system uptime checking, string word counting, temperature conversion, and string reversal.

Code Type : The type of code

Code Difficulty : Advanced


                
                    
import random
import schedule
import time

def random_task():
    tasks = {
        "task1": lambda: print("Task 1: Random number generation"),
        "task2": lambda: print("Task 2: Check system uptime"),
        "task3": lambda: print("Task 3: Count words in a string"),
        "task4": lambda: print("Task 4: Convert temperature from Celsius to Fahrenheit"),
        "task5": lambda: print("Task 5: Reverse a string")
    }
    
    selected_task = random.choice(list(tasks.keys()))
    tasks[selected_task]()

def schedule_task():
    schedule.every().hour.do(random_task)
    
    while True:
        schedule.run_pending()
        time.sleep(1)

# Code Information