Skip to content

Instantly share code, notes, and snippets.

@msaffitz
Created February 11, 2025 18:59
Show Gist options
  • Select an option

  • Save msaffitz/fb65787cf1d65b87e7ef9e19d5c2e25d to your computer and use it in GitHub Desktop.

Select an option

Save msaffitz/fb65787cf1d65b87e7ef9e19d5c2e25d to your computer and use it in GitHub Desktop.
Action Code
class Task:
    def __init__(self, name: str):
        self.name = name
class TaskExecutor:
    def __init__(self, id: int):
        self.id = id
    def execute(self, task: Task):
        """Executes a task and prints which worker processed it"""
        print(f"Worker {self.id} executed {task.name}")
class LoadBalancer:
    def __init__(self, num_workers: int):
        """Distributes tasks to workers in a round-robin fashion"""
        pass
    def submit_task(self, task: Task):
        """Assigns a task to the next available worker"""
        pas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment