Automate Shopify reconciliation in daily cron
This commit is contained in:
1 parent
e24394866f
commit
bf875f6dea
4 files changed
+85
-3
No files matched your search
@@ -3,6 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../shared/db.php';
|
||||
require_once __DIR__ . '/../erp/lager/forecast.php';
|
||||
require_once __DIR__ . '/../erp/import-integration/shopify-webhook-worker.php';
|
||||
require_once __DIR__ . '/../erp/import-integration/shopify-delta-run.php';
|
||||
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
http_response_code(404);
|
||||
@@ -19,7 +21,25 @@ $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);
|
||||
$runId = shopify_delta_start_run($pdo, $cutoff, false);
|
||||
try {
|
||||
$result = run_shopify_delta($env, $pdo, $cutoff, false);
|
||||
$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),
|
||||
];
|
||||
$results = [];
|
||||
|
||||
Reference in new issue
Block a user