2023-07-26 22:31:52 -07:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2021-01-04 00:36:50 -08:00
|
|
|
<template>
|
2023-03-09 02:59:11 -08:00
|
|
|
<div data-cy-mkw-jobQueue class="mkw-jobQueue _monospace" :class="{ _panel: !widgetProps.transparent }">
|
2021-01-04 00:36:50 -08:00
|
|
|
<div class="inbox">
|
2022-12-19 02:01:30 -08:00
|
|
|
<div class="label">Inbox queue<i v-if="current.inbox.waiting > 0" class="ti ti-alert-triangle icon"></i></div>
|
2021-01-04 00:36:50 -08:00
|
|
|
<div class="values">
|
|
|
|
<div>
|
|
|
|
<div>Process</div>
|
2024-01-03 20:04:00 -08:00
|
|
|
<div :class="{ inc: current.inbox.activeSincePrevTick > prev.inbox.activeSincePrevTick, dec: current.inbox.activeSincePrevTick < prev.inbox.activeSincePrevTick }" :title="`${current.inbox.activeSincePrevTick}`">{{ kmg(current.inbox.activeSincePrevTick, 2) }}</div>
|
2021-01-04 00:36:50 -08:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div>Active</div>
|
2024-01-03 20:04:00 -08:00
|
|
|
<div :class="{ inc: current.inbox.active > prev.inbox.active, dec: current.inbox.active < prev.inbox.active }" :title="`${current.inbox.active}`">{{ kmg(current.inbox.active, 2) }}</div>
|
2021-01-04 00:36:50 -08:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div>Delayed</div>
|
2024-01-03 20:04:00 -08:00
|
|
|
<div :class="{ inc: current.inbox.delayed > prev.inbox.delayed, dec: current.inbox.delayed < prev.inbox.delayed }" :title="`${current.inbox.delayed}`">{{ kmg(current.inbox.delayed, 2) }}</div>
|
2021-01-04 00:36:50 -08:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div>Waiting</div>
|
2024-01-03 20:04:00 -08:00
|
|
|
<div :class="{ inc: current.inbox.waiting > prev.inbox.waiting, dec: current.inbox.waiting < prev.inbox.waiting }" :title="`${current.inbox.waiting}`">{{ kmg(current.inbox.waiting, 2) }}</div>
|
2021-01-04 00:36:50 -08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="deliver">
|
2022-12-19 02:01:30 -08:00
|
|
|
<div class="label">Deliver queue<i v-if="current.deliver.waiting > 0" class="ti ti-alert-triangle icon"></i></div>
|
2021-01-04 00:36:50 -08:00
|
|
|
<div class="values">
|
|
|
|
<div>
|
|
|
|
<div>Process</div>
|
2024-01-03 20:04:00 -08:00
|
|
|
<div :class="{ inc: current.deliver.activeSincePrevTick > prev.deliver.activeSincePrevTick, dec: current.deliver.activeSincePrevTick < prev.deliver.activeSincePrevTick }" :title="`${current.deliver.activeSincePrevTick}`">{{ kmg(current.deliver.activeSincePrevTick, 2) }}</div>
|
2021-01-04 00:36:50 -08:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div>Active</div>
|
2024-01-03 20:04:00 -08:00
|
|
|
<div :class="{ inc: current.deliver.active > prev.deliver.active, dec: current.deliver.active < prev.deliver.active }" :title="`${current.deliver.active}`">{{ kmg(current.deliver.active, 2) }}</div>
|
2021-01-04 00:36:50 -08:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div>Delayed</div>
|
2024-01-03 20:04:00 -08:00
|
|
|
<div :class="{ inc: current.deliver.delayed > prev.deliver.delayed, dec: current.deliver.delayed < prev.deliver.delayed }" :title="`${current.deliver.delayed}`">{{ kmg(current.deliver.delayed, 2) }}</div>
|
2021-01-04 00:36:50 -08:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div>Waiting</div>
|
2024-01-03 20:04:00 -08:00
|
|
|
<div :class="{ inc: current.deliver.waiting > prev.deliver.waiting, dec: current.deliver.waiting < prev.deliver.waiting }" :title="`${current.deliver.waiting}`">{{ kmg(current.deliver.waiting, 2) }}</div>
|
2021-01-04 00:36:50 -08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-08 03:30:01 -08:00
|
|
|
<script lang="ts" setup>
|
2023-12-06 21:42:09 -08:00
|
|
|
import { onUnmounted, reactive, ref } from 'vue';
|
2023-12-20 18:36:45 -08:00
|
|
|
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
|
2023-09-19 00:37:43 -07:00
|
|
|
import { GetFormResultType } from '@/scripts/form.js';
|
|
|
|
import { useStream } from '@/stream.js';
|
2024-01-03 20:04:00 -08:00
|
|
|
import kmg from '@/filters/kmg.js';
|
2023-09-19 00:37:43 -07:00
|
|
|
import * as sound from '@/scripts/sound.js';
|
|
|
|
import { deepClone } from '@/scripts/clone.js';
|
2023-11-25 21:38:34 -08:00
|
|
|
import { defaultStore } from '@/store.js';
|
2021-01-04 00:36:50 -08:00
|
|
|
|
2022-01-08 03:30:01 -08:00
|
|
|
const name = 'jobQueue';
|
2021-01-04 00:36:50 -08:00
|
|
|
|
2022-01-08 03:30:01 -08:00
|
|
|
const widgetPropsDef = {
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2021-01-04 00:36:50 -08:00
|
|
|
},
|
2022-01-08 03:30:01 -08:00
|
|
|
sound: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2021-01-04 00:36:50 -08:00
|
|
|
},
|
2022-01-08 03:30:01 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
2023-05-19 00:20:53 -07:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2022-01-08 03:30:01 -08:00
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
2023-05-15 03:08:46 -07:00
|
|
|
const connection = useStream().useChannel('queueStats');
|
2022-01-08 03:30:01 -08:00
|
|
|
const current = reactive({
|
|
|
|
inbox: {
|
|
|
|
activeSincePrevTick: 0,
|
|
|
|
active: 0,
|
|
|
|
waiting: 0,
|
|
|
|
delayed: 0,
|
2021-01-04 00:36:50 -08:00
|
|
|
},
|
2022-01-08 03:30:01 -08:00
|
|
|
deliver: {
|
|
|
|
activeSincePrevTick: 0,
|
|
|
|
active: 0,
|
|
|
|
waiting: 0,
|
|
|
|
delayed: 0,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const prev = reactive({} as typeof current);
|
2023-12-06 21:42:09 -08:00
|
|
|
const jammedAudioBuffer = ref<AudioBuffer | null>(null);
|
|
|
|
const jammedSoundNodePlaying = ref<boolean>(false);
|
2023-11-21 03:05:04 -08:00
|
|
|
|
2023-11-25 21:38:34 -08:00
|
|
|
if (defaultStore.state.sound_masterVolume) {
|
2024-01-07 19:46:20 -08:00
|
|
|
sound.loadAudio('/client-assets/sounds/syuilo/queue-jammed.mp3').then(buf => {
|
2023-11-27 00:33:42 -08:00
|
|
|
if (!buf) throw new Error('[WidgetJobQueue] Failed to initialize AudioBuffer');
|
2023-12-06 21:42:09 -08:00
|
|
|
jammedAudioBuffer.value = buf;
|
2023-11-27 00:33:42 -08:00
|
|
|
});
|
2023-11-25 21:38:34 -08:00
|
|
|
}
|
2021-01-04 00:36:50 -08:00
|
|
|
|
2022-01-08 03:30:01 -08:00
|
|
|
for (const domain of ['inbox', 'deliver']) {
|
2022-11-16 16:31:07 -08:00
|
|
|
prev[domain] = deepClone(current[domain]);
|
2022-01-08 03:30:01 -08:00
|
|
|
}
|
2021-01-04 00:36:50 -08:00
|
|
|
|
2022-01-08 03:30:01 -08:00
|
|
|
const onStats = (stats) => {
|
|
|
|
for (const domain of ['inbox', 'deliver']) {
|
2022-11-16 16:31:07 -08:00
|
|
|
prev[domain] = deepClone(current[domain]);
|
2022-01-08 03:30:01 -08:00
|
|
|
current[domain].activeSincePrevTick = stats[domain].activeSincePrevTick;
|
|
|
|
current[domain].active = stats[domain].active;
|
|
|
|
current[domain].waiting = stats[domain].waiting;
|
|
|
|
current[domain].delayed = stats[domain].delayed;
|
|
|
|
|
2023-12-06 21:42:09 -08:00
|
|
|
if (current[domain].waiting > 0 && widgetProps.sound && jammedAudioBuffer.value && !jammedSoundNodePlaying.value) {
|
2024-01-07 19:46:20 -08:00
|
|
|
const soundNode = sound.createSourceNode(jammedAudioBuffer.value, 1)?.soundSource;
|
2023-11-21 03:05:04 -08:00
|
|
|
if (soundNode) {
|
2023-12-06 21:42:09 -08:00
|
|
|
jammedSoundNodePlaying.value = true;
|
|
|
|
soundNode.onended = () => jammedSoundNodePlaying.value = false;
|
2023-11-21 03:05:04 -08:00
|
|
|
soundNode.start();
|
|
|
|
}
|
2022-01-08 03:30:01 -08:00
|
|
|
}
|
2021-01-04 00:36:50 -08:00
|
|
|
}
|
2022-01-08 03:30:01 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
const onStatsLog = (statsLog) => {
|
|
|
|
for (const stats of [...statsLog].reverse()) {
|
|
|
|
onStats(stats);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
connection.on('stats', onStats);
|
|
|
|
connection.on('statsLog', onStatsLog);
|
|
|
|
|
|
|
|
connection.send('requestLog', {
|
2023-07-13 15:59:54 -07:00
|
|
|
id: Math.random().toString().substring(2, 10),
|
2022-01-08 03:30:01 -08:00
|
|
|
length: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
connection.off('stats', onStats);
|
|
|
|
connection.off('statsLog', onStatsLog);
|
|
|
|
connection.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2021-01-04 00:36:50 -08:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@keyframes warnBlink {
|
|
|
|
0% { opacity: 1; }
|
|
|
|
50% { opacity: 0; }
|
|
|
|
}
|
|
|
|
|
|
|
|
.mkw-jobQueue {
|
2021-01-08 04:44:02 -08:00
|
|
|
font-size: 0.9em;
|
|
|
|
|
2021-01-04 00:36:50 -08:00
|
|
|
> div {
|
|
|
|
padding: 16px;
|
|
|
|
|
|
|
|
&:not(:first-child) {
|
2021-04-09 20:40:50 -07:00
|
|
|
border-top: solid 0.5px var(--divider);
|
2021-01-04 00:36:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
> .icon {
|
|
|
|
color: var(--warn);
|
|
|
|
margin-left: auto;
|
|
|
|
animation: warnBlink 1s infinite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .values {
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
> div {
|
|
|
|
flex: 1;
|
|
|
|
|
|
|
|
> div:first-child {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
2021-02-19 18:05:46 -08:00
|
|
|
|
|
|
|
> div:last-child {
|
|
|
|
&.inc {
|
|
|
|
color: var(--warn);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.dec {
|
|
|
|
color: var(--success);
|
|
|
|
}
|
|
|
|
}
|
2021-01-04 00:36:50 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|