Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change deactivation approach #2562

Merged
merged 8 commits into from
Aug 18, 2023

Conversation

renatho
Copy link
Contributor

@renatho renatho commented Aug 16, 2023

Changes proposed in this Pull Request

  • We identified an issue that could happen in intervals between syncs (WPJM <> wpjobmanager.com <> JobTarget). It could cause a promotion stop accidentally. The discussion: p1692125471733679-slack-C053397HN30.
  • In order to fix it, we're implementing @fjorgemota's idea to keep all the jobs with _promoted meta key on the feed, even if it's not promoted. To represent it in the feed, we added the promote attribute, which is not currently used but it's useful if we want to iterate in the future, and it makes the endpoint more concise.

The previous issue:

  1. User promote a job, completing the JobTarget checkout.
  2. Before the 5 minutes polling interval (or more if they delay to complete the checkout), the user change something in another promoted jobs triggering a sync (WPJM -> wpjobmanager.com).
  3. Their job would still have _promoted 0 because it didn't sync with the new status yet (wpjobmanager.com -> WPJM). So in the sync WPJM -> wpjobmanager.com, it would remove the job from wpjobmanager.com, removing from the feed that JobTarget will consume, which would deactivate their promotion.

Testing instructions

  • Make sure your env has at least one promote job.
  • Promote a new job, completing the JobTarget checkout.
  • Before the status is updated in WPJM, update another promoted job, and make sure the new job you created wasn't removed from wpjobmanager.com (Check it through WP Admin because the feed has cache, or just clear the cache).
  • On wpjobmanager.com, run the job to update the statuses vip dev-env -- exec wp cron event run wpjobmanager_com_sync_promoted_job_status.
  • Check that the job is marked as promoted on WPJM.
  • Deactivate the job on WPJM job listings, and make sure it was removed from wpjobmanager.com.
  • For another promoted job of your site, update the status to expired (see instructions on https://github.com/Automattic/wpjobmanager.com/pull/579).
  • Make sure the job is marked as not promoted on job listings but continues on the feed of WPJM and wpjobmanager.com.

@renatho renatho requested a review from a team August 16, 2023 18:50
@renatho renatho self-assigned this Aug 16, 2023
Copy link
Member

@fjorgemota fjorgemota left a comment

Choose a reason for hiding this comment

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

Hey there, this is looking good!

I left a couple of comments/suggestions, and I'll test the PR in the meantime. :)

@@ -234,6 +233,7 @@ private function prepare_item_for_response( WP_Post $item ) {
return [
'id' => (string) $item->ID,
'status' => $item->post_status,
'promoted' => WP_Job_Manager_Promoted_Jobs::is_promoted( $item->ID ),
Copy link
Member

Choose a reason for hiding this comment

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

Do you foresee any changes we need to make on WPJMCOM to use this field?

I am just thinking about the use-case here. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, I don't think so. But I added it because it can be useful in the future and make the feed more concise (we don't have promoted and not promoted jobs in the feed without a differentiation).
We could use that, in case we want to list all the promoted jobs as a type of extra promotion, for example.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, thanks!

docs/api/internal.json Outdated Show resolved Hide resolved
renatho and others added 2 commits August 17, 2023 17:08
Copy link
Member

@fjorgemota fjorgemota left a comment

Choose a reason for hiding this comment

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

Looks good and works well! I left a comment for updating a PHPDoc, but everything else seems to be working just fine. Thanks!

@@ -209,6 +209,11 @@ public function handle_promote_job() {
$verify_endpoint_url = rest_url( '/wpjm-internal/v1/promoted-jobs/verify-token', 'https' );
$verify_endpoint_url = substr( $verify_endpoint_url, strlen( $site_url ) );

// Make sure the job contains the promoted job meta to be listed in the feed.
if ( ! $is_editing ) {
WP_Job_Manager_Promoted_Jobs::update_promotion( $post_id, false );
Copy link
Member

Choose a reason for hiding this comment

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

Good catch on setting the flag only if we're creating a new job

@@ -234,6 +233,7 @@ private function prepare_item_for_response( WP_Post $item ) {
return [
'id' => (string) $item->ID,
'status' => $item->post_status,
'promoted' => WP_Job_Manager_Promoted_Jobs::is_promoted( $item->ID ),
Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, thanks!

Comment on lines 153 to 154
* @param bool|string $promoted `true` to promoted, `false` to not promoted, `force_delete` to delete.
* The deletion is used to force a removal from the feed, deactivating the promotion while syncing.
Copy link
Member

Choose a reason for hiding this comment

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

I think we should probably update this PHPDoc, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! Good catch! I updated the previous commit just changing this. ;)
51ebc4b

@renatho renatho force-pushed the change/deactivation-approach branch from 99c974b to 51ebc4b Compare August 18, 2023 13:07
@renatho renatho merged commit 8114ae1 into feature/promoted-jobs Aug 18, 2023
7 checks passed
@renatho renatho deleted the change/deactivation-approach branch August 18, 2023 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants