'skipped', 'reason' => 'already_running'], JSON_THROW_ON_ERROR) . PHP_EOL; exit; } $env = expand_env_values(parse_env_file(dirname(__DIR__, 2) . '/.env')); $pdo = connect_database($env); try { $reconciliationStartedAt = new DateTimeImmutable('now', new DateTimeZone('Europe/Zurich')); $jobs = [ 'erp.import-integration.shopify_webhook_worker' => static fn (): array => shopify_webhook_worker_run($pdo, $env, 100), 'erp.import-integration.shopify_delta_order_import' => static function () use ($pdo, $env, $reconciliationStartedAt): array { $cutoff = shopify_delta_reconciliation_cutoff($pdo); $recoveryOrderGids = shopify_delta_load_pending_order_gids($pdo); $runId = shopify_delta_start_run($pdo, $cutoff, false); try { $result = run_shopify_delta($env, $pdo, $cutoff, false, $recoveryOrderGids); $result['technical_run_id'] = $runId; if (($result['status'] ?? '') === 'done') { shopify_delta_store_watermark($pdo, $reconciliationStartedAt->format(DATE_ATOM)); } shopify_delta_finish_run($pdo, $runId, (string) $result['status'], $result); return $result; } catch (Throwable $error) { shopify_delta_finish_run($pdo, $runId, 'failed', ['status' => 'failed', 'technical_run_id' => $runId], $error); throw $error; } }, 'erp.lager.stock_lot_forecast_refresh' => static fn (): array => run_lager_stock_lot_forecast($pdo), 'market_management.occurrence_status_completion' => static fn (): array => market_management_auto_complete_occurrences($pdo), ]; $results = []; foreach ($jobs as $name => $job) { $results[$name] = $job(); } echo json_encode(['status' => 'done', 'jobs' => $results], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL; } catch (Throwable $error) { fwrite(STDERR, $error->getMessage() . PHP_EOL); exit(1); }