Skip to content

Commit 2d4f89b

Browse files
refactor: extract resolveAndRemember method for improved readability and error handling
1 parent acedb63 commit 2d4f89b

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

ProcessMaker/Services/ProcessVariableDiscoveryService.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,7 @@ private function refresh(string $cacheKey, string $lastKnownKey, callable $resol
227227
}
228228

229229
try {
230-
$payload = $resolver();
231-
Cache::put($lastKnownKey, $payload, self::LAST_KNOWN_SECONDS);
232-
233-
return $payload;
234-
} catch (Throwable $exception) {
235-
Log::warning('Process variable discovery failed', [
236-
'message' => $exception->getMessage(),
237-
]);
238-
239-
return is_array($lastKnown) ? $lastKnown : [];
230+
return $this->resolveAndRemember($lastKnownKey, $lastKnown, $resolver);
240231
} finally {
241232
$lock->release();
242233
}
@@ -260,7 +251,28 @@ private function waitForLock($lock, string $lastKnownKey, $lastKnown, callable $
260251
}
261252

262253
// No last-known-good payload: resolve directly so we do not cache an empty result.
263-
return $resolver();
254+
return $this->resolveAndRemember($lastKnownKey, $lastKnown, $resolver);
255+
}
256+
}
257+
258+
/**
259+
* @param mixed $lastKnown
260+
* @param callable(): list<array<string, mixed>> $resolver
261+
* @return list<array<string, mixed>>
262+
*/
263+
private function resolveAndRemember(string $lastKnownKey, $lastKnown, callable $resolver): array
264+
{
265+
try {
266+
$payload = $resolver();
267+
Cache::put($lastKnownKey, $payload, self::LAST_KNOWN_SECONDS);
268+
269+
return $payload;
270+
} catch (Throwable $exception) {
271+
Log::warning('Process variable discovery failed', [
272+
'message' => $exception->getMessage(),
273+
]);
274+
275+
return is_array($lastKnown) ? $lastKnown : [];
264276
}
265277
}
266278

0 commit comments

Comments
 (0)