PreorderBilling

This commit is contained in:
Frank Schubert
2025-03-31 13:50:49 +02:00
parent 21655c5ff4
commit 17405c8c5d
17 changed files with 704 additions and 43 deletions

View File

@@ -5,17 +5,15 @@ if (PHP_SAPI !== 'cli') {
die("This program can only be run on the command line.\n");
}
require("../../config/config.php");
/*
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);
$STDIN = fopen('/dev/null', 'r');
$STDOUT = fopen('/dev/null', 'w');
$STDERR = fopen('/dev/null', 'w');
$STDOUT = fopen(BASEDIR.'/var/log/invoice-job-broker.log', 'w');
$STDERR = fopen(BASEDIR.'/var/log/invoice-job-broker.err.log', 'w');
*/
require("../../config/config.php");
define('mfUI',"cli");
define('FRONKDB_SQLDEBUG',false);
define("MFBASE_BYPASS_LOGIN", true);
@@ -88,7 +86,8 @@ $all_pids = [];
$valid_tasks = [
"make-invoice-pdf",
"send-invoice-email"
"send-invoice-email",
"send-preorder-invoice-email",
];
while(1) {
@@ -171,6 +170,7 @@ while(1) {
//echo "looking for runner for job $taskname\n";
cli_set_process_title($proc["processtitle"]);
$include_name = __DIR__ . "/job-runners/" . $taskname . ".php";
if(!file_exists($include_name)) {
echo "[$mypid] Runner $include_name not found\n";

View File

@@ -0,0 +1,74 @@
<?php
/**
* @var $job InvoiceJob
*/
/*
echo "==========================\n";
echo "in send-preorder-invoice-email-runner\n";
echo "==========================\n";
*/
$started = new DateTime("now");
if(!$job->started) {
$job->started = $started->format("Y-m-d H:i:s");
$job->reconnectDB();
$job->save();
}
$job_return = new stdClass();
$job_return->sent = 0;
$pdfs_sent = 0;
$defer = false;
$timeout = false;
if($job->result) {
$job_return = json_decode($job->result);
if(json_last_error() === JSON_ERROR_NONE) {
$pdfs_sent = $job_return->sent;
} else {
$job_return = new stdClass();
$job_return->sent = 0;
}
}
$ic = new PreorderBillingInvoiceController(false);
$ic->reconnectDB();
// main loop
do {
$now = new DateTime("now");
if($now->format("Y-m-d H:i:s") > $job->to_date." 23:59:59") {
$timeout = true;
break;
}
$email_return = $ic->_sendEmailInvoices(300);
if($email_return["defer"]) {
$defer = true;
}
$sent = $email_return["sent"];
$pdfs_sent += $sent;
$job_return->sent = $pdfs_sent;
$job->result = json_encode($job_return);
//$job->return = json_encode(["sent" => $sent]);
$job->reconnectDB();
$job->save();
} while($sent);
// prepare job update
if($timeout) {
$job->status = "timeout";
} elseif($defer) {
echo "email runner: deferring to next run\n";
$job->status = "defer";
} else {
$finished = new DateTime("now");
$job->finished = $finished->format("Y-m-d H:i:s");
$job->status = "finished";
}
$job->reconnectDB();
$job->save();