libretime/legacy/application/services/ThirdPartyCeleryService.php

119 lines
3.8 KiB
PHP
Raw Permalink Normal View History

<?php
2021-10-11 16:10:47 +02:00
abstract class Application_Service_ThirdPartyCeleryService extends Application_Service_ThirdPartyService
{
/**
* @var string broker exchange name for third-party tasks
*/
protected static $_CELERY_EXCHANGE_NAME;
/**
* @var array map of celery identifiers to their task names
*/
protected static $_CELERY_TASKS;
/**
2021-10-11 16:10:47 +02:00
* Execute a Celery task with the given name and data parameters.
*
* @param string $taskName the name of the celery task to execute
2021-10-11 16:10:47 +02:00
* @param array $data the data array to send as task parameters
* @param int $fileId the unique identifier for the file involved in the task
*
2021-10-11 16:10:47 +02:00
* @return CeleryTasks the created task
2022-09-12 13:16:14 +02:00
*
* @throws Exception
*/
2021-10-11 16:10:47 +02:00
protected function _executeTask($taskName, $data, $fileId = null)
{
try {
2021-10-11 16:10:47 +02:00
$brokerTaskId = CeleryManager::sendCeleryMessage(
$taskName,
static::$_CELERY_EXCHANGE_NAME,
$data
);
return $this->_createTaskReference($fileId, $brokerTaskId, $taskName);
} catch (Exception $e) {
2021-10-11 16:10:47 +02:00
Logging::error('Invalid request: ' . $e->getMessage());
throw $e;
}
}
/**
* Create a CeleryTasks object for a pending task
* TODO: should we have a database layer class to handle Propel operations?
*
* @param $fileId int CcFiles identifier
* @param $brokerTaskId int broker task identifier to so we can asynchronously
fix(deps): update dependency friendsofphp/php-cs-fixer to <3.43.2 (stable) (#2849) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [friendsofphp/php-cs-fixer](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer) | `<3.42.1` -> `<3.43.2` | [![age](https://developer.mend.io/api/mc/badges/age/packagist/friendsofphp%2fphp-cs-fixer/3.43.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/packagist/friendsofphp%2fphp-cs-fixer/3.43.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/packagist/friendsofphp%2fphp-cs-fixer/3.42.0/3.43.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/packagist/friendsofphp%2fphp-cs-fixer/3.42.0/3.43.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>PHP-CS-Fixer/PHP-CS-Fixer (friendsofphp/php-cs-fixer)</summary> ### [`v3.43.1`](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/HEAD/CHANGELOG.md#Changelog-for-v3431) [Compare Source](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/compare/v3.43.0...v3.43.1) - fix: Import only unique symbols' short names ([#&#8203;7635](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7635)) ### [`v3.43.0`](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/HEAD/CHANGELOG.md#Changelog-for-v3430) [Compare Source](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/compare/v3.42.0...v3.43.0) - chore: change base of `@Symfony` set to `@PER-CS2.0` ([#&#8203;7627](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7627)) - chore: PHPUnit - allow for v10 ([#&#8203;7606](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7606)) - chore: Preg - rework catching the error ([#&#8203;7616](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7616)) - chore: Revert unneeded peer-dep-pin and re-gen lock file ([#&#8203;7618](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7618)) - docs: drop extra note about 8.0.0 bug in README.md ([#&#8203;7614](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7614)) - feat: add cast_spaces into `@PER-CS2.0` ([#&#8203;7625](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7625)) - feat: Configurable phpDoc tags for FQCN processing ([#&#8203;7628](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7628)) - feat: StatementIndentationFixer - introduce stick_comment_to_next_continuous_control_statement config ([#&#8203;7624](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7624)) - feat: UnaryOperatorSpacesFixer - introduce only_dec_inc config ([#&#8203;7626](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7626)) - fix: FullyQualifiedStrictTypesFixer - better support annotations in inline {} ([#&#8203;7633](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7633)) - fix: Improve how FQCN is handled in phpDoc ([#&#8203;7622](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7622)) - fix: phpdoc_align - fix multiline tag alignment issue ([#&#8203;7630](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7630)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/libretime/libretime). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMDMuMSIsInVwZGF0ZWRJblZlciI6IjM3LjEwMy4xIiwidGFyZ2V0QnJhbmNoIjoic3RhYmxlIn0=--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: jo <ljonas@riseup.net>
2023-12-29 15:29:05 +01:00
* receive completed task messages
* @param $taskName string broker task name
*
2022-09-12 13:16:14 +02:00
* @return CeleryTasks the created task
*
* @throws Exception
* @throws PropelException
*/
2021-10-11 16:10:47 +02:00
protected function _createTaskReference($fileId, $brokerTaskId, $taskName)
{
$trackReferenceId = $this->createTrackReference($fileId);
$task = new CeleryTasks();
$task->setDbTaskId($brokerTaskId);
2015-06-18 19:49:25 +02:00
$task->setDbName($taskName);
2021-10-11 16:10:47 +02:00
$utc = new DateTimeZone('UTC');
$task->setDbDispatchTime(new DateTime('now', $utc));
2015-06-18 19:49:25 +02:00
$task->setDbStatus(CELERY_PENDING_STATUS);
$task->setDbTrackReference($trackReferenceId);
2015-06-18 19:49:25 +02:00
$task->save();
2021-10-11 16:10:47 +02:00
return $task;
}
/**
* Update a CeleryTasks object for a completed task
* TODO: should we have a database layer class to handle Propel operations?
*
* @param $task CeleryTasks the completed CeleryTasks object
* @param $status string Celery task status
*
* @throws Exception
* @throws PropelException
*/
2021-10-11 16:10:47 +02:00
public function updateTask($task, $status)
{
$task->setDbStatus($status);
$task->save();
}
/**
2021-10-11 16:10:47 +02:00
* Update a ThirdPartyTrackReferences object for a completed upload.
*
* Manipulation and use of the track object is left up to child implementations
*
* @param $task CeleryTasks the completed CeleryTasks object
* @param $trackId int ThirdPartyTrackReferences identifier
* @param $result mixed Celery task result message
* @param $status string Celery task status
*
2022-09-12 13:16:14 +02:00
* @return ThirdPartyTrackReferences the updated ThirdPartyTrackReferences object
*
* @throws Exception
* @throws PropelException
*/
2021-10-11 16:10:47 +02:00
public function updateTrackReference($task, $trackId, $result, $status)
{
static::updateTask($task, $status);
$ref = ThirdPartyTrackReferencesQuery::create()
->findOneByDbId($trackId);
if (is_null($ref)) {
$ref = new ThirdPartyTrackReferences();
}
$ref->setDbService(static::$_SERVICE_NAME);
2021-10-11 16:10:47 +02:00
$utc = new DateTimeZone('UTC');
$ref->setDbUploadTime(new DateTime('now', $utc));
$ref->save();
2021-10-11 16:10:47 +02:00
return $ref;
}
2021-10-11 16:10:47 +02:00
}