PHRAS-3239 purge queue in admin

#time 6h
This commit is contained in:
aina esokia
2020-10-19 17:50:03 +03:00
parent aa4fd6f17a
commit 641c2d210d
3 changed files with 42 additions and 0 deletions

View File

@@ -141,6 +141,22 @@ class AdminConfigurationController extends Controller
]);
}
public function purgeQueueAction(PhraseaApplication $app, Request $request)
{
$queueName = $request->request->get('queueName');
if (empty($queueName)) {
return $this->app->json(['success' => false]);
}
/** @var AMQPConnection $serverConnection */
$serverConnection = $this->app['alchemy_worker.amqp.connection'];
$serverConnection->reinitializeQueue([$queueName]);
return $this->app->json(['success' => true]);
}
public function truncateTableAction(PhraseaApplication $app)
{
/** @var WorkerRunningJobRepository $repoWorker */

View File

@@ -88,6 +88,10 @@ class ControllerServiceProvider implements ControllerProviderInterface, ServiceP
->method('GET')
->bind('worker_admin_queue_monitor');
$controllers->match('/purge-queue', 'controller.worker.admin.configuration:purgeQueueAction')
->method('POST')
->bind('worker_admin_purge_queue');
$controllers->match('/{workerId}/change-status', 'controller.worker.admin.configuration:changeStatusAction')
->method('POST')
->assert('workerId', '\d+')

View File

@@ -11,6 +11,7 @@
<th></th>
<th>{{ 'admin::workermanager:tab:queueMonitor: Message count' |trans }}</th>
<th>{{ 'admin::workermanager:tab:queueMonitor: Consumer count' |trans }}</th>
<th></th>
</tr>
</thead>
<tbody class="queue-list">
@@ -21,6 +22,9 @@
<th>{{ queueStatus.queueName }}</th>
<td>{{ queueStatus.messageCount }}</td>
<td>{{ queueStatus.consumerCount }}</td>
<td>
<buton class="btn btn-danger btn-mini purge-queue" data-queue-name="{{ queueStatus.queueName }}">{{ 'admin::workermanager:tab:queueMonitor: Purge Queue' | trans }}</buton>
</td>
</tr>
{% endfor %}
@@ -38,5 +42,23 @@
}
});
});
$("#worker-queue-monitor").on('click', '.purge-queue', function() {
if (confirm("Warning! Are you sure? Messages cannot be recovered after purging.")) {
$.ajax({
type: "POST",
url: "/admin/worker-manager/purge-queue",
dataType: 'json',
data : {
queueName : $(this).attr("data-queue-name")
},
success: function (data) {
console.log(data);
$("#refresh-monitor").trigger("click");
}
});
}
});
</script>
{% endif %}