Skip to content

Simplify the job assigner

Cal Pratt requested to merge cpratt34/job-assigner-refactor into master

This MR greatly simplifies the Job Assigner class.

Instead of having a mutable state associated with each bot to be updated, the mapping is simply a bot_name and corresponding threading.Event which is provided to the listener. When the job assigner calls assign_n_leases, we no longer pass in a callback method to validate the bot state.. instead we look to the database for answers, locking both the jobs as well as the bot sessions entries we will be mutating. This allows us to create most of the state update in a single transaction up front. When the job is updated in the database, the event is triggered after the updates are committed. When the listener receives the event, they then query the database to get the most up to date information regarding the job.

I believe this also solves a long-standing bug in the jobassigner logic with a race-condition causing the lease to be updated by the session prior to changes from the assigner being committed to the database. Now session threads will only be notified after transactions have been completed. I've taken off the @flaky markers from the tests so we can start getting an idea if the issue still persists.

Merge request reports