type fixes
This commit is contained in:
@@ -36,11 +36,11 @@ use stdClass;
|
||||
|
||||
class Data
|
||||
{
|
||||
private $data;
|
||||
private stdClass $data;
|
||||
|
||||
private $targetId = null;
|
||||
private ?string $targetId = null;
|
||||
|
||||
private $targetType = null;
|
||||
private ?string $targetType = null;
|
||||
|
||||
public function __construct(?stdClass $data = null)
|
||||
{
|
||||
@@ -50,7 +50,7 @@ class Data
|
||||
/**
|
||||
* Create an instance.
|
||||
*
|
||||
* @param stdClass|array|null $data Raw data.
|
||||
* @param stdClass|array<string,mixed>|null $data Raw data.
|
||||
* @return self
|
||||
*/
|
||||
public static function create($data = null): self
|
||||
|
||||
@@ -29,18 +29,17 @@
|
||||
|
||||
namespace Espo\Core\Job\Job\Jobs;
|
||||
|
||||
use RuntimeException;
|
||||
use Espo\Core\Job\JobDataLess;
|
||||
use Espo\Core\Job\JobManager;
|
||||
use Espo\Core\Job\QueuePortionNumberProvider;
|
||||
|
||||
abstract class AbstractQueueJob implements JobDataLess
|
||||
{
|
||||
protected $queue = null;
|
||||
protected string $queue;
|
||||
|
||||
private $jobManager;
|
||||
private JobManager $jobManager;
|
||||
|
||||
private $portionNumberProvider;
|
||||
private QueuePortionNumberProvider $portionNumberProvider;
|
||||
|
||||
public function __construct(JobManager $jobManager, QueuePortionNumberProvider $portionNumberProvider)
|
||||
{
|
||||
@@ -50,10 +49,6 @@ abstract class AbstractQueueJob implements JobDataLess
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
if (!$this->queue) {
|
||||
throw new RuntimeException("No queue name.");
|
||||
}
|
||||
|
||||
$limit = $this->portionNumberProvider->get($this->queue);
|
||||
|
||||
$this->jobManager->processQueue($this->queue, $limit);
|
||||
|
||||
@@ -38,9 +38,9 @@ class ProcessJobGroup implements Job
|
||||
{
|
||||
private const PORTION_NUMBER = 100;
|
||||
|
||||
private $jobManager;
|
||||
private JobManager $jobManager;
|
||||
|
||||
private $config;
|
||||
private Config $config;
|
||||
|
||||
public function __construct(
|
||||
JobManager $jobManager,
|
||||
|
||||
@@ -36,5 +36,5 @@ use Espo\Core\{
|
||||
|
||||
class ProcessJobQueueE0 extends AbstractQueueJob
|
||||
{
|
||||
protected $queue = QueueName::E0;
|
||||
protected string $queue = QueueName::E0;
|
||||
}
|
||||
|
||||
@@ -36,5 +36,5 @@ use Espo\Core\{
|
||||
|
||||
class ProcessJobQueueQ0 extends AbstractQueueJob
|
||||
{
|
||||
protected $queue = QueueName::Q0;
|
||||
protected string $queue = QueueName::Q0;
|
||||
}
|
||||
|
||||
@@ -36,5 +36,5 @@ use Espo\Core\{
|
||||
|
||||
class ProcessJobQueueQ1 extends AbstractQueueJob
|
||||
{
|
||||
protected $queue = QueueName::Q1;
|
||||
protected string $queue = QueueName::Q1;
|
||||
}
|
||||
|
||||
@@ -39,11 +39,11 @@ use Espo\Core\{
|
||||
|
||||
class JobFactory
|
||||
{
|
||||
private $classFinder;
|
||||
private ClassFinder $classFinder;
|
||||
|
||||
private $injectableFactory;
|
||||
private InjectableFactory $injectableFactory;
|
||||
|
||||
private $metadataProvider;
|
||||
private MetadataProvider $metadataProvider;
|
||||
|
||||
public function __construct(
|
||||
ClassFinder $classFinder,
|
||||
@@ -74,7 +74,7 @@ class JobFactory
|
||||
|
||||
/**
|
||||
* Create a job by a class name.
|
||||
|
||||
* @param class-string $className
|
||||
* @return Job|JobDataLess
|
||||
*/
|
||||
public function createByClassName(string $className): object
|
||||
@@ -84,6 +84,9 @@ class JobFactory
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?class-string
|
||||
*/
|
||||
private function getClassName(string $name): ?string
|
||||
{
|
||||
$className = $this->metadataProvider->getJobClassName($name);
|
||||
|
||||
@@ -35,9 +35,7 @@ use Espo\Core\{
|
||||
Utils\Log,
|
||||
};
|
||||
|
||||
use Espo\{
|
||||
Entities\Job as JobEntity,
|
||||
};
|
||||
use Espo\Entities\Job as JobEntity;
|
||||
|
||||
use Throwable;
|
||||
|
||||
@@ -46,25 +44,25 @@ use Throwable;
|
||||
*/
|
||||
class JobManager
|
||||
{
|
||||
private $useProcessPool = false;
|
||||
private bool $useProcessPool = false;
|
||||
|
||||
protected $lastRunTimeFile = 'data/cache/application/cronLastRunTime.php';
|
||||
protected string $lastRunTimeFile = 'data/cache/application/cronLastRunTime.php';
|
||||
|
||||
private $config;
|
||||
private Config $config;
|
||||
|
||||
private $fileManager;
|
||||
private FileManager $fileManager;
|
||||
|
||||
private $jobRunner;
|
||||
private JobRunner $jobRunner;
|
||||
|
||||
private $log;
|
||||
private Log $log;
|
||||
|
||||
private $scheduleProcessor;
|
||||
private ScheduleProcessor $scheduleProcessor;
|
||||
|
||||
private $queueUtil;
|
||||
private QueueUtil $queueUtil;
|
||||
|
||||
private $asyncPoolFactory;
|
||||
private AsyncPoolFactory $asyncPoolFactory;
|
||||
|
||||
private $queueProcessorFactory;
|
||||
private QueueProcessorFactory $queueProcessorFactory;
|
||||
|
||||
public function __construct(
|
||||
Config $config,
|
||||
|
||||
@@ -48,28 +48,22 @@ use TypeError;
|
||||
*/
|
||||
class JobScheduler
|
||||
{
|
||||
private $className = null;
|
||||
|
||||
private $queue = null;
|
||||
|
||||
private $group = null;
|
||||
|
||||
/**
|
||||
* @var Data|null
|
||||
* @var ?class-string
|
||||
*/
|
||||
private $data = null;
|
||||
private ?string $className = null;
|
||||
|
||||
/**
|
||||
* @var DateTimeImmutable|null
|
||||
*/
|
||||
private $time = null;
|
||||
private ?string $queue = null;
|
||||
|
||||
/**
|
||||
* @var DateInterval|null
|
||||
*/
|
||||
private $delay = null;
|
||||
private ?string $group = null;
|
||||
|
||||
private $entityManager;
|
||||
private ?Data $data = null;
|
||||
|
||||
private ?DateTimeImmutable $time = null;
|
||||
|
||||
private ?DateInterval $delay = null;
|
||||
|
||||
private EntityManager $entityManager;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
@@ -78,6 +72,8 @@ class JobScheduler
|
||||
|
||||
/**
|
||||
* A class name of the job. Should implement the `Job` interface.
|
||||
*
|
||||
* @param class-string $className
|
||||
*/
|
||||
public function setClassName(string $className): self
|
||||
{
|
||||
@@ -152,7 +148,7 @@ class JobScheduler
|
||||
/**
|
||||
* Set data to be passed to the job.
|
||||
*
|
||||
* @param Data|array|null $data
|
||||
* @param Data|array<string,mixed>|null $data
|
||||
*/
|
||||
public function setData($data): self
|
||||
{
|
||||
|
||||
@@ -41,17 +41,23 @@ use Throwable;
|
||||
|
||||
class JobTask extends AsyncTask
|
||||
{
|
||||
private $jobId;
|
||||
private string $jobId;
|
||||
|
||||
public function __construct(string $jobId)
|
||||
{
|
||||
$this->jobId = $jobId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function configure()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$app = new Application();
|
||||
|
||||
@@ -33,7 +33,7 @@ use Espo\Core\Utils\Metadata;
|
||||
|
||||
class MetadataProvider
|
||||
{
|
||||
private $metadata;
|
||||
private Metadata $metadata;
|
||||
|
||||
public function __construct(Metadata $metadata)
|
||||
{
|
||||
@@ -80,11 +80,17 @@ class MetadataProvider
|
||||
return $this->metadata->get(['app', 'scheduledJobs', $name, 'jobClassName']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getScheduledJobNameList(): array
|
||||
{
|
||||
return array_keys($this->metadata->get(['app', 'scheduledJobs']) ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNonSystemScheduledJobNameList(): array
|
||||
{
|
||||
return array_filter(
|
||||
|
||||
@@ -34,9 +34,9 @@ use Espo\Core\Exceptions\Error;
|
||||
|
||||
class PreparatorFactory
|
||||
{
|
||||
private $metadataProvider;
|
||||
private MetadataProvider $metadataProvider;
|
||||
|
||||
private $injectableFactory;
|
||||
private InjectableFactory $injectableFactory;
|
||||
|
||||
public function __construct(MetadataProvider $metadataProvider, InjectableFactory $injectableFactory)
|
||||
{
|
||||
@@ -51,6 +51,7 @@ class PreparatorFactory
|
||||
*/
|
||||
public function create(string $name): Preparator
|
||||
{
|
||||
/** @var class-string */
|
||||
$className = $this->metadataProvider->getPreparatorClassName($name);
|
||||
|
||||
if (!$className) {
|
||||
|
||||
@@ -29,20 +29,24 @@
|
||||
|
||||
namespace Espo\Core\Job;
|
||||
|
||||
use Espo\Core\{
|
||||
Utils\Config,
|
||||
};
|
||||
use Espo\Core\Utils\Config;
|
||||
|
||||
class QueuePortionNumberProvider
|
||||
{
|
||||
private $config;
|
||||
private Config $config;
|
||||
|
||||
/**
|
||||
* @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>
|
||||
*/
|
||||
private $queueParamNameMap = [
|
||||
QueueName::Q0 => 'jobQ0MaxPortion',
|
||||
QueueName::Q1 => 'jobQ1MaxPortion',
|
||||
|
||||
@@ -31,15 +31,15 @@ namespace Espo\Core\Job;
|
||||
|
||||
class QueueProcessorParams
|
||||
{
|
||||
private $useProcessPool = false;
|
||||
private bool $useProcessPool = false;
|
||||
|
||||
private $noLock = false;
|
||||
private bool $noLock = false;
|
||||
|
||||
private $queue = null;
|
||||
private ?string $queue = null;
|
||||
|
||||
private $group = null;
|
||||
private ?string $group = null;
|
||||
|
||||
private $limit = 0;
|
||||
private int $limit = 0;
|
||||
|
||||
public function withUseProcessPool(bool $useProcessPool): self
|
||||
{
|
||||
|
||||
@@ -46,19 +46,13 @@ use DateTime;
|
||||
|
||||
class QueueUtil
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
private Config $config;
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $entityManager;
|
||||
private EntityManager $entityManager;
|
||||
|
||||
private $scheduleUtil;
|
||||
private ScheduleUtil $scheduleUtil;
|
||||
|
||||
private $metadataProvider;
|
||||
private MetadataProvider $metadataProvider;
|
||||
|
||||
private const NOT_EXISTING_PROCESS_PERIOD = 300;
|
||||
|
||||
@@ -96,7 +90,7 @@ class QueueUtil
|
||||
|
||||
/**
|
||||
* @return JobEntity[]
|
||||
* @phpstan-return Collection&iterable<JobEntity>
|
||||
* @phpstan-return Collection<JobEntity>
|
||||
*/
|
||||
public function getPendingJobList(?string $queue = null, ?string $group = null, int $limit = 0): Collection
|
||||
{
|
||||
@@ -128,7 +122,7 @@ class QueueUtil
|
||||
$builder->limit(0, $limit);
|
||||
}
|
||||
|
||||
/** @var Collection&iterable<JobEntity> $collection */
|
||||
/** @var Collection<JobEntity> $collection */
|
||||
$collection = $builder->find();
|
||||
|
||||
return $collection;
|
||||
@@ -348,6 +342,9 @@ class QueueUtil
|
||||
$this->markJobListFailed($failedJobList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param iterable<JobEntity> $jobList
|
||||
*/
|
||||
protected function markJobListFailed(iterable $jobList): void
|
||||
{
|
||||
if (!count($jobList)) {
|
||||
|
||||
@@ -55,6 +55,9 @@ use DateTimeImmutable;
|
||||
*/
|
||||
class ScheduleProcessor
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $asSoonAsPossibleSchedulingList = [
|
||||
'*',
|
||||
'* *',
|
||||
|
||||
@@ -45,7 +45,7 @@ use Espo\Entities\{
|
||||
|
||||
class ScheduleUtil
|
||||
{
|
||||
private $entityManager;
|
||||
private EntityManager $entityManager;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
@@ -55,11 +55,11 @@ class ScheduleUtil
|
||||
/**
|
||||
* Get active scheduled job list.
|
||||
*
|
||||
* @phpstan-return iterable<ScheduledJobEntity>&Collection
|
||||
* @return Collection<ScheduledJobEntity>
|
||||
*/
|
||||
public function getActiveScheduledJobList(): Collection
|
||||
{
|
||||
/** @var iterable<ScheduledJobEntity>&Collection $collection */
|
||||
/** @var Collection<ScheduledJobEntity> */
|
||||
$collection = $this->entityManager
|
||||
->getRDBRepository(ScheduledJobEntity::ENTITY_TYPE)
|
||||
->select([
|
||||
|
||||
@@ -36,41 +36,40 @@ use Espo\Core\Container;
|
||||
*/
|
||||
abstract class Base
|
||||
{
|
||||
private $container;
|
||||
private $container; /** @phpstan-ignore-line */
|
||||
|
||||
protected function getContainer()
|
||||
protected function getContainer() /** @phpstan-ignore-line */
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
protected function getEntityManager() /** @phpstan-ignore-line */
|
||||
{
|
||||
return $this->getContainer()->get('entityManager');
|
||||
}
|
||||
|
||||
protected function getServiceFactory()
|
||||
protected function getServiceFactory() /** @phpstan-ignore-line */
|
||||
{
|
||||
return $this->getContainer()->get('serviceFactory');
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
protected function getConfig() /** @phpstan-ignore-line */
|
||||
{
|
||||
return $this->getContainer()->get('config');
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
protected function getMetadata() /** @phpstan-ignore-line */
|
||||
{
|
||||
return $this->getContainer()->get('metadata');
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
protected function getUser() /** @phpstan-ignore-line */
|
||||
{
|
||||
return $this->getContainer()->get('user');
|
||||
}
|
||||
|
||||
public function __construct(Container $container)
|
||||
public function __construct(Container $container) /** @phpstan-ignore-line */
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user