Skip to content

Commit

Permalink
Merge pull request #140 from lilt/4.x-development
Browse files Browse the repository at this point in the history
4.x development
  • Loading branch information
hadomskyi authored Apr 10, 2024
2 parents 5302daa + 5bc9ee8 commit 2a123bc
Show file tree
Hide file tree
Showing 29 changed files with 1,252 additions and 59 deletions.
37 changes: 36 additions & 1 deletion .github/workflows/craft-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,43 @@ jobs:
"4.4.16",
"4.4.16.1",
"4.4.17",
# TODO: check this, seems like bug in CraftCMS https://github.com/lilt/craft-lilt-plugin/actions/runs/8605507218/job/23582189269?pr=146
# "4.5.0",
# "4.5.1",
"4.5.2",
"4.5.3",
"4.5.4",
"4.5.5",
"4.5.6",
"4.5.6.1",
"4.5.7",
"4.5.8",
"4.5.9",
"4.5.10",
"4.5.11",
"4.5.11.1",
"4.5.12",
"4.5.13",
"4.5.14",
"4.6.0",
"4.6.1",
"4.7.0",
"4.7.1",
# TODO: check this, bug in CraftCMS https://github.com/lilt/craft-lilt-plugin/actions/runs/8605507218/job/23582193181?pr=146
# "4.7.2",
"4.7.2.1",
"4.7.3",
"4.7.4",
"4.8.0",
"4.8.1",
"4.8.2",
"4.8.3",
"4.8.4",
"4.8.5",
"4.8.6",
"4.8.7",
]
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set the value
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
os: [ ubuntu-20.04 ]
scenario: [
"cypress/e2e/jobs/copy-source-text-flow/filters.cy.js",
"cypress/e2e/jobs/copy-source-text-flow/success-path-multiple.cy.js",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- "*"
jobs:
tests-php-80:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set the value
Expand All @@ -23,7 +23,7 @@ jobs:
run: make test

tests-php-80-mysql-80:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set the value
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 4.5.0 - 2024-04-10
### Added
- Introduced a new configuration setting that allows the disabling of automatic synchronization for jobs that are currently in progress

### Fixed
- Download translations triggered only after all of them are done
- Lock release issue after queue message processing
- Rise condition of queue messages

## 4.4.5 - 2024-02-09
### Fixed
- Translation of nested link field
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lilt/craft-lilt-plugin",
"description": "The Lilt plugin makes it easy for you to send content to Lilt for translation right from within Craft CMS.",
"type": "craft-plugin",
"version": "4.4.5",
"version": "4.5.0",
"keywords": [
"craft",
"cms",
Expand Down
12 changes: 12 additions & 0 deletions src/controllers/PostConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function actionInvoke(): Response
$request->getBodyParam('copyEntriesSlugFromSourceToTarget') ?? '0'
);

// queueEachTranslationFileSeparately
$queueEachTranslationFileSeparately = $request->getBodyParam('queueEachTranslationFileSeparately');
if (empty($queueEachTranslationFileSeparately)) {
$queueEachTranslationFileSeparately = 0;
Expand All @@ -108,6 +109,17 @@ public function actionInvoke(): Response
(string)$queueEachTranslationFileSeparately
);

// queueDisableAutomaticSync
$queueDisableAutomaticSync = $request->getBodyParam('queueDisableAutomaticSync');
if (empty($queueDisableAutomaticSync)) {
$queueDisableAutomaticSync = 0;
}

Craftliltplugin::getInstance()->settingsRepository->save(
SettingsRepository::QUEUE_DISABLE_AUTOMATIC_SYNC,
(string)$queueDisableAutomaticSync
);

$settingsRequest = new SettingsRequest();
$settingsRequest->setProjectPrefix(
$request->getBodyParam('projectPrefix')
Expand Down
59 changes: 36 additions & 23 deletions src/modules/FetchJobStatusFromConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use lilthq\craftliltplugin\elements\Job;
use lilthq\craftliltplugin\records\JobRecord;
use lilthq\craftliltplugin\records\TranslationRecord;
use lilthq\craftliltplugin\services\repositories\SettingsRepository;

class FetchJobStatusFromConnector extends AbstractRetryJob
{
Expand Down Expand Up @@ -96,7 +97,7 @@ public function execute($queue): void
Craft::error([
"message" => sprintf(
'Set job %d and translations to status failed due to failed/cancel status from lilt',
$jobRecord->id,
$jobRecord->id
),
"jobRecord" => $jobRecord,
]);
Expand All @@ -107,18 +108,24 @@ public function execute($queue): void
}

if (!$isJobFinished) {
Queue::push(
(new FetchJobStatusFromConnector(
[
'jobId' => $this->jobId,
'liltJobId' => $this->liltJobId,
]
)),
self::PRIORITY,
self::getDelay(),
self::TTR
$queueDisableAutomaticSync = (bool) Craftliltplugin::getInstance()->settingsRepository->get(
SettingsRepository::QUEUE_DISABLE_AUTOMATIC_SYNC
);

if (!$queueDisableAutomaticSync) {
Queue::push(
(new FetchJobStatusFromConnector(
[
'jobId' => $this->jobId,
'liltJobId' => $this->liltJobId,
]
)),
self::PRIORITY,
self::getDelay(),
self::TTR
);
}

$mutex->release($mutexKey);
$this->markAsDone($queue);

Expand Down Expand Up @@ -163,7 +170,7 @@ function (TranslationResponse $connectorTranslation) {
Craft::error([
"message" => sprintf(
'Set job %d and translations to status failed due to failed status for translation from lilt',
$jobRecord->id,
$jobRecord->id
),
"jobRecord" => $jobRecord,
]);
Expand All @@ -177,18 +184,24 @@ function (TranslationResponse $connectorTranslation) {
return;
}

Queue::push(
(new FetchJobStatusFromConnector(
[
'jobId' => $this->jobId,
'liltJobId' => $this->liltJobId,
]
)),
self::PRIORITY,
self::getDelay(),
self::TTR
$queueDisableAutomaticSync = (bool) Craftliltplugin::getInstance()->settingsRepository->get(
SettingsRepository::QUEUE_DISABLE_AUTOMATIC_SYNC
);

if (!$queueDisableAutomaticSync) {
Queue::push(
(new FetchJobStatusFromConnector(
[
'jobId' => $this->jobId,
'liltJobId' => $this->liltJobId,
]
)),
self::PRIORITY,
self::getDelay(),
self::TTR
);
}

$mutex->release($mutexKey);
$this->markAsDone($queue);

Expand Down Expand Up @@ -239,7 +252,7 @@ function (TranslationResponse $connectorTranslation) {
Craft::error([
"message" => sprintf(
'Set job %d and translations to status failed due to failed/cancel status from lilt',
$jobRecord->id,
$jobRecord->id
),
"jobRecord" => $jobRecord,
]);
Expand Down
13 changes: 10 additions & 3 deletions src/modules/FetchTranslationFromConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,18 @@ public function execute($queue): void
Craft::error(
sprintf(
"Connector translation id is empty for translation:"
. "%d source site: %d target site: %d lilt job: %d",
. "%d source site: %d (%s) target site: %d (%s) lilt job: %d element: %d",
$translationRecord->id,
$translationRecord->sourceSiteId,
Craftliltplugin::getInstance()->languageMapper->getLanguageBySiteId(
$translationRecord->sourceSiteId
),
$translationRecord->targetSiteId,
$job->liltJobId
Craftliltplugin::getInstance()->languageMapper->getLanguageBySiteId(
$translationRecord->targetSiteId
),
$job->liltJobId,
$translationRecord->elementId
)
);

Expand Down Expand Up @@ -123,7 +130,7 @@ public function execute($queue): void
Craft::error([
"message" => sprintf(
'Set translation %d to status failed, got status failed from lilt platform',
$translationRecord->id,
$translationRecord->id
),
"translationRecord" => $translationRecord,
]);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/ManualJobSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function execute($queue): void
1,
Craft::t(
'app',
'Syncing finished',
'Syncing finished'
)
);

Expand All @@ -74,7 +74,7 @@ public function execute($queue): void
1,
Craft::t(
'app',
'Syncing finished',
'Syncing finished'
)
);

Expand Down
24 changes: 20 additions & 4 deletions src/modules/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
use Craft;
use craft\queue\BaseJob;
use craft\helpers\Queue as CraftHelpersQueue;
use lilthq\craftliltplugin\Craftliltplugin;
use lilthq\craftliltplugin\elements\Job;
use lilthq\craftliltplugin\parameters\CraftliltpluginParameters;
use lilthq\craftliltplugin\records\JobRecord;
use lilthq\craftliltplugin\services\repositories\SettingsRepository;

class QueueManager extends BaseJob
{
Expand All @@ -25,8 +27,17 @@ class QueueManager extends BaseJob
*/
public function execute($queue): void
{
$queueDisableAutomaticSync = (bool) Craftliltplugin::getInstance()->settingsRepository->get(
SettingsRepository::QUEUE_DISABLE_AUTOMATIC_SYNC
);

if ($queueDisableAutomaticSync) {
// skip because automatic sync is disabled
return;
}

$mutex = Craft::$app->getMutex();
$mutexKey = __CLASS__ . '_' . __FUNCTION__;
$mutexKey = self::getMutexKey();
if (!$mutex->acquire($mutexKey)) {
Craft::warning('Lilt queue manager is already running');

Expand All @@ -35,7 +46,7 @@ public function execute($queue): void
1,
Craft::t(
'app',
'Finished lilt queue manager',
'Finished lilt queue manager'
)
);

Expand All @@ -61,7 +72,7 @@ public function execute($queue): void
1,
Craft::t(
'app',
'Finished lilt queue manager',
'Finished lilt queue manager'
)
);

Expand Down Expand Up @@ -90,7 +101,7 @@ public function execute($queue): void
1,
Craft::t(
'app',
'Finished lilt queue manager',
'Finished lilt queue manager'
)
);

Expand All @@ -104,4 +115,9 @@ protected function defaultDescription(): ?string
{
return Craft::t('app', 'Lilt queue manager');
}

public static function getMutexKey(): string
{
return __CLASS__ . '_' . __FUNCTION__;
}
}
23 changes: 15 additions & 8 deletions src/modules/SendTranslationToConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use lilthq\craftliltplugin\models\TranslationModel;
use lilthq\craftliltplugin\records\TranslationRecord;
use lilthq\craftliltplugin\services\handlers\commands\SendTranslationCommand;
use lilthq\craftliltplugin\services\repositories\SettingsRepository;
use Throwable;

class SendTranslationToConnector extends AbstractRetryJob
Expand Down Expand Up @@ -113,7 +114,7 @@ public function execute($queue): void
sprintf(
'Can\'t find job %d for element %d',
$this->jobId,
$this->versionId,
$this->versionId
)
);
}
Expand Down Expand Up @@ -180,15 +181,21 @@ function (TranslationModel $translationModel) {
);
}

Queue::push(
(new FetchJobStatusFromConnector([
'jobId' => $command->getJob()->id,
'liltJobId' => $command->getJob()->liltJobId,
])),
FetchJobStatusFromConnector::PRIORITY,
10
$queueDisableAutomaticSync = (bool) Craftliltplugin::getInstance()->settingsRepository->get(
SettingsRepository::QUEUE_DISABLE_AUTOMATIC_SYNC
);

if (!$queueDisableAutomaticSync) {
Queue::push(
(new FetchJobStatusFromConnector([
'jobId' => $command->getJob()->id,
'liltJobId' => $command->getJob()->liltJobId,
])),
FetchJobStatusFromConnector::PRIORITY,
10
);
}

$this->markAsDone($queue);
$this->release();

Expand Down
Loading

0 comments on commit 2a123bc

Please sign in to comment.