Files

30 lines
1.1 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* Cron: retry failed Mailchimp / Sinch deliveries and purge expired leads.
*
* cPanel → Cron Jobs → every 5 minutes:
* VISIT_PRIVATE_DIR=/home/USER/visit-private /usr/local/bin/php /home/USER/visit.waterschurch.org/api/cron/retry-integrations.php >> /home/USER/visit-private/logs/cron.log 2>&1
*
* CLI only — web requests are refused by the .htaccess in this folder AND by the guard below.
*/
declare(strict_types=1);
if (PHP_SAPI !== 'cli') {
http_response_code(404);
exit;
}
require_once dirname(__DIR__) . '/lib/bootstrap.php';
require_once dirname(__DIR__) . '/lib/LeadProcessor.php';
$lock = fopen(Config::dataDir() . '/retry.lock', 'c');
if (!$lock || !flock($lock, LOCK_EX | LOCK_NB)) {
fwrite(STDOUT, gmdate('c') . " retry: another run is in progress\n");
exit(0);
}
$result = LeadProcessor::retryDue(Config::int('RETRY_BATCH_SIZE', 25));
$purged = LeadProcessor::purgeExpired();
fwrite(STDOUT, sprintf("%s retry: checked=%d processed=%d purged=%d mode=%s\n", gmdate('c'), $result['checked'], $result['processed'], $purged, Config::mode()));
flock($lock, LOCK_UN);