Make it possible for flag some tasks as non-disableable
This commit is contained in:
@@ -316,7 +316,7 @@ return (function () {
|
||||
DispatchCommand::TASK_NAME => [
|
||||
'command' => DispatchCommand::ROUTE,
|
||||
'name' => DispatchCommand::TASK_NAME,
|
||||
'info' => 'The new events dispatcher system. That will replace the old events systems eventually. (cannot be disabled).',
|
||||
'info' => 'Dispatch queued events to their respective listeners.',
|
||||
'enabled' => true,
|
||||
'timer' => '* * * * *',
|
||||
'args' => '-v',
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
<div class="is-capitalized card-header-title">
|
||||
{{ task.name }}
|
||||
</div>
|
||||
<span class="card-header-icon" v-tooltip="'Enable/Disable Task.'">
|
||||
<span class="card-header-icon" v-tooltip="'Enable/Disable Task.'" v-if="task.allow_disable">
|
||||
<input :id="task.name" type="checkbox" class="switch is-success" :checked="task.enabled"
|
||||
@change="toggleTask(task)">
|
||||
<label :for="task.name"></label>
|
||||
@@ -70,13 +70,21 @@
|
||||
</div>
|
||||
<div class="column is-6 has-text-left">
|
||||
<strong class="is-hidden-mobile">Timer: </strong>
|
||||
<NuxtLink class="has-tooltip" :to='makeEnvLink(`WS_CRON_${task.name.toUpperCase()}_AT`, task.timer)'>
|
||||
<span v-if="!task.allow_disabled" class="is-unselectable">
|
||||
{{ task.timer }}
|
||||
</span>
|
||||
<NuxtLink v-else class="has-tooltip"
|
||||
:to='makeEnvLink(`WS_CRON_${task.name.toUpperCase()}_AT`, task.timer)'>
|
||||
{{ task.timer }}
|
||||
</NuxtLink>
|
||||
</div>
|
||||
<div class="column is-6 has-text-right" v-if="task.args">
|
||||
<strong class="is-hidden-mobile">Args: </strong>
|
||||
<NuxtLink class="has-tooltip" :to='makeEnvLink(`WS_CRON_${task.name.toUpperCase()}_ARGS`, task.args)'>
|
||||
<span v-if="!task.allow_disabled" class="is-unselectable">
|
||||
{{ task.args }}
|
||||
</span>
|
||||
<NuxtLink v-else class="has-tooltip"
|
||||
:to='makeEnvLink(`WS_CRON_${task.name.toUpperCase()}_ARGS`, task.args)'>
|
||||
{{ task.args }}
|
||||
</NuxtLink>
|
||||
</div>
|
||||
@@ -162,7 +170,7 @@
|
||||
import 'assets/css/bulma-switch.css'
|
||||
import moment from 'moment'
|
||||
import request from '~/utils/request'
|
||||
import {awaitElement, makeConsoleCommand, notification, TOOLTIP_DATE_FORMAT} from '~/utils/index'
|
||||
import {awaitElement, makeConsoleCommand, notification, parse_api_response, TOOLTIP_DATE_FORMAT} from '~/utils/index'
|
||||
import cronstrue from 'cronstrue'
|
||||
import Message from '~/components/Message'
|
||||
import {useStorage} from '@vueuse/core'
|
||||
@@ -199,11 +207,21 @@ onMounted(async () => await loadContent())
|
||||
const toggleTask = async task => {
|
||||
try {
|
||||
const keyName = `WS_CRON_${task.name.toUpperCase()}`
|
||||
await request(`/system/env/${keyName}`, {
|
||||
|
||||
const oldState = task.enabled
|
||||
|
||||
const update = await request(`/system/env/${keyName}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({"value": !task.enabled})
|
||||
})
|
||||
|
||||
if (200 !== update.status) {
|
||||
const json = await parse_api_response(update)
|
||||
notification('error', 'Error', `Failed to toggle task '${task.name}' status. ${json.error.message}`)
|
||||
tasks.value[tasks.value.findIndex(b => b.name === task.name)].enabled = oldState
|
||||
return
|
||||
}
|
||||
|
||||
const response = await request(`/tasks/${task.name}`)
|
||||
tasks.value[tasks.value.findIndex(b => b.name === task.name)] = await response.json()
|
||||
} catch (e) {
|
||||
|
||||
@@ -465,6 +465,14 @@ const basename = (path, ext = '') => {
|
||||
return base
|
||||
}
|
||||
|
||||
const parse_api_response = async r => {
|
||||
try {
|
||||
return await r.json()
|
||||
} catch (e) {
|
||||
return {error: {code: r.status, message: r.statusText}}
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
r,
|
||||
ag_set,
|
||||
@@ -485,5 +493,6 @@ export {
|
||||
TOOLTIP_DATE_FORMAT,
|
||||
makeSecret,
|
||||
explode,
|
||||
basename
|
||||
basename,
|
||||
parse_api_response,
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ final class Index
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[Get(self::URL . '[/]', name: 'tasks.index')]
|
||||
public function tasksIndex(iRequest $request): iResponse
|
||||
public function tasksIndex(): iResponse
|
||||
{
|
||||
$queuedTasks = $this->cache->get('queued_tasks', []);
|
||||
$response = [
|
||||
@@ -39,6 +39,8 @@ final class Index
|
||||
foreach (TasksCommand::getTasks() as $task) {
|
||||
$task = self::formatTask($task);
|
||||
$task['queued'] = in_array(ag($task, 'name'), $queuedTasks);
|
||||
|
||||
|
||||
$response['tasks'][] = $task;
|
||||
}
|
||||
|
||||
@@ -49,12 +51,8 @@ final class Index
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[Route(['GET', 'POST', 'DELETE'], self::URL . '/{id:[a-zA-Z0-9_-]+}/queue[/]', name: 'tasks.task.queue')]
|
||||
public function taskQueue(iRequest $request, array $args = []): iResponse
|
||||
public function taskQueue(iRequest $request, string $id): iResponse
|
||||
{
|
||||
if (null === ($id = ag($args, 'id'))) {
|
||||
return api_error('No id was given.', Status::BAD_REQUEST);
|
||||
}
|
||||
|
||||
$task = TasksCommand::getTasks($id);
|
||||
|
||||
if (empty($task)) {
|
||||
@@ -85,12 +83,8 @@ final class Index
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[Get(self::URL . '/{id:[a-zA-Z0-9_-]+}[/]', name: 'tasks.task.view')]
|
||||
public function taskView(iRequest $request, array $args = []): iResponse
|
||||
public function taskView(string $id): iResponse
|
||||
{
|
||||
if (null === ($id = ag($args, 'id'))) {
|
||||
return api_error('No id was given.', Status::BAD_REQUEST);
|
||||
}
|
||||
|
||||
$task = TasksCommand::getTasks($id);
|
||||
|
||||
if (empty($task)) {
|
||||
@@ -127,6 +121,9 @@ final class Index
|
||||
$item['command'] = get_debug_type($item['command']);
|
||||
}
|
||||
|
||||
$ff = getEnvSpec('WS_CRON_' . strtoupper(ag($task, 'name')));
|
||||
$item['allow_disable'] = !empty($ff);
|
||||
|
||||
if (true === $isEnabled) {
|
||||
try {
|
||||
$item['next_run'] = makeDate($timer->getNextRunDate());
|
||||
|
||||
Reference in New Issue
Block a user