Skip to content

Background process runner#498

Closed
ankitrox wants to merge 11 commits intofeature/regenerate-existing-imagesfrom
background-process-runner
Closed

Background process runner#498
ankitrox wants to merge 11 commits intofeature/regenerate-existing-imagesfrom
background-process-runner

Conversation

@ankitrox
Copy link
Copy Markdown

@ankitrox ankitrox commented Aug 26, 2022

Background process runner class.

Mainly responsible for handling and validating the heavy lifting tasks in background without hampering the user experience.

Summary

Fixes #482 #494

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.

BG process placeholder class
@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 26, 2022
@ankitrox ankitrox self-assigned this Aug 26, 2022
@ankitrox ankitrox linked an issue Aug 26, 2022 that may be closed by this pull request
2 tasks
Copy link
Copy Markdown
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 I think this PR is a bit too much all at once. Let's work in smaller units, to be able to have focused reviews and not block multiple items because of having them in one PR.

Your PR currently tackles #482, #494, and also #503. Can you please reduce this (or open a new PR with the code instead) which only focuses on #503? We should always try to have one PR for one issue. Of course, don't completely delete the other code, but let's split that into multiple PRs. I believe the first one should be the PR for #503 since that is the most foundational part of the three.

Copy link
Copy Markdown
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.

Left some quick feedback.

*/
public function __construct() {
add_action( 'wp_ajax_' . Perflab_Background_Process::BG_PROCESS_ACTION, array( $this, 'handle_request' ) );
add_action( 'wp_ajax_nopriv' . Perflab_Background_Process::BG_PROCESS_ACTION, array( $this, 'handle_request' ) );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
add_action( 'wp_ajax_nopriv' . Perflab_Background_Process::BG_PROCESS_ACTION, array( $this, 'handle_request' ) );
add_action( 'wp_ajax_nopriv_' . Perflab_Background_Process::BG_PROCESS_ACTION, array( $this, 'handle_request' ) );

/**
* Class Perflab_Background_Job.
*
* Runs the heavy lifting tasks in background in separate process.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add @since n.e.x.t

/**
* Meta key for storing job name/action.
*
* @const string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/**
* Perflab_Background_Job constructor.
*
* @param int $job_id job ID.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add @since n.e.x.t for all the functions.

* @param string $name Job identifier or name.
* @param array $data Job data.
*
* @since n.e.x.t
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As per document standard https://developer.wordpress.org/coding-standards/inline-documentation-standards/php/#4-hooks-actions-and-filters you should add @since before the parameter document.

Comment on lines +38 to +39
add_action( 'wp_ajax_' . Perflab_Background_Process::BG_PROCESS_ACTION, array( $this, 'handle_request' ) );
add_action( 'wp_ajax_nopriv' . Perflab_Background_Process::BG_PROCESS_ACTION, array( $this, 'handle_request' ) );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the same file class file, we should use self::. It should be updated in other places as well. 

Suggested change
add_action( 'wp_ajax_' . Perflab_Background_Process::BG_PROCESS_ACTION, array( $this, 'handle_request' ) );
add_action( 'wp_ajax_nopriv' . Perflab_Background_Process::BG_PROCESS_ACTION, array( $this, 'handle_request' ) );
add_action( 'wp_ajax_' . self::BG_PROCESS_ACTION, array( $this, 'handle_request' ) );
add_action( 'wp_ajax_nopriv' . self::BG_PROCESS_ACTION, array( $this, 'handle_request' ) );

@ankitrox
Copy link
Copy Markdown
Author

Thanks for the review @mukeshpanchal27 .

As per discussion with @felixarntz , I have created a separate (and smaller) PR background job class: #507

So, this PR will be closed and further work will be continued in those smaller chunks. Please consider to review those new PRs.

@jjgrainger
Copy link
Copy Markdown
Contributor

Closing to avoid confusion with another open PR

@jjgrainger jjgrainger closed this Sep 8, 2022
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

4 participants