OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
45
app/Domain/Cron/Controllers/Run.php
Normal file
45
app/Domain/Cron/Controllers/Run.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Cron\Controllers;
|
||||
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Core\Events\EventDispatcher;
|
||||
use Leantime\Domain\Cron\Services\Cron as CronService;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class Run extends Controller
|
||||
{
|
||||
private CronService $cronService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(CronService $cronService): void
|
||||
{
|
||||
$this->cronService = $cronService;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Poor Man's Cron Endpoint.
|
||||
*
|
||||
* Registers a terminate listener that runs the scheduled tasks after the response is sent,
|
||||
* then immediately returns an empty response so the client connection can close.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get(array $params): Response
|
||||
{
|
||||
EventDispatcher::add_event_listener(
|
||||
'leantime.core.http.httpkernel.terminate.request_terminated',
|
||||
fn () => $this->cronService->runScheduledTasks()
|
||||
);
|
||||
|
||||
return tap(new Response, function ($response) {
|
||||
$response->headers->set('Content-Length', '0');
|
||||
$response->headers->set('Connection', 'close');
|
||||
});
|
||||
}
|
||||
}
|
||||
54
app/Domain/Cron/Services/Cron.php
Normal file
54
app/Domain/Cron/Services/Cron.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Cron\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Leantime\Core\Configuration\Environment;
|
||||
use Leantime\Core\Console\ConsoleKernel;
|
||||
use Leantime\Core\Events\DispatchesEvents;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
class Cron
|
||||
{
|
||||
use DispatchesEvents;
|
||||
|
||||
private Environment $environment;
|
||||
|
||||
public function __construct(Environment $environment)
|
||||
{
|
||||
$this->environment = $environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the scheduled tasks (poor man's cron) after the HTTP response has been sent.
|
||||
*
|
||||
* Encapsulates the deferred-execution orchestration: it disables the user-abort and
|
||||
* execution-time limits, runs Laravel's `schedule:run` command through the console kernel,
|
||||
* and registers a shutdown function that logs the scheduler output when debug mode is enabled.
|
||||
*
|
||||
* @return int The exit code returned by the `schedule:run` command.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function runScheduledTasks(): int
|
||||
{
|
||||
ignore_user_abort(true);
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$output = new BufferedOutput;
|
||||
$consoleKernel = app()->make(ConsoleKernel::class);
|
||||
$result = $consoleKernel->call('schedule:run', [], $output);
|
||||
|
||||
register_shutdown_function(function () use ($output) {
|
||||
if ($this->environment->debug) {
|
||||
Log::info('Cron Schedule Output: '.$output->fetch());
|
||||
}
|
||||
});
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user