Write a thread-safe worker queue in Python that processes tasks using Celery-like logic, handling graceful shutdowns and retries at Peregrine Technologies.
Implement process_tasks(tasks, worker_count, max_retries). Each task is a dictionary with a unique task_id and failures_before_success, which simulates how many attempts fail before success. Return results in input order, including each task ID, final status, and total attempts. Workers must use a thread-safe queue, retry failed tasks up to max_retries, wait for all queued work to finish, and then shut down cleanly.
Input values are valid and failures_before_success is nonnegative.
def process_tasks(tasks, worker_count, max_retries):