Create Perflab_Background_Process::run method
Create a new a Perflab_Background_Process class to handle the background process runs.
This class will contain other helper methods for running jobs the background process built out in other issues.
Acceptance Criteria
- Create a new
run( int $job_id ) method in the Perflab_Background_Process class.
- The method will run through the following steps sequentially.
-
Set the start time
A $start_time variable is set using the current timestamp as the value.
-
Lock the process
- The job process is locked by setting a term meta against the job term. The meta key will be
job_lock and the value the current timestamp.
- The job status is also updated by setting the
job_status meta to running
- Retrieve the job information
Using the $job_id passed to the run method get the following information.
$job - Create a new Job object using the Perflab_Background_Job class
$job_name this is the the job terms slug
$job_data this is from the job_data term meta
- Call the job action
Within a do/while loop call do_action( 'perflab_job_' . $job_name, $job_id, $job_data );
The while loop conditions will call the following like so:
while( ! $this->memory_exceeded() && ! $this->time_exceeded() && ! $job->is_completed( $job_id ) )
-
Unlock process
Outside of the while loop, to end the process, unlock the job by removing the job_lock term meta.
-
Start the next batch process
Start the next batch process by calling the function perflab_background_process_next_batch() passing the $job_id as the only parameter.
Create Perflab_Background_Process::run method
Create a new a
Perflab_Background_Processclass to handle the background process runs.This class will contain other helper methods for running jobs the background process built out in other issues.
Acceptance Criteria
run( int $job_id )method in thePerflab_Background_Processclass.Set the start time
A
$start_timevariable is set using the current timestamp as the value.Lock the process
job_lockand the value the current timestamp.job_statusmeta torunningUsing the
$job_idpassed to therunmethod get the following information.$job- Create a new Job object using thePerflab_Background_Jobclass$job_namethis is the the job terms slug$job_datathis is from thejob_dataterm metaWithin a do/while loop call
do_action( 'perflab_job_' . $job_name, $job_id, $job_data );The while loop conditions will call the following like so:
while( ! $this->memory_exceeded() && ! $this->time_exceeded() && ! $job->is_completed( $job_id ) )Unlock process
Outside of the while loop, to end the process, unlock the job by removing the
job_lockterm meta.Start the next batch process
Start the next batch process by calling the function
perflab_background_process_next_batch()passing the$job_idas the only parameter.