stock aggregate table
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* etl_stock_maintenance.php — Called by Node.js scheduler every hour.
|
||||
* Checks and repairs etl_stock_summary for companies in the current slot.
|
||||
*
|
||||
* Body: { slot: 14 } (0–23, = HOUR(NOW()) from Node.js)
|
||||
*/
|
||||
require __DIR__ . '/../assets/utils/cron_auth.php';
|
||||
require_once __DIR__ . '/../assets/utils/classes/EtlStockManager.php';
|
||||
|
||||
$slot = (int)($data['slot'] ?? -1);
|
||||
if ($slot < 0 || $slot > 23) {
|
||||
http_response_code(400);
|
||||
exit(json_encode(['success' => 0, 'message' => 'Invalid slot.']));
|
||||
}
|
||||
|
||||
$sth = $pdo1->prepare(
|
||||
"SELECT company_id FROM company_list WHERE company_id % 24 = :slot"
|
||||
);
|
||||
$sth->execute([':slot' => $slot]);
|
||||
$companies = $sth->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
$results = [];
|
||||
foreach ($companies as $company_id) {
|
||||
try {
|
||||
$etl = new EtlStockManager($pdo2, $pdo1, (int)$company_id);
|
||||
$result = $etl->checkAndRepair();
|
||||
$results[] = [
|
||||
'company_id' => $company_id,
|
||||
'gaps_found' => $result['gaps_found'],
|
||||
'periods_rebuilt' => $result['periods_rebuilt'],
|
||||
];
|
||||
} catch (Exception $e) {
|
||||
$results[] = ['company_id' => $company_id, 'error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
$answer['success'] = 1;
|
||||
$answer['slot'] = $slot;
|
||||
$answer['results'] = $results;
|
||||
exit(json_encode($answer));
|
||||
Reference in New Issue
Block a user