Skip to content

Create Background Processing Infrastructure: Create Status Cron Event #484

@mxbclang

Description

@mxbclang

Create a Status Cron Event to check jobs are running correctly and remove old completed jobs.

Acceptance Criteria

Cron Schedule

  • Scheduled a new event using the wp_schedule_event function.
  • The event is scheduled with the following parameters
    • timestamp: time()
    • recurrence: hourly
    • hook: perflab_background_process_status_check

Event hook
Create a new function for the perflab_background_process_status_check hook that checks the following

Check jobs are running correctly

  • Query jobs that are currently running with get_terms
  • Retrieve running jobs by querying for terms with the job_status meta and the value running.
  • If no terms are returned continue to next check.
  • If terms are passed, loop over each term and check the following:
    • Retrieve the job_lock term meta value
    • Check the job_lock value against the ini_get( 'max_execution_time' )
    • If the job_lock meta exists and the value is less than the max_execution_time continue to the next term
    • If the job_lock meta does not exist or the value is greater the max_execution_time restart the job by calling perflab_start_background_job passing the $job_id

Remove old completed jobs

  • Query jobs that are currently running with get_terms
  • Retrieve running jobs by querying for terms with the job_status meta and the value completed.
  • If no terms are returned exit early.
  • If terms are passed, loop over each term and check the following:
    • Retrieve the job_completed_at term meta value
    • If the job_completed_at meta exists and the timestamp value is older than 7 days, the term is deleted.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions