Skip to content

Commit 24307a8

Browse files
committed
Configuration to enable/disable automatic sync jobs
ENG-14343
1 parent 29755ce commit 24307a8

File tree

10 files changed

+151
-37
lines changed

10 files changed

+151
-37
lines changed

.github/workflows/craft-versions.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,28 @@ jobs:
116116
"3.8.5",
117117
"3.8.6",
118118
"3.8.7",
119+
"3.8.8",
120+
"3.8.9",
121+
"3.8.10",
122+
"3.8.10.1",
123+
"3.8.10.2",
124+
"3.8.11",
125+
"3.8.12",
126+
"3.8.13",
127+
"3.8.14",
128+
"3.8.15",
129+
"3.8.16",
130+
"3.8.17",
131+
"3.9.0",
132+
"3.9.1",
133+
"3.9.2",
134+
"3.9.3",
135+
"3.9.4",
136+
"3.9.5",
137+
"3.9.6",
138+
"3.9.10",
139+
"3.9.11",
140+
"3.9.12",
119141
]
120142
runs-on: ubuntu-latest
121143
steps:

.github/workflows/e2e.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ jobs:
4040
run: |
4141
echo "CYPRESS_SCENARIO=${{ matrix.scenario }}" >> $GITHUB_ENV
4242
echo "DB_DATABASE=$(uuidgen)" >> $GITHUB_ENV
43-
- name: Run automation
43+
- name: Prepare automation
4444
working-directory: ./e2e
4545
run: |
4646
echo ${DB_DATABASE}
4747
make up
48-
make e2e-github
48+
- name: Run automation with retry
49+
uses: nick-invision/retry@v2
50+
working-directory: ./e2e
51+
with:
52+
timeout_minutes: 60
53+
max_attempts: 3
54+
command: make e2e-github
4955
- name: Copy artifacts
5056
if: ${{ failure() }}
5157
working-directory: ./e2e

src/controllers/PostConfigurationController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function actionInvoke(): Response
9898
$request->getBodyParam('copyEntriesSlugFromSourceToTarget') ?? '0'
9999
);
100100

101+
// queueEachTranslationFileSeparately
101102
$queueEachTranslationFileSeparately = $request->getBodyParam('queueEachTranslationFileSeparately');
102103
if (empty($queueEachTranslationFileSeparately)) {
103104
$queueEachTranslationFileSeparately = 0;
@@ -108,6 +109,17 @@ public function actionInvoke(): Response
108109
(string)$queueEachTranslationFileSeparately
109110
);
110111

112+
// queueDisableAutomaticSync
113+
$queueDisableAutomaticSync = $request->getBodyParam('queueDisableAutomaticSync');
114+
if (empty($queueDisableAutomaticSync)) {
115+
$queueDisableAutomaticSync = 0;
116+
}
117+
118+
Craftliltplugin::getInstance()->settingsRepository->save(
119+
SettingsRepository::QUEUE_DISABLE_AUTOMATIC_SYNC,
120+
(string)$queueDisableAutomaticSync
121+
);
122+
111123
$settingsRequest = new SettingsRequest();
112124
$settingsRequest->setProjectPrefix(
113125
$request->getBodyParam('projectPrefix')

src/modules/FetchJobStatusFromConnector.php

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use lilthq\craftliltplugin\elements\Job;
2020
use lilthq\craftliltplugin\records\JobRecord;
2121
use lilthq\craftliltplugin\records\TranslationRecord;
22+
use lilthq\craftliltplugin\services\repositories\SettingsRepository;
2223

2324
class FetchJobStatusFromConnector extends AbstractRetryJob
2425
{
@@ -107,18 +108,24 @@ public function execute($queue): void
107108
}
108109

109110
if (!$isJobFinished) {
110-
Queue::push(
111-
(new FetchJobStatusFromConnector(
112-
[
113-
'jobId' => $this->jobId,
114-
'liltJobId' => $this->liltJobId,
115-
]
116-
)),
117-
self::PRIORITY,
118-
self::getDelay(),
119-
self::TTR
111+
$queueDisableAutomaticSync = (bool) Craftliltplugin::getInstance()->settingsRepository->get(
112+
SettingsRepository::QUEUE_DISABLE_AUTOMATIC_SYNC
120113
);
121114

115+
if(!$queueDisableAutomaticSync) {
116+
Queue::push(
117+
(new FetchJobStatusFromConnector(
118+
[
119+
'jobId' => $this->jobId,
120+
'liltJobId' => $this->liltJobId,
121+
]
122+
)),
123+
self::PRIORITY,
124+
self::getDelay(),
125+
self::TTR
126+
);
127+
}
128+
122129
$mutex->release($mutexKey);
123130
$this->markAsDone($queue);
124131

@@ -177,18 +184,24 @@ function (TranslationResponse $connectorTranslation) {
177184
return;
178185
}
179186

180-
Queue::push(
181-
(new FetchJobStatusFromConnector(
182-
[
183-
'jobId' => $this->jobId,
184-
'liltJobId' => $this->liltJobId,
185-
]
186-
)),
187-
self::PRIORITY,
188-
self::getDelay(),
189-
self::TTR
187+
$queueDisableAutomaticSync = (bool) Craftliltplugin::getInstance()->settingsRepository->get(
188+
SettingsRepository::QUEUE_DISABLE_AUTOMATIC_SYNC
190189
);
191190

191+
if(!$queueDisableAutomaticSync) {
192+
Queue::push(
193+
(new FetchJobStatusFromConnector(
194+
[
195+
'jobId' => $this->jobId,
196+
'liltJobId' => $this->liltJobId,
197+
]
198+
)),
199+
self::PRIORITY,
200+
self::getDelay(),
201+
self::TTR
202+
);
203+
}
204+
192205
$mutex->release($mutexKey);
193206
$this->markAsDone($queue);
194207

src/modules/QueueManager.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
use Craft;
1313
use craft\queue\BaseJob;
1414
use craft\helpers\Queue as CraftHelpersQueue;
15+
use lilthq\craftliltplugin\Craftliltplugin;
1516
use lilthq\craftliltplugin\elements\Job;
1617
use lilthq\craftliltplugin\parameters\CraftliltpluginParameters;
1718
use lilthq\craftliltplugin\records\JobRecord;
19+
use lilthq\craftliltplugin\services\repositories\SettingsRepository;
1820

1921
class QueueManager extends BaseJob
2022
{
@@ -25,6 +27,15 @@ class QueueManager extends BaseJob
2527
*/
2628
public function execute($queue): void
2729
{
30+
$queueDisableAutomaticSync = (bool) Craftliltplugin::getInstance()->settingsRepository->get(
31+
SettingsRepository::QUEUE_DISABLE_AUTOMATIC_SYNC
32+
);
33+
34+
if($queueDisableAutomaticSync) {
35+
// skip because automatic sync is disabled
36+
return;
37+
}
38+
2839
$mutex = Craft::$app->getMutex();
2940
$mutexKey = __CLASS__ . '_' . __FUNCTION__;
3041
if (!$mutex->acquire($mutexKey)) {

src/modules/SendTranslationToConnector.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use lilthq\craftliltplugin\models\TranslationModel;
2121
use lilthq\craftliltplugin\records\TranslationRecord;
2222
use lilthq\craftliltplugin\services\handlers\commands\SendTranslationCommand;
23+
use lilthq\craftliltplugin\services\repositories\SettingsRepository;
2324
use Throwable;
2425

2526
class SendTranslationToConnector extends AbstractRetryJob
@@ -180,15 +181,21 @@ function (TranslationModel $translationModel) {
180181
);
181182
}
182183

183-
Queue::push(
184-
(new FetchJobStatusFromConnector([
185-
'jobId' => $command->getJob()->id,
186-
'liltJobId' => $command->getJob()->liltJobId,
187-
])),
188-
FetchJobStatusFromConnector::PRIORITY,
189-
10
184+
$queueDisableAutomaticSync = (bool) Craftliltplugin::getInstance()->settingsRepository->get(
185+
SettingsRepository::QUEUE_DISABLE_AUTOMATIC_SYNC
190186
);
191187

188+
if(!$queueDisableAutomaticSync) {
189+
Queue::push(
190+
(new FetchJobStatusFromConnector([
191+
'jobId' => $command->getJob()->id,
192+
'liltJobId' => $command->getJob()->liltJobId,
193+
])),
194+
FetchJobStatusFromConnector::PRIORITY,
195+
10
196+
);
197+
}
198+
192199
$this->markAsDone($queue);
193200
$this->release();
194201

src/services/handlers/SendJobToLiltConnectorHandler.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,21 @@ public function __invoke(Job $job): void
196196
'Job uploaded to Lilt Platform'
197197
);
198198

199-
Queue::push(
200-
(new FetchJobStatusFromConnector([
201-
'jobId' => $job->id,
202-
'liltJobId' => $jobLilt->getId(),
203-
])),
204-
FetchJobStatusFromConnector::PRIORITY,
205-
10 //10 seconds for fist job
199+
$queueDisableAutomaticSync = (bool) Craftliltplugin::getInstance()->settingsRepository->get(
200+
SettingsRepository::QUEUE_DISABLE_AUTOMATIC_SYNC
206201
);
202+
203+
if(!$queueDisableAutomaticSync) {
204+
// push fetch status job from connector
205+
Queue::push(
206+
(new FetchJobStatusFromConnector([
207+
'jobId' => $job->id,
208+
'liltJobId' => $jobLilt->getId(),
209+
])),
210+
FetchJobStatusFromConnector::PRIORITY,
211+
10 //10 seconds for fist job
212+
);
213+
}
207214
}
208215

209216
/**

src/services/repositories/SettingsRepository.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class SettingsRepository
1717
{
1818
public const ENABLE_ENTRIES_FOR_TARGET_SITES = 'enable_entries_for_target_sites';
1919
public const COPY_ENTRIES_SLUG_FROM_SOURCE_TO_TARGET = 'copy_entries_slug_from_source_to_target';
20-
2120
public const QUEUE_EACH_TRANSLATION_FILE_SEPARATELY = 'queue_each_translation_file_separately';
21+
public const QUEUE_DISABLE_AUTOMATIC_SYNC = 'queue_disable_automatic_sync';
2222
public const QUEUE_MANAGER_EXECUTED_AT = 'queue_manager_executed_at';
2323

2424
public const IGNORE_DROPDOWNS = 'ignore_dropdowns';
@@ -56,6 +56,25 @@ public function isQueueEachTranslationFileSeparately(): bool
5656
return (bool)$settingValue->value;
5757
}
5858

59+
public function get(string $name): ?string
60+
{
61+
$tableSchema = Craft::$app->getDb()->schema->getTableSchema(CraftliltpluginParameters::SETTINGS_TABLE_NAME);
62+
if ($tableSchema === null) {
63+
return null;
64+
}
65+
66+
67+
$settingValue = SettingRecord::findOne(
68+
['name' => $name]
69+
);
70+
71+
if (empty($settingValue) || empty($settingValue->value)) {
72+
return null;
73+
}
74+
75+
return $settingValue->value;
76+
}
77+
5978
public function ignoreDropdowns(): bool
6079
{
6180
$tableSchema = Craft::$app->getDb()->schema->getTableSchema(CraftliltpluginParameters::SETTINGS_TABLE_NAME);

src/templates/_components/utilities/configuration.twig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@
9191
}) }}
9292
</div>
9393

94+
<div class="field">
95+
{{ forms.checkbox({
96+
label: 'Disable automatic synchronization of sent translation jobs',
97+
name: 'queueDisableAutomaticSync',
98+
id: 'queueDisableAutomaticSync',
99+
checked: queueDisableAutomaticSync,
100+
errors: model is defined? model.getErrors('queueDisableAutomaticSync') : [],
101+
disabled: liltConfigDisabled
102+
}) }}
103+
</div>
104+
94105
{{ forms.textField({
95106
name: 'liltConfigDisabled',
96107
id: 'liltConfigDisabled',

src/utilities/Configuration.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public static function contentHtml(): string
9292
);
9393
$queueEachTranslationFileSeparately = (bool) ($queueEachTranslationFileSeparately->value ?? false);
9494

95+
$queueDisableAutomaticSync = SettingRecord::findOne(
96+
['name' => SettingsRepository::QUEUE_DISABLE_AUTOMATIC_SYNC,]
97+
);
98+
$queueDisableAutomaticSync = (bool) ($queueDisableAutomaticSync->value ?? false);
99+
95100
return Craft::$app->getView()->renderTemplate(
96101
'craft-lilt-plugin/_components/utilities/configuration.twig',
97102
[
@@ -106,6 +111,7 @@ public static function contentHtml(): string
106111
'enableEntriesForTargetSites' => $enableEntriesForTargetSites,
107112
'copyEntriesSlugFromSourceToTarget' => $copyEntriesSlugFromSourceToTarget,
108113
'queueEachTranslationFileSeparately' => $queueEachTranslationFileSeparately,
114+
'queueDisableAutomaticSync' => $queueDisableAutomaticSync,
109115
]
110116
);
111117
}

0 commit comments

Comments
 (0)