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

MAE-318: Use queue to process memberships #348

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

ahed-compucorp
Copy link
Contributor

@ahed-compucorp ahed-compucorp commented Feb 13, 2021

Overview

The OfflineAutoRenewalJob job is responsible for membership auto-renewal but
there is a timeout issue when many records exist and the admin run the job for the first time on the test site.

Before

Peek 2021-02-13 20-24

After

Peek 2021-02-15 19-41

Technical Details

The feature will help the admin see the job's progress only when he executes it from CiviCRM UI. No change needed to the way we run the job (cv api, drush, HTTP request).

CiviCRM queue has Claim item concept that handles the case when the admin execute the job, and cronjob ran the job during the processing.

These are the keys points of this PR:

  • 1st commit: I found out that any test that explicitly/implicitly calls CRM_Utils_System::currentPath will raise 'Undefined index: q' notice because PHPUnit converts PHP errors, warnings, and notices
    that are triggered during the execution of a test to an exception. I fixed that.
  • 2nd commit: Added @throw line and fix typos in phpdoc.
  • 3rd commit: Refactored getRecurringContributions to return an array of integers instead of an array of arrays because the number of installments is not used.
  • 4th commit: Refactored the job OfflineAutoRenewal to use CiviCRM queue implicitly. I copied everything related as is to preserve the old functionality.
  • 5th commit: Fixed failing tests because of the renamed files.
  • 6th commit: Handled edge case when the job executed twice and the queue got populated with repeated tasks.
  • 7th commit: A message "Failed to claim next task" will appear if we ran an empty queue. This commit handled that.
  • 8th & 9th commits: Refactored the code for more clarity.
  • 10th commit: Created JobLog with the description "Finished execution of Renew offline auto-renewal memberships with result: Success" on completion
  • 11th commit: Added PostRunAllTask as the last task to solve a problem with queue web-runner that show 'Done' message instead of the last task's title.

@erawat
Copy link
Member

erawat commented Feb 13, 2021

@ana-compucorp Nice approach!

Copy link
Member

@erawat erawat left a comment

Choose a reason for hiding this comment

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

@ahed-compucorp

  • Can you explain help more on the first commit on the technical details why we need to set the current path in order to resolve the 'undefined index' error?
  • Can you confirm if schedule job is working properly with cron job as we do not normally run schedule job via the UI. Can you perhaps explain and show some screenshots in the after section?
  • I am not 100% sure which commands that infrastructure team use for running cron either cvapi -u 1 job.execute or URL over http(s). I think it is the best to check with them and update the README they are a couple of cautions regarding schedule job as if we use https(s) it will time out anyway if the queue is large or if we would need to have this schedule job separate from normal CiviCRM corn cc @omarabuhussein

CRM/MembershipExtras/Job/OfflineAutoRenewal.php Outdated Show resolved Hide resolved
@ahed-compucorp ahed-compucorp force-pushed the MAE-318-use-queue-to-process-memberships branch 2 times, most recently from ec3255c to 77d14ee Compare February 15, 2021 15:44
@ahed-compucorp
Copy link
Contributor Author

ahed-compucorp commented Feb 15, 2021

I double-checked the commit Use queue to process memberships. while doing that, I moved any change outside the commit's scope to new commits.

@ahed-compucorp ahed-compucorp force-pushed the MAE-318-use-queue-to-process-memberships branch 4 times, most recently from 5c26873 to 5e73186 Compare February 15, 2021 19:24
@ahed-compucorp
Copy link
Contributor Author

@erawat

Can you explain help more on the first commit on the technical details why we need to set the current path in order to resolve the 'undefined index' error?

Updated the commit message and the PR description to make it more clear.

Can you confirm if schedule job is working properly with cron job?

Yes, and no change needed if you run the job form the cron job.

if we use https(s) it will time out anyway if the queue is large.

Using the http(s) is a bad idea in general, and this PR will help continue processing from where it stopped.

Copy link
Member

@erawat erawat left a comment

Choose a reason for hiding this comment

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

@ahed-compucorp look good to me. I'll leave the final review to @omarabuhussein as we might need second eyes on this.

These test will implicitly call the method
`CRM_Utils_System::currentPath` which will raise 'Undefined index:q'
notice because PHPUnit converts PHP errors, warnings, and notices
that are triggered during the execution of a test to an exception.
A simple array of integers to hold the IDs is enough because the number
of installments is not used.
@ahed-compucorp ahed-compucorp force-pushed the MAE-318-use-queue-to-process-memberships branch from 5e73186 to 1c3d595 Compare February 17, 2021 17:55
Use CiviCRM queue to process the memberships asynchronically to the auto-renewal
job execution if the job triggered from the browser
@ahed-compucorp ahed-compucorp force-pushed the MAE-318-use-queue-to-process-memberships branch from 1c3d595 to 8392754 Compare February 17, 2021 17:58
omarabuhussein
omarabuhussein previously approved these changes Feb 17, 2021
@ahed-compucorp ahed-compucorp force-pushed the MAE-318-use-queue-to-process-memberships branch 2 times, most recently from 0a946b9 to 4ed4543 Compare February 18, 2021 09:32
If the job executed during the execution of the queue, there will be
repeated tasks in the queue and this commit fixed it and only adds tasks
when the queue is empty.
The created folders will hold the related classes and give a better separation.
@ahed-compucorp ahed-compucorp force-pushed the MAE-318-use-queue-to-process-memberships branch from 4ed4543 to c10abcc Compare February 18, 2021 09:34
omarabuhussein
omarabuhussein previously approved these changes Feb 18, 2021
@ahed-compucorp
Copy link
Contributor Author

ahed-compucorp commented Feb 26, 2021

Will wait for #355 to be merged then will rebase this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants