gl aggregate table (ETL), cronjob by NODEJS

This commit is contained in:
Thanakorn S
2026-05-23 10:52:27 +07:00
parent 9c275eb358
commit f5ea74e134
15 changed files with 1048 additions and 230 deletions
+43
View File
@@ -0,0 +1,43 @@
<?php
/**
* etl_gl_maintenance.php — Called by Node.js scheduler every hour.
* Checks and repairs etl_gl_summary (GL summary) for companies in the current slot.
* For stock ETL maintenance use etl_stock_maintenance.php (not yet implemented).
*
* Body: { slot: 14 } (0–23, = HOUR(NOW()) from Node.js)
*/
require '../../assets/utils/cron_auth.php';
require_once '../../assets/utils/classes_ac/EtlManager.php';
$slot = (int)($data['slot'] ?? -1);
if ($slot < 0 || $slot > 23) {
http_response_code(400);
exit(json_encode(['success' => 0, 'message' => 'Invalid slot.']));
}
// Fetch companies whose slot matches this hour
$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 EtlManager($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));