Initial commit
This commit is contained in:
114
application/Espo/Core/Job/Job/Data.php
Normal file
114
application/Espo/Core/Job/Job/Data.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Job\Job;
|
||||
|
||||
use Espo\Core\Utils\ObjectUtil;
|
||||
|
||||
use TypeError;
|
||||
use stdClass;
|
||||
|
||||
class Data
|
||||
{
|
||||
private stdClass $data;
|
||||
private ?string $targetId = null;
|
||||
private ?string $targetType = null;
|
||||
|
||||
public function __construct(?stdClass $data = null)
|
||||
{
|
||||
$this->data = $data ?? (object) [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance.
|
||||
*
|
||||
* @param stdClass|array<string, mixed>|null $data Raw data.
|
||||
* @return self
|
||||
*/
|
||||
public static function create($data = null): self
|
||||
{
|
||||
/** @var mixed $data */
|
||||
|
||||
if ($data !== null && !is_object($data) && !is_array($data)) {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
||||
if (is_array($data)) {
|
||||
$data = (object) $data;
|
||||
}
|
||||
|
||||
/** @var ?stdClass $data */
|
||||
|
||||
return new self($data);
|
||||
}
|
||||
|
||||
public function getRaw(): stdClass
|
||||
{
|
||||
return ObjectUtil::clone($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $name)
|
||||
{
|
||||
return $this->getRaw()->$name ?? null;
|
||||
}
|
||||
|
||||
public function has(string $name): bool
|
||||
{
|
||||
return property_exists($this->data, $name);
|
||||
}
|
||||
|
||||
public function getTargetId(): ?string
|
||||
{
|
||||
return $this->targetId;
|
||||
}
|
||||
|
||||
public function getTargetType(): ?string
|
||||
{
|
||||
return $this->targetType;
|
||||
}
|
||||
|
||||
public function withTargetId(?string $targetId): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->targetId = $targetId;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function withTargetType(?string $targetType): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->targetType = $targetType;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
51
application/Espo/Core/Job/Job/Jobs/AbstractQueueJob.php
Normal file
51
application/Espo/Core/Job/Job/Jobs/AbstractQueueJob.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Job\Job\Jobs;
|
||||
|
||||
use Espo\Core\Job\JobDataLess;
|
||||
use Espo\Core\Job\JobManager;
|
||||
use Espo\Core\Job\QueuePortionNumberProvider;
|
||||
|
||||
abstract class AbstractQueueJob implements JobDataLess
|
||||
{
|
||||
protected string $queue;
|
||||
|
||||
public function __construct(
|
||||
private JobManager $jobManager,
|
||||
private QueuePortionNumberProvider $portionNumberProvider)
|
||||
{}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$limit = $this->portionNumberProvider->get($this->queue);
|
||||
|
||||
$this->jobManager->processQueue($this->queue, $limit);
|
||||
}
|
||||
}
|
||||
54
application/Espo/Core/Job/Job/Jobs/ProcessJobGroup.php
Normal file
54
application/Espo/Core/Job/Job/Jobs/ProcessJobGroup.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Job\Job\Jobs;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Job\Job;
|
||||
use Espo\Core\Job\Job\Data;
|
||||
use Espo\Core\Job\JobManager;
|
||||
|
||||
class ProcessJobGroup implements Job
|
||||
{
|
||||
private const PORTION_NUMBER = 100;
|
||||
|
||||
public function __construct(
|
||||
private JobManager $jobManager,
|
||||
private Config $config
|
||||
) {}
|
||||
|
||||
public function run(Data $data): void
|
||||
{
|
||||
$limit = $this->config->get('jobGroupMaxPortion') ?? self::PORTION_NUMBER;
|
||||
|
||||
$group = $data->get('group');
|
||||
|
||||
$this->jobManager->processGroup($group, $limit);
|
||||
}
|
||||
}
|
||||
37
application/Espo/Core/Job/Job/Jobs/ProcessJobQueueE0.php
Normal file
37
application/Espo/Core/Job/Job/Jobs/ProcessJobQueueE0.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Job\Job\Jobs;
|
||||
|
||||
use Espo\Core\Job\QueueName;
|
||||
|
||||
class ProcessJobQueueE0 extends AbstractQueueJob
|
||||
{
|
||||
protected string $queue = QueueName::E0;
|
||||
}
|
||||
37
application/Espo/Core/Job/Job/Jobs/ProcessJobQueueQ0.php
Normal file
37
application/Espo/Core/Job/Job/Jobs/ProcessJobQueueQ0.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Job\Job\Jobs;
|
||||
|
||||
use Espo\Core\Job\QueueName;
|
||||
|
||||
class ProcessJobQueueQ0 extends AbstractQueueJob
|
||||
{
|
||||
protected string $queue = QueueName::Q0;
|
||||
}
|
||||
37
application/Espo/Core/Job/Job/Jobs/ProcessJobQueueQ1.php
Normal file
37
application/Espo/Core/Job/Job/Jobs/ProcessJobQueueQ1.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Job\Job\Jobs;
|
||||
|
||||
use Espo\Core\Job\QueueName;
|
||||
|
||||
class ProcessJobQueueQ1 extends AbstractQueueJob
|
||||
{
|
||||
protected string $queue = QueueName::Q1;
|
||||
}
|
||||
39
application/Espo/Core/Job/Job/Status.php
Normal file
39
application/Espo/Core/Job/Job/Status.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
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';
|
||||
}
|
||||
Reference in New Issue
Block a user