Skip to content

Conversation

ankitrox
Copy link

@ankitrox ankitrox commented Aug 30, 2022

Summary

Background job class to manage the life cycle of a background job.

This class is responsible for:

  1. Creation of job in the queue (taxonomy).
  2. Locking/unlocking a particular job.
  3. Job status management (running, failed, complete etc.)
  4. Logging the errors for job.
  5. Data retrieval of a job.

Fixes #503 #479

Relevant technical choices

Checklist

  • PR has either [Focus] or Infrastructure label.
  • PR has a [Type] label.
  • PR has a milestone or the no milestone label.

@ankitrox ankitrox added [Focus] Images no milestone PRs that do not have a defined milestone for release [Type] Epic A high-level project / epic that will encompass several sub-issues [Plugin] Regenerate Existing Images Issues for the Regenerate Existing Images module labels Aug 30, 2022
@ankitrox ankitrox self-assigned this Aug 30, 2022
@ankitrox ankitrox mentioned this pull request Aug 30, 2022
3 tasks
@ankitrox ankitrox marked this pull request as ready for review August 30, 2022 13:02
@ankitrox ankitrox requested a review from jjgrainger as a code owner August 30, 2022 13:02
@ankitrox
Copy link
Author

As of now, there is no update_data method as I did not find the real use case for updating the job data. In some edge case, consumer code can update the data using update_term_meta.
If such scenario to update data arises during development, we can add the method.

CC: @jjgrainger @felixarntz @eugene-manuilov

@ankitrox
Copy link
Author

@eugene-manuilov Thanks for review. Addressed the feedback, requesting re-review.

Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ankitrox Left some reviews with suggestions.

Is a unit test remaining for these changes?

@ankitrox
Copy link
Author

ankitrox commented Sep 1, 2022

@mukeshpanchal27 Added unit tests and addressed the feedback. Re-requesting review.

@felixarntz
Copy link
Member

@ankitrox Left replies to the open comments. Once those iterations have been made, the PR should be good.

@ankitrox ankitrox requested a review from felixarntz September 30, 2022 10:14
Copy link
Contributor

@jjgrainger jjgrainger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ankitrox we're almost there, just followed up on some comments from @felixarntz I think still need to be addressed.

Comment on lines 37 to 48
$this->assertEquals( 'perflab_job_action', constant( $job_class . '::META_KEY_JOB_ACTION' ) );
$this->assertEquals( 'perflab_job_data', constant( $job_class . '::META_KEY_JOB_DATA' ) );
$this->assertEquals( 'perflab_job_attempts', constant( $job_class . '::META_KEY_JOB_ATTEMPTS' ) );
$this->assertEquals( 'perflab_job_lock', constant( $job_class . '::META_KEY_JOB_LOCK' ) );
$this->assertEquals( 'perflab_job_errors', constant( $job_class . '::META_KEY_JOB_ERRORS' ) );
$this->assertEquals( 'perflab_job_status', constant( $job_class . '::META_KEY_JOB_STATUS' ) );
$this->assertEquals( 'perflab_job_completed_at', constant( $job_class . '::META_KEY_JOB_COMPLETED_AT' ) );
$this->assertEquals( 'queued', constant( $job_class . '::JOB_STATUS_QUEUED' ) );
$this->assertEquals( 'running', constant( $job_class . '::JOB_STATUS_RUNNING' ) );
$this->assertEquals( 'partial', constant( $job_class . '::JOB_STATUS_PARTIAL' ) );
$this->assertEquals( 'completed', constant( $job_class . '::JOB_STATUS_COMPLETE' ) );
$this->assertEquals( 'failed', constant( $job_class . '::JOB_STATUS_FAILED' ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ankitrox I agree with @felixarntz here, lets keep it simple and reference the class name directly.

*
* @var Perflab_Background_Job
*/
private $job;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ankitrox have you addressed this?

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ankitrox A few last fixes needed here. Please make sure to address the open comments from previous reviews as well.

Comment on lines 37 to 48
$this->assertEquals( 'perflab_job_action', constant( $job_class . '::META_KEY_JOB_ACTION' ) );
$this->assertEquals( 'perflab_job_data', constant( $job_class . '::META_KEY_JOB_DATA' ) );
$this->assertEquals( 'perflab_job_attempts', constant( $job_class . '::META_KEY_JOB_ATTEMPTS' ) );
$this->assertEquals( 'perflab_job_lock', constant( $job_class . '::META_KEY_JOB_LOCK' ) );
$this->assertEquals( 'perflab_job_errors', constant( $job_class . '::META_KEY_JOB_ERRORS' ) );
$this->assertEquals( 'perflab_job_status', constant( $job_class . '::META_KEY_JOB_STATUS' ) );
$this->assertEquals( 'perflab_job_completed_at', constant( $job_class . '::META_KEY_JOB_COMPLETED_AT' ) );
$this->assertEquals( 'queued', constant( $job_class . '::JOB_STATUS_QUEUED' ) );
$this->assertEquals( 'running', constant( $job_class . '::JOB_STATUS_RUNNING' ) );
$this->assertEquals( 'partial', constant( $job_class . '::JOB_STATUS_PARTIAL' ) );
$this->assertEquals( 'completed', constant( $job_class . '::JOB_STATUS_COMPLETE' ) );
$this->assertEquals( 'failed', constant( $job_class . '::JOB_STATUS_FAILED' ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be addressed.

Comment on lines 53 to 55
public function test_create_job() {
$this->assertInstanceOf( Perflab_Background_Job::class, $this->job );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed as it's not testing any part of the class, but rather the perflab_create_background_job() function, which is already covered by the other test class's test_perflab_create_background_job() method.

Copy link
Contributor

@jjgrainger jjgrainger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ankitrox I've requested a couple of changes here, can you take a look?

*
* @var Perflab_Background_Job
*/
private $job;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ankitrox please can you address or respond to this comment from Felix

No need to have a class property for jobs created in tests. WordPress cleans up pretty much any changes to the database after each tests. So you don't need this property, simply use a local variable per test method - and then you can also remove the unnecessary tear_down() method implementation.

ankitrox and others added 2 commits October 4, 2022 00:14
Co-authored-by: Joe Grainger <904708+jjgrainger@users.noreply.github.com>
@ankitrox
Copy link
Author

ankitrox commented Oct 3, 2022

@ankitrox please can you address or respond to this comment from Felix

@jjgrainger Please refer this comment, according to this comment we will be using $this->job property and will be creating job instance in setUp method.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ankitrox! LGTM, just one tiny nit-pick.

@jjgrainger Could you please re-review as well?

@felixarntz felixarntz requested a review from jjgrainger October 3, 2022 19:06
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ankitrox Left some minor update, not blocker.

ankitrox and others added 3 commits October 4, 2022 14:12
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Copy link
Contributor

@jjgrainger jjgrainger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ankitrox great work here, approved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no milestone PRs that do not have a defined milestone for release [Plugin] Regenerate Existing Images Issues for the Regenerate Existing Images module [Type] Epic A high-level project / epic that will encompass several sub-issues
Projects
None yet
5 participants