Make it possible for flag some tasks as non-disableable
This commit is contained in:
@@ -316,7 +316,7 @@ return (function () {
|
|||||||
DispatchCommand::TASK_NAME => [
|
DispatchCommand::TASK_NAME => [
|
||||||
'command' => DispatchCommand::ROUTE,
|
'command' => DispatchCommand::ROUTE,
|
||||||
'name' => DispatchCommand::TASK_NAME,
|
'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,
|
'enabled' => true,
|
||||||
'timer' => '* * * * *',
|
'timer' => '* * * * *',
|
||||||
'args' => '-v',
|
'args' => '-v',
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
<div class="is-capitalized card-header-title">
|
<div class="is-capitalized card-header-title">
|
||||||
{{ task.name }}
|
{{ task.name }}
|
||||||
</div>
|
</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"
|
<input :id="task.name" type="checkbox" class="switch is-success" :checked="task.enabled"
|
||||||
@change="toggleTask(task)">
|
@change="toggleTask(task)">
|
||||||
<label :for="task.name"></label>
|
<label :for="task.name"></label>
|
||||||
@@ -70,13 +70,21 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="column is-6 has-text-left">
|
<div class="column is-6 has-text-left">
|
||||||
<strong class="is-hidden-mobile">Timer: </strong>
|
<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 }}
|
{{ task.timer }}
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-6 has-text-right" v-if="task.args">
|
<div class="column is-6 has-text-right" v-if="task.args">
|
||||||
<strong class="is-hidden-mobile">Args: </strong>
|
<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 }}
|
{{ task.args }}
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
@@ -162,7 +170,7 @@
|
|||||||
import 'assets/css/bulma-switch.css'
|
import 'assets/css/bulma-switch.css'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import request from '~/utils/request'
|
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 cronstrue from 'cronstrue'
|
||||||
import Message from '~/components/Message'
|
import Message from '~/components/Message'
|
||||||
import {useStorage} from '@vueuse/core'
|
import {useStorage} from '@vueuse/core'
|
||||||
@@ -199,11 +207,21 @@ onMounted(async () => await loadContent())
|
|||||||
const toggleTask = async task => {
|
const toggleTask = async task => {
|
||||||
try {
|
try {
|
||||||
const keyName = `WS_CRON_${task.name.toUpperCase()}`
|
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',
|
method: 'POST',
|
||||||
body: JSON.stringify({"value": !task.enabled})
|
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}`)
|
const response = await request(`/tasks/${task.name}`)
|
||||||
tasks.value[tasks.value.findIndex(b => b.name === task.name)] = await response.json()
|
tasks.value[tasks.value.findIndex(b => b.name === task.name)] = await response.json()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -465,6 +465,14 @@ const basename = (path, ext = '') => {
|
|||||||
return base
|
return base
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parse_api_response = async r => {
|
||||||
|
try {
|
||||||
|
return await r.json()
|
||||||
|
} catch (e) {
|
||||||
|
return {error: {code: r.status, message: r.statusText}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
r,
|
r,
|
||||||
ag_set,
|
ag_set,
|
||||||
@@ -485,5 +493,6 @@ export {
|
|||||||
TOOLTIP_DATE_FORMAT,
|
TOOLTIP_DATE_FORMAT,
|
||||||
makeSecret,
|
makeSecret,
|
||||||
explode,
|
explode,
|
||||||
basename
|
basename,
|
||||||
|
parse_api_response,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ final class Index
|
|||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
#[Get(self::URL . '[/]', name: 'tasks.index')]
|
#[Get(self::URL . '[/]', name: 'tasks.index')]
|
||||||
public function tasksIndex(iRequest $request): iResponse
|
public function tasksIndex(): iResponse
|
||||||
{
|
{
|
||||||
$queuedTasks = $this->cache->get('queued_tasks', []);
|
$queuedTasks = $this->cache->get('queued_tasks', []);
|
||||||
$response = [
|
$response = [
|
||||||
@@ -39,6 +39,8 @@ final class Index
|
|||||||
foreach (TasksCommand::getTasks() as $task) {
|
foreach (TasksCommand::getTasks() as $task) {
|
||||||
$task = self::formatTask($task);
|
$task = self::formatTask($task);
|
||||||
$task['queued'] = in_array(ag($task, 'name'), $queuedTasks);
|
$task['queued'] = in_array(ag($task, 'name'), $queuedTasks);
|
||||||
|
|
||||||
|
|
||||||
$response['tasks'][] = $task;
|
$response['tasks'][] = $task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,12 +51,8 @@ final class Index
|
|||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
#[Route(['GET', 'POST', 'DELETE'], self::URL . '/{id:[a-zA-Z0-9_-]+}/queue[/]', name: 'tasks.task.queue')]
|
#[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);
|
$task = TasksCommand::getTasks($id);
|
||||||
|
|
||||||
if (empty($task)) {
|
if (empty($task)) {
|
||||||
@@ -85,12 +83,8 @@ final class Index
|
|||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
#[Get(self::URL . '/{id:[a-zA-Z0-9_-]+}[/]', name: 'tasks.task.view')]
|
#[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);
|
$task = TasksCommand::getTasks($id);
|
||||||
|
|
||||||
if (empty($task)) {
|
if (empty($task)) {
|
||||||
@@ -127,6 +121,9 @@ final class Index
|
|||||||
$item['command'] = get_debug_type($item['command']);
|
$item['command'] = get_debug_type($item['command']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ff = getEnvSpec('WS_CRON_' . strtoupper(ag($task, 'name')));
|
||||||
|
$item['allow_disable'] = !empty($ff);
|
||||||
|
|
||||||
if (true === $isEnabled) {
|
if (true === $isEnabled) {
|
||||||
try {
|
try {
|
||||||
$item['next_run'] = makeDate($timer->getNextRunDate());
|
$item['next_run'] = makeDate($timer->getNextRunDate());
|
||||||
|
|||||||
Reference in New Issue
Block a user