start_autoscaling_worker

Function start_autoscaling_worker 

Source
pub fn start_autoscaling_worker()
Expand description

Starts an autoscaling worker system based on the configured number of concurrent jobs.

This function spawns multiple worker threads—one per configured worker—and continuously polls the database for pending jobs. When a worker retrieves a job, it attempts to execute that job’s logic by deserializing the job’s payload into a type implementing the [JobTrait].

§Behavior

  • Thread Spawning: Spawns max_concurrent_jobs threads as defined in Config::get_config.
  • Polling: Each thread periodically fetches the next pending job via Job::fetch_pending_job.
  • Execution: If a job is found, [execute_job_logic] is called to handle it. If execute_job_logic returns an error, it’s logged, and the worker moves on.
  • Idle Wait: If no job is found or an error occurs, the thread sleeps for the configured tick_rate_ms duration before polling again.

This function does not return; the spawned threads run indefinitely.

§Example

fn main() {
    // Configure your DB and environment
    // ...

    // Start the worker system
    start_autoscaling_worker();

    // The workers will now run in the background
    // ...
}