1
0
Files
breadcrumb-the-shire/lib/Repository/Scheduler/SchedulerRuntimeRepository.php
fs f4ce9f3378 docs: add class docblocks, business-rule comments, and transaction wrapper
- Add single-line class docblocks to all 59 repository classes and interfaces
  describing scope and responsibility
- Add multi-line docblocks to key services documenting business rules:
  AuthService (6-step login cascade), ImportService (3-phase CSV workflow),
  TenantScopeService (strict/permissive modes), PermissionService (RBAC
  resolution + two-tier caching), UserAccountService (atomicity + audit)
- Add transaction(callable) wrapper to DatabaseSessionRepository to DRY up
  begin/commit/rollback boilerplate

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 21:58:51 +01:00

52 lines
1.7 KiB
PHP

<?php
namespace MintyPHP\Repository\Scheduler;
use MintyPHP\DB;
use MintyPHP\Domain\Taxonomy\SchedulerRuntimeResult;
/** Tracks scheduler daemon heartbeat, result codes, and error state. */
class SchedulerRuntimeRepository implements SchedulerRuntimeRepositoryInterface
{
public function touchHeartbeat(string $result, ?string $errorCode = null, ?string $heartbeatAtUtc = null): bool
{
$heartbeatAtUtc = trim((string) ($heartbeatAtUtc ?? ''));
if ($heartbeatAtUtc === '') {
$heartbeatAtUtc = gmdate('Y-m-d H:i:s');
}
$result = SchedulerRuntimeResult::normalizeOr($result, SchedulerRuntimeResult::Ok)->value;
$errorCode = $this->nullableTrim($errorCode);
$updated = DB::update(
'insert into scheduler_runtime_status (id, last_heartbeat_at, last_result, last_error_code) ' .
'values (1, ?, ?, ?) ' .
'on duplicate key update ' .
'last_heartbeat_at = values(last_heartbeat_at), ' .
'last_result = values(last_result), ' .
'last_error_code = values(last_error_code)',
$heartbeatAtUtc,
$result,
$errorCode
);
return $updated !== false;
}
public function findStatus(): ?array
{
$row = DB::selectOne('select * from scheduler_runtime_status where id = 1 limit 1');
if (!is_array($row)) {
return null;
}
$item = $row['scheduler_runtime_status'] ?? $row;
return is_array($item) ? $item : null;
}
private function nullableTrim(?string $value): ?string
{
$value = trim((string) $value);
return $value !== '' ? $value : null;
}
}