Skip to content

Create Background Processing Infrastructure: Perflab_Background_Process class #482

@mxbclang

Description

@mxbclang

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.
  1. Set the start time
    A $start_time variable is set using the current timestamp as the value.

  2. 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
  1. 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
  1. 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 ) )

  1. Unlock process
    Outside of the while loop, to end the process, unlock the job by removing the job_lock term meta.

  2. 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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions