sync logs :D

This commit is contained in:
Lars Behrends
2025-10-19 14:54:33 +02:00
parent 7f13b180b9
commit 0f95458466
9 changed files with 184 additions and 35 deletions

View File

@@ -2,20 +2,18 @@
namespace App\Services;
use App\Models\SyncLog;
use Exception;
abstract class BaseSyncService
{
protected \PDO $pdo;
protected array $source;
protected SyncLog $syncLog;
protected int $sourceId;
protected $logFileHandle;
protected $logFilePath;
public function __construct(\PDO $pdo, array $source)
public function __construct(\PDO $pdo, array $source, ?int $existingSyncLogId = null)
{
$this->pdo = $pdo;
$this->source = $source;
@@ -25,6 +23,7 @@ abstract class BaseSyncService
}
$this->sourceId = (int) $source['id'];
$this->currentSyncLogId = $existingSyncLogId;
// Create log file for this sync operation
$this->initializeLogFile();
@@ -62,8 +61,19 @@ abstract class BaseSyncService
ini_set('max_execution_time', 3600); // 1 hour
ini_set('memory_limit', '512M');
// Create sync log entry
$syncLogId = $this->createSyncLog($syncType, 'started');
// Use existing sync log ID if provided, otherwise create a new one
if ($this->currentSyncLogId) {
$syncLogId = $this->currentSyncLogId;
// Update the existing log to 'started' status
$this->updateSyncLog($syncLogId, 'started', [
'sync_type' => $syncType,
'started_at' => date('Y-m-d H:i:s')
]);
} else {
// Create sync log entry
$syncLogId = $this->createSyncLog($syncType, 'started');
}
$this->currentSyncLogId = $syncLogId;
try {