Skip to content

Commit 0dd4032

Browse files
committed
Added scheduled tasks register button to admin
1 parent b5afe23 commit 0dd4032

10 files changed

Lines changed: 71 additions & 6 deletions

File tree

src/Controller/ScheduledTaskController.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
77
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
88
use Shopware\Core\Framework\MessageQueue\Handler\AbstractMessageHandler;
9+
use Shopware\Core\Framework\MessageQueue\ScheduledTask\Registry\TaskRegistry;
910
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskDefinition;
1011
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskEntity;
1112
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -23,10 +24,17 @@ class ScheduledTaskController
2324

2425
private EntityRepositoryInterface $scheduledTaskRepository;
2526

26-
public function __construct(iterable $taskHandler, EntityRepositoryInterface $scheduledTaskRepository)
27+
private TaskRegistry $taskRegistry;
28+
29+
public function __construct(
30+
iterable $taskHandler,
31+
EntityRepositoryInterface $scheduledTaskRepository,
32+
TaskRegistry $taskRegistry
33+
)
2734
{
2835
$this->taskHandler = $taskHandler;
2936
$this->scheduledTaskRepository = $scheduledTaskRepository;
37+
$this->taskRegistry = $taskRegistry;
3038
}
3139

3240
/**
@@ -68,6 +76,16 @@ public function runTask(string $id, Context $context): JsonResponse
6876
return new JsonResponse(null, JsonResponse::HTTP_NO_CONTENT);
6977
}
7078

79+
/**
80+
* @Route(path="/scheduled-tasks/register", methods={"POST"}, name="api.frosh.tools.scheduled.tasks.register")
81+
*/
82+
public function registerTasks(): JsonResponse
83+
{
84+
$this->taskRegistry->registerTasks();
85+
86+
return new JsonResponse(null, JsonResponse::HTTP_NO_CONTENT);
87+
}
88+
7189
private function fetchTask(string $id, Context $context): ScheduledTaskEntity
7290
{
7391
$criteria = new Criteria([$id]);

src/Resources/app/administration/src/api/frosh-tools.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ class FroshTools extends ApiService {
6666
});
6767
}
6868

69+
scheduledTasksRegister() {
70+
const apiRoute = `${this.getApiBasePath()}/scheduled-tasks/register`;
71+
return this.httpClient.post(
72+
apiRoute,
73+
{},
74+
{
75+
headers: this.getBasicHeaders()
76+
}
77+
).then((response) => {
78+
return ApiService.handleResponse(response);
79+
});
80+
}
81+
6982
healthStatus() {
7083
const apiRoute = `${this.getApiBasePath()}/health/status`;
7184
return this.httpClient.get(
@@ -170,7 +183,7 @@ class FroshTools extends ApiService {
170183
return ApiService.handleResponse(response);
171184
});
172185
}
173-
186+
174187
stateMachines(stateMachine) {
175188
const apiRoute = `${this.getApiBasePath()}/state-machines/load`;
176189
return this.httpClient.get(

src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-scheduled/index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ Component.register('frosh-tools-tab-scheduled', {
6767
this.isLoading = true;
6868
await this.createdComponent();
6969
},
70+
7071
async createdComponent() {
7172
const criteria = new Criteria;
7273
criteria.addSorting(Criteria.sort('nextExecutionTime', 'ASC'));
7374
this.items = await this.scheduledRepository.search(criteria, Shopware.Context.api);
7475
this.isLoading = false;
7576
},
77+
7678
async runTask(item) {
7779
this.isLoading = true;
7880

@@ -91,6 +93,26 @@ Component.register('frosh-tools-tab-scheduled', {
9193
}
9294

9395
this.createdComponent();
94-
}
96+
},
97+
98+
async registerScheduledTasks() {
99+
this.isLoading = true;
100+
101+
try {
102+
this.createNotificationInfo({
103+
message: this.$tc('frosh-tools.scheduledTasksRegisterStarted')
104+
})
105+
await this.froshToolsService.scheduledTasksRegister();
106+
this.createNotificationSuccess({
107+
message: this.$tc('frosh-tools.scheduledTasksRegisterSucceed')
108+
})
109+
} catch (e) {
110+
this.createNotificationError({
111+
message: this.$tc('frosh-tools.scheduledTasksRegisterFailed')
112+
})
113+
}
114+
115+
this.createdComponent();
116+
},
95117
}
96118
});

src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-scheduled/style.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
.frosh-tools-tab-scheduled__tasks-card {
2+
.sw-card__toolbar {
3+
display: flex;
4+
justify-content: space-between;
5+
}
6+
27
.sw-card__content {
38
padding: 0;
49
}

src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-scheduled/template.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<sw-card class="frosh-tools-tab-scheduled__tasks-card" :title="$tc('frosh-tools.tabs.scheduledTaskOverview.title')" :isLoading="isLoading" :large="true">
33

44
<template #toolbar>
5-
<!-- @todo: Make the refresh button fancy -->
65
<sw-button variant="ghost" @click="refresh"><sw-icon :small="true" name="default-arrow-360-left"></sw-icon></sw-button>
6+
<sw-button variant="primary" @click="registerScheduledTasks">{{ $tc('frosh-tools.scheduledTasksRegisterStarted') }}</sw-button>
77
</template>
88

99
<sw-entity-listing

src/Resources/app/administration/src/module/frosh-tools/snippet/de-DE.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
"scheduledTaskStarted": "Die geplante Aufgabe für \"{name}\" wurde gestartet",
7676
"scheduledTaskSucceed": "Die geplante Aufgabe für \"{name}\" war erfolgreich",
7777
"scheduledTaskFailed": "Die geplante Aufgabe für \"{name}\" ist fehlgeschlagen",
78+
"scheduledTasksRegisterStarted": "Registriere geplante Aufgaben",
79+
"scheduledTasksRegisterSucceed": "Geplante Aufgaben registriert",
80+
"scheduledTasksRegisterFailed": "Es ist ein Fehler beim registrieren aufgetreten",
7881
"checker": {
7982
"scheduledTaskGood": "Die geplanten Aufgaben laufen regelmäßig",
8083
"scheduledTaskWarning": "Die geplanten Aufgaben laufen seit mehr als 10 Minuten nicht",

src/Resources/app/administration/src/module/frosh-tools/snippet/en-GB.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
"scheduledTaskStarted": "The scheduled task execution for \"{name}\" started",
7676
"scheduledTaskSucceed": "The scheduled task execution for \"{name}\" succeed",
7777
"scheduledTaskFailed": "The scheduled task execution for \"{name}\" failed",
78+
"scheduledTasksRegisterStarted": "Register scheduled tasks",
79+
"scheduledTasksRegisterSucceed": "Scheduled tasks registered",
80+
"scheduledTasksRegisterFailed": "Scheduled tasks registration failed",
7881
"checker": {
7982
"scheduledTaskGood": "Scheduled tasks working scheduled",
8083
"scheduledTaskWarning": "The scheduled tasks are waiting for executing for more than 10 minutes",

src/Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<service id="Frosh\Tools\Controller\ScheduledTaskController" public="true">
6969
<argument type="tagged" tag="messenger.message_handler"/>
7070
<argument type="service" id="scheduled_task.repository"/>
71+
<argument type="service" id="Shopware\Core\Framework\MessageQueue\ScheduledTask\Registry\TaskRegistry"/>
7172
</service>
7273

7374
<service id="Frosh\Tools\Controller\LogController" public="true">

src/Resources/public/administration/css/frosh-tools.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/public/administration/js/frosh-tools.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)