@@ -130,20 +130,29 @@ private function performMailmanRequest(
130130 * Acquire sync lock.
131131 *
132132 * To ensure that the sync between GEWISDB and Mailman is as clean as possible, we need to acquire a global lock on
133- * the mail list administration. This will prevent (if properly implemented and used) the secretary from modifying
134- * any mailing list memberships.
133+ * the mail list administration. This will prevent (if properly implemented and used) concurrent syncs from running.
135134 */
136- private function acquireSyncLock (int $ retries = 3 ): void
137- {
135+ private function acquireSyncLock (
136+ int $ retries = 3 ,
137+ bool $ renew = false ,
138+ ): void {
138139 if (0 === $ retries ) {
139140 throw new RuntimeException ('Unable to acquire sync lock for Mailman sync: timeout. ' );
140141 }
141142
142- if ($ this ->isSyncLocked ()) {
143+ if ($ this ->isSyncLocked () && ! $ renew ) {
143144 throw new RuntimeException ('Unable to acquire sync lock for Mailman sync: locked by other process. ' );
144145 }
145146
146- $ this ->configService ->setConfig (ConfigNamespaces::DatabaseMailman, 'locked ' , true );
147+ if (!$ this ->isSyncLocked () && $ renew ) {
148+ throw new RuntimeException ('Unable to renew sync lock for Mailman sync: currently unlocked. ' );
149+ }
150+
151+ $ this ->configService ->setConfig (
152+ ConfigNamespaces::DatabaseMailman,
153+ 'locked ' ,
154+ (new DateTime ())->modify ('+23 hours ' ),
155+ );
147156
148157 if ($ this ->isSyncLocked ()) {
149158 return ;
@@ -159,15 +168,15 @@ private function acquireSyncLock(int $retries = 3): void
159168 */
160169 private function releaseSyncLock (): void
161170 {
162- $ this ->configService ->setConfig (ConfigNamespaces::DatabaseMailman, 'locked ' , false );
171+ $ this ->configService ->setConfig (ConfigNamespaces::DatabaseMailman, 'locked ' , new DateTime () );
163172 }
164173
165174 /**
166175 * Get state of sync lock.
167176 */
168177 public function isSyncLocked (): bool
169178 {
170- return $ this ->configService ->getConfig (ConfigNamespaces::DatabaseMailman, 'locked ' , false );
179+ return $ this ->configService ->getConfig (ConfigNamespaces::DatabaseMailman, 'locked ' ) > new DateTime ( );
171180 }
172181
173182 /**
@@ -185,6 +194,7 @@ public function syncMembership(
185194 $ lists = $ this ->mailingListMapper ->findAll ();
186195
187196 foreach ($ lists as $ list ) {
197+ $ this ->acquireSyncLock (renew: true );
188198 $ this ->syncMembershipSingle ($ list , $ output , $ dryRun );
189199 }
190200
0 commit comments