Add PayPal client, donate flow, webhook; wire rules engine with per-goal lock
Replace the static Engine call (which silently failed) with Engine::default() and a MySQL named lock. Add engine->overlay integration test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
65082fb2f5
commit
589e84f28b
21 files changed
+1659
No files matched your search
@@ -17,6 +17,28 @@ final class Engine {
|
||||
/** @var callable():int */
|
||||
private $clock;
|
||||
|
||||
/** Production wiring: $wpdb-backed stores. */
|
||||
public static function default(): self {
|
||||
return new self( new WpRuleStore(), new WpEventStore(), new \StreamGoals\Core\StateStore() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize state updates per goal using a MySQL named lock, so simultaneous captures
|
||||
* (e.g. a raid) cannot lose timer/counter updates. Falls back to running unlocked if the lock is unavailable.
|
||||
*/
|
||||
public static function withGoalLock( int $goalId, callable $fn ): void {
|
||||
global $wpdb;
|
||||
$name = 'sg_goal_' . $goalId;
|
||||
$locked = $wpdb && 1 === (int) $wpdb->get_var( $wpdb->prepare( 'SELECT GET_LOCK(%s, 5)', $name ) );
|
||||
try {
|
||||
$fn();
|
||||
} finally {
|
||||
if ( $locked ) {
|
||||
$wpdb->get_var( $wpdb->prepare( 'SELECT RELEASE_LOCK(%s)', $name ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct(
|
||||
private readonly RuleStore $rules,
|
||||
private readonly EventStore $events,
|
||||
|
||||
Reference in new issue
Block a user