import random
import time
import threading


# This could be a consumer function, which is invoked when a new RabbitMQ message arrives.
def busy_process(id):
    print("Processing message ID: " + str(id))

    loop_count = 1000
    for outer in range(0, loop_count):
        for inner in range(0, loop_count):
            random_sum = outer + inner

    print("Finished processing the message bearing ID: " + str(id))

# This could be a callback function which the RabbitMQ invokes when a message arrives.
# However, we need to limit max. amount of concurrent threads that can execute.
def execute_busy_processes():
    # Generating a new job id for the task.
    job_id = random.randint(1, 100)
    new_thread = threading.Thread(target=busy_process, args=(job_id,))
    new_thread.start()

if __name__ == "__main__":
    # Simulate a new log message coming.
    for new_message in range(0, 10000):
        execute_busy_processes()
