From 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 25 Aug 2026 22:57:22 +0000
Subject: [PATCH] =It's been a minute. I went through the Routes and associated Managers and ensured they played together well. Reworked the Cache.php, and I think I caught all the references. Moving away from JVBase() root class, to individuall classes that are Instanced. Double checked for the ABSPATH check in every file, and added index.php to every directory that didn't already have it. Also still working on the MenuBlock to work with WooCommerce for now for Northeh

---
 inc/managers/queue/Locker.php |   61 ++++++++++--------------------
 1 files changed, 20 insertions(+), 41 deletions(-)

diff --git a/inc/managers/queue/Locker.php b/inc/managers/queue/Locker.php
index cd527ad..4d4b5d6 100644
--- a/inc/managers/queue/Locker.php
+++ b/inc/managers/queue/Locker.php
@@ -1,65 +1,44 @@
 <?php
 namespace JVBase\managers\queue;
+
 if (!defined('ABSPATH')) {
 	exit;
 }
-
 class Locker
 {
 	private string $lockKey;
-	private int $ttl;
+	private int $timeout;
 	private ?string $token = null;
 
-	public function __construct(string $key = 'queue_processor', int $ttl = 300)
+	public function __construct(string $key = 'queue', int $timeout = 60)
 	{
-		$this->lockKey = BASE . '_lock_' . $key;
-		$this->ttl = $ttl;
+		$this->lockKey = BASE . $key . '_lock';
+		$this->timeout = $timeout;
 	}
 
-	public function acquire(): bool
+	public function withLock(callable $callback): void
 	{
-		// Generate unique token for this process
-		$this->token = uniqid(gethostname() . '_', true);
+		if (!$this->acquire()) return;
 
-		// SET NX with TTL - atomic "set if not exists"
-		$result = wp_cache_add($this->lockKey, $this->token, 'locks', $this->ttl);
-
-		return $result === true;
-	}
-
-	public function release(): void
-	{
-		if (!$this->token) {
-			return;
+		try {
+			$callback();
+		} finally {
+			$this->unlock();
 		}
+	}
 
-		// Only release if we own the lock
+	private function acquire(): bool
+	{
+		$this->token = bin2hex(random_bytes(8));
+		return (bool) wp_cache_add($this->lockKey, $this->token, 'locks', $this->timeout);
+	}
+
+	public function unlock(): void
+	{
 		$current = wp_cache_get($this->lockKey, 'locks');
 		if ($current === $this->token) {
 			wp_cache_delete($this->lockKey, 'locks');
 		}
-
 		$this->token = null;
 	}
-
-	public function isLocked(): bool
-	{
-		return wp_cache_get($this->lockKey, 'locks') !== false;
-	}
-
-	/**
-	 * Execute callback with lock, auto-release after
-	 */
-	public function withLock(callable $callback): mixed
-	{
-		if (!$this->acquire()) {
-			return null;
-		}
-
-		try {
-			return $callback();
-		} finally {
-			$this->release();
-		}
-	}
 }

--
Gitblit v1.10.0