compucorp / uk.co.compucorp.membershipextras

Membership Extras for CiviCRM
Other
5 stars 8 forks source link

CIVIIB-11: Allow only one instance of auto-renewal job to run #446

Closed omarabuhussein closed 2 years ago

omarabuhussein commented 2 years ago

Overview

Here we only allow once instance of the autorenewal job to run at any given time, given the renewal might happen more than one time for the same membership if the autorenewal happen to run multiple times simultaneously.

Before

Multiple instances of the autorenewal job could run at the same time, which might cause the same membership to be renewed multiple times.

After

Only once instance of the autorenewal job can run at any given time:

22222

An error saying:

Could not acquire lock, another Offline Autorenewal process is running

would show in the job logs for any other instance tries to run while there is a one t hat is already running.

Technical Details

I've used CiviCRM lock manager Civi::lockManager() to acquire a lock on the first instance that runs, and that lock is only released when job is done running.