mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 15:06:06 +00:00
cs
This commit is contained in:
@@ -35,12 +35,8 @@ use Spatie\Async\Pool;
|
||||
|
||||
class AsyncPoolFactory
|
||||
{
|
||||
private $config;
|
||||
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
public function __construct(private Config $config)
|
||||
{}
|
||||
|
||||
public function isSupported(): bool
|
||||
{
|
||||
|
||||
@@ -37,9 +37,7 @@ use stdClass;
|
||||
class Data
|
||||
{
|
||||
private stdClass $data;
|
||||
|
||||
private ?string $targetId = null;
|
||||
|
||||
private ?string $targetType = null;
|
||||
|
||||
public function __construct(?stdClass $data = null)
|
||||
@@ -50,7 +48,7 @@ class Data
|
||||
/**
|
||||
* Create an instance.
|
||||
*
|
||||
* @param stdClass|array<string,mixed>|null $data Raw data.
|
||||
* @param stdClass|array<string, mixed>|null $data Raw data.
|
||||
* @return self
|
||||
*/
|
||||
public static function create($data = null): self
|
||||
@@ -101,7 +99,6 @@ class Data
|
||||
public function withTargetId(?string $targetId): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
|
||||
$obj->targetId = $targetId;
|
||||
|
||||
return $obj;
|
||||
@@ -110,7 +107,6 @@ class Data
|
||||
public function withTargetType(?string $targetType): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
|
||||
$obj->targetType = $targetType;
|
||||
|
||||
return $obj;
|
||||
|
||||
@@ -38,17 +38,10 @@ class ProcessJobGroup implements Job
|
||||
{
|
||||
private const PORTION_NUMBER = 100;
|
||||
|
||||
private JobManager $jobManager;
|
||||
|
||||
private Config $config;
|
||||
|
||||
public function __construct(
|
||||
JobManager $jobManager,
|
||||
Config $config
|
||||
) {
|
||||
$this->jobManager = $jobManager;
|
||||
$this->config = $config;
|
||||
}
|
||||
private JobManager $jobManager,
|
||||
private Config $config
|
||||
) {}
|
||||
|
||||
public function run(Data $data): void
|
||||
{
|
||||
|
||||
@@ -29,10 +29,7 @@
|
||||
|
||||
namespace Espo\Core\Job\Job\Jobs;
|
||||
|
||||
use Espo\Core\{
|
||||
Job\QueueName,
|
||||
Job\Job\Jobs\AbstractQueueJob,
|
||||
};
|
||||
use Espo\Core\Job\QueueName;
|
||||
|
||||
class ProcessJobQueueE0 extends AbstractQueueJob
|
||||
{
|
||||
|
||||
@@ -29,10 +29,7 @@
|
||||
|
||||
namespace Espo\Core\Job\Job\Jobs;
|
||||
|
||||
use Espo\Core\{
|
||||
Job\QueueName,
|
||||
Job\Job\Jobs\AbstractQueueJob,
|
||||
};
|
||||
use Espo\Core\Job\QueueName;
|
||||
|
||||
class ProcessJobQueueQ0 extends AbstractQueueJob
|
||||
{
|
||||
|
||||
@@ -29,10 +29,7 @@
|
||||
|
||||
namespace Espo\Core\Job\Job\Jobs;
|
||||
|
||||
use Espo\Core\{
|
||||
Job\QueueName,
|
||||
Job\Job\Jobs\AbstractQueueJob,
|
||||
};
|
||||
use Espo\Core\Job\QueueName;
|
||||
|
||||
class ProcessJobQueueQ1 extends AbstractQueueJob
|
||||
{
|
||||
|
||||
@@ -32,12 +32,8 @@ namespace Espo\Core\Job\Job;
|
||||
class Status
|
||||
{
|
||||
public const PENDING = 'Pending';
|
||||
|
||||
public const READY = 'Ready';
|
||||
|
||||
public const RUNNING = 'Running';
|
||||
|
||||
public const SUCCESS = 'Success';
|
||||
|
||||
public const FAILED = 'Failed';
|
||||
}
|
||||
|
||||
@@ -35,19 +35,11 @@ use Espo\Core\Utils\ClassFinder;
|
||||
|
||||
class JobFactory
|
||||
{
|
||||
private ClassFinder $classFinder;
|
||||
private InjectableFactory $injectableFactory;
|
||||
private MetadataProvider $metadataProvider;
|
||||
|
||||
public function __construct(
|
||||
ClassFinder $classFinder,
|
||||
InjectableFactory $injectableFactory,
|
||||
MetadataProvider $metadataProvider
|
||||
) {
|
||||
$this->classFinder = $classFinder;
|
||||
$this->injectableFactory = $injectableFactory;
|
||||
$this->metadataProvider = $metadataProvider;
|
||||
}
|
||||
private ClassFinder $classFinder,
|
||||
private InjectableFactory $injectableFactory,
|
||||
private MetadataProvider $metadataProvider
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Create a job by a scheduled job name.
|
||||
@@ -68,6 +60,7 @@ class JobFactory
|
||||
|
||||
/**
|
||||
* Create a job by a class name.
|
||||
*
|
||||
* @param class-string<Job|JobDataLess> $className
|
||||
* @return Job|JobDataLess
|
||||
*/
|
||||
|
||||
@@ -30,10 +30,8 @@
|
||||
namespace Espo\Core\Job;
|
||||
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
use Espo\Core\Utils\DateTime;
|
||||
use Espo\Core\Job\Job\Data;
|
||||
|
||||
use Espo\Entities\Job as JobEntity;
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
@@ -36,12 +36,8 @@ use Espo\Core\InjectableFactory;
|
||||
*/
|
||||
class JobSchedulerFactory
|
||||
{
|
||||
private $injectableFactory;
|
||||
|
||||
public function __construct(InjectableFactory $injectableFactory)
|
||||
{
|
||||
$this->injectableFactory = $injectableFactory;
|
||||
}
|
||||
public function __construct(private InjectableFactory $injectableFactory)
|
||||
{}
|
||||
|
||||
public function create(): JobScheduler
|
||||
{
|
||||
|
||||
@@ -29,14 +29,13 @@
|
||||
|
||||
namespace Espo\Core\Job;
|
||||
|
||||
use Espo\Core\{
|
||||
Application,
|
||||
ApplicationRunners\Job as JobRunner,
|
||||
Application\Runner\Params as RunnerParams,
|
||||
};
|
||||
|
||||
use Spatie\Async\Task as AsyncTask;
|
||||
|
||||
use Espo\Core\Application;
|
||||
use Espo\Core\Application\Runner\Params as RunnerParams;
|
||||
use Espo\Core\ApplicationRunners\Job as JobRunner;
|
||||
use Espo\Core\Utils\Log;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class JobTask extends AsyncTask
|
||||
@@ -52,8 +51,7 @@ class JobTask extends AsyncTask
|
||||
* @return void
|
||||
*/
|
||||
public function configure()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
@@ -62,20 +60,15 @@ class JobTask extends AsyncTask
|
||||
{
|
||||
$app = new Application();
|
||||
|
||||
$params = RunnerParams::fromArray([
|
||||
'id' => $this->jobId,
|
||||
]);
|
||||
$params = RunnerParams::fromArray(['id' => $this->jobId]);
|
||||
|
||||
try {
|
||||
$app->run(JobRunner::class, $params);
|
||||
}
|
||||
catch (Throwable $e) {
|
||||
/** @var \Espo\Core\Utils\Log $log */
|
||||
$log = $app->getContainer()->get('log');
|
||||
$log = $app->getContainer()->getByClass(Log::class);
|
||||
|
||||
$log->error(
|
||||
"JobTask: Failed to run job '{$this->jobId}'. Error: " . $e->getMessage()
|
||||
);
|
||||
$log->error("JobTask: Failed to run job '{$this->jobId}'. Error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,12 +33,8 @@ use Espo\Core\Utils\Metadata;
|
||||
|
||||
class MetadataProvider
|
||||
{
|
||||
private Metadata $metadata;
|
||||
|
||||
public function __construct(Metadata $metadata)
|
||||
{
|
||||
$this->metadata = $metadata;
|
||||
}
|
||||
public function __construct(private Metadata $metadata)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
|
||||
@@ -31,15 +31,8 @@ namespace Espo\Core\Job\Preparator;
|
||||
|
||||
class Data
|
||||
{
|
||||
private $id;
|
||||
|
||||
private $name;
|
||||
|
||||
public function __construct(string $id, string $name)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
}
|
||||
public function __construct(private string $id, private string $name)
|
||||
{}
|
||||
|
||||
/**
|
||||
* A scheduled job ID.
|
||||
|
||||
@@ -42,12 +42,8 @@ use DateTimeImmutable;
|
||||
|
||||
class ProcessJobGroupPreparator implements Preparator
|
||||
{
|
||||
private $entityManager;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
public function __construct(private EntityManager $entityManager)
|
||||
{}
|
||||
|
||||
public function prepare(Data $data, DateTimeImmutable $executeTime): void
|
||||
{
|
||||
|
||||
@@ -34,14 +34,10 @@ use Espo\Core\Exceptions\Error;
|
||||
|
||||
class PreparatorFactory
|
||||
{
|
||||
private MetadataProvider $metadataProvider;
|
||||
private InjectableFactory $injectableFactory;
|
||||
|
||||
public function __construct(MetadataProvider $metadataProvider, InjectableFactory $injectableFactory)
|
||||
{
|
||||
$this->metadataProvider = $metadataProvider;
|
||||
$this->injectableFactory = $injectableFactory;
|
||||
}
|
||||
public function __construct(
|
||||
private MetadataProvider $metadataProvider,
|
||||
private InjectableFactory $injectableFactory
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Create a preparator.
|
||||
|
||||
@@ -33,20 +33,14 @@ use Espo\Core\Utils\Config;
|
||||
|
||||
class QueuePortionNumberProvider
|
||||
{
|
||||
private Config $config;
|
||||
|
||||
/**
|
||||
* @var array<string,int>
|
||||
*/
|
||||
/** @var array<string, int> */
|
||||
private $queueNumberMap = [
|
||||
QueueName::Q0 => self::Q0_PORTION_NUMBER,
|
||||
QueueName::Q1 => self::Q1_PORTION_NUMBER,
|
||||
QueueName::E0 => self::E0_PORTION_NUMBER,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array<string,string>
|
||||
*/
|
||||
/** @var array<string, string> */
|
||||
private $queueParamNameMap = [
|
||||
QueueName::Q0 => 'jobQ0MaxPortion',
|
||||
QueueName::Q1 => 'jobQ1MaxPortion',
|
||||
@@ -54,17 +48,12 @@ class QueuePortionNumberProvider
|
||||
];
|
||||
|
||||
private const Q0_PORTION_NUMBER = 200;
|
||||
|
||||
private const Q1_PORTION_NUMBER = 500;
|
||||
|
||||
private const E0_PORTION_NUMBER = 100;
|
||||
|
||||
private const DEFAULT_PORTION_NUMBER = 200;
|
||||
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
public function __construct(private Config $config)
|
||||
{}
|
||||
|
||||
public function get(string $queue): int
|
||||
{
|
||||
@@ -75,4 +64,4 @@ class QueuePortionNumberProvider
|
||||
$this->queueNumberMap[$queue] ??
|
||||
self::DEFAULT_PORTION_NUMBER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,12 +33,8 @@ use Espo\Core\InjectableFactory;
|
||||
|
||||
class QueueProcessorFactory
|
||||
{
|
||||
private $injectableFactory;
|
||||
|
||||
public function __construct(InjectableFactory $injectableFactory)
|
||||
{
|
||||
$this->injectableFactory = $injectableFactory;
|
||||
}
|
||||
public function __construct(private InjectableFactory $injectableFactory)
|
||||
{}
|
||||
|
||||
public function create(QueueProcessorParams $params): QueueProcessor
|
||||
{
|
||||
|
||||
@@ -58,28 +58,14 @@ class ScheduleProcessor
|
||||
'* * * * * *',
|
||||
];
|
||||
|
||||
private Log $log;
|
||||
private EntityManager $entityManager;
|
||||
private QueueUtil $queueUtil;
|
||||
private ScheduleUtil $scheduleUtil;
|
||||
private PreparatorFactory $preparatorFactory;
|
||||
private MetadataProvider $metadataProvider;
|
||||
|
||||
public function __construct(
|
||||
Log $log,
|
||||
EntityManager $entityManager,
|
||||
QueueUtil $queueUtil,
|
||||
ScheduleUtil $scheduleUtil,
|
||||
PreparatorFactory $preparatorFactory,
|
||||
MetadataProvider $metadataProvider
|
||||
) {
|
||||
$this->log = $log;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->queueUtil = $queueUtil;
|
||||
$this->scheduleUtil = $scheduleUtil;
|
||||
$this->preparatorFactory = $preparatorFactory;
|
||||
$this->metadataProvider = $metadataProvider;
|
||||
}
|
||||
private Log $log,
|
||||
private EntityManager $entityManager,
|
||||
private QueueUtil $queueUtil,
|
||||
private ScheduleUtil $scheduleUtil,
|
||||
private PreparatorFactory $preparatorFactory,
|
||||
private MetadataProvider $metadataProvider
|
||||
) {}
|
||||
|
||||
public function process(): void
|
||||
{
|
||||
|
||||
@@ -29,23 +29,17 @@
|
||||
|
||||
namespace Espo\Core\Job;
|
||||
|
||||
use Espo\Core\Utils\DateTime as DateTimeUtil;
|
||||
use Espo\Core\ORM\Repository\Option\SaveOption;
|
||||
use Espo\ORM\Collection;
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
use Espo\Core\Utils\DateTime as DateTimeUtil;
|
||||
|
||||
use Espo\Entities\ScheduledJob as ScheduledJobEntity;
|
||||
use Espo\Entities\ScheduledJobLogRecord as ScheduledJobLogRecordEntity;
|
||||
|
||||
class ScheduleUtil
|
||||
{
|
||||
private EntityManager $entityManager;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
public function __construct(private EntityManager $entityManager)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Get active scheduled job list.
|
||||
|
||||
Reference in New Issue
Block a user