デバッグ機構
This commit is contained in:
parent
6d1ce48198
commit
db4fe14316
5 changed files with 37 additions and 19 deletions
|
@ -8,7 +8,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "run-s build:backend build:frontend build:meta",
|
"build": "run-s build:backend build:frontend build:meta",
|
||||||
"build:frontend": "webpack",
|
"build:frontend": "webpack",
|
||||||
"build:backend": "run-p build:backend-source build:views build:styles",
|
"build:backend": "run-s build:backend-source build:views build:styles",
|
||||||
"build:backend-source": "tsc",
|
"build:backend-source": "tsc",
|
||||||
"build:views": "copyfiles -u 1 src/backend/views/*.pug ./built/",
|
"build:views": "copyfiles -u 1 src/backend/views/*.pug ./built/",
|
||||||
"build:meta": "node ./build-meta.js",
|
"build:meta": "node ./build-meta.js",
|
||||||
|
|
|
@ -19,12 +19,12 @@ export class AdminController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('/misshai/error') getMisshaiError(@CurrentUser({ required: true }) user: IUser) {
|
@Get('/misshai/log') getMisshaiLog(@CurrentUser({ required: true }) user: IUser) {
|
||||||
if (!user.isAdmin) {
|
if (!user.isAdmin) {
|
||||||
throw new BadRequestError('Not an Admin');
|
throw new BadRequestError('Not an Admin');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Store.getState().misshaiWorkerRecentError;
|
return Store.getState().misshaiWorkerLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnUndefined(204)
|
@OnUndefined(204)
|
||||||
|
|
|
@ -19,24 +19,41 @@ export default (): void => {
|
||||||
export const work = async () => {
|
export const work = async () => {
|
||||||
Store.dispatch({ nowCalculating: true });
|
Store.dispatch({ nowCalculating: true });
|
||||||
|
|
||||||
|
clearLog();
|
||||||
|
|
||||||
|
printLog('[Miss-hai Worker] Started.');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const users = await Users.find({ alertMode: Not<AlertMode>('nothing') });
|
const users = await Users.find({ alertMode: Not<AlertMode>('nothing') });
|
||||||
for (const user of users) {
|
for (const user of users) {
|
||||||
await update(user).catch(e => handleError(user, e));
|
await update(user).catch(e => handleError(user, e));
|
||||||
|
printLog(`[Miss-hai Worker] processed for ${user.username}@${user.host}`);
|
||||||
|
|
||||||
if (user.alertMode === 'note') {
|
if (user.alertMode === 'note') {
|
||||||
return delay(3000);
|
return delay(3000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Store.dispatch({ misshaiWorkerRecentError: null });
|
printLog('[Miss-hai Worker] finished successfully.');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = String(e instanceof Error ? e.stack : e);
|
const msg = String(e instanceof Error ? e.stack : e);
|
||||||
Store.dispatch({ misshaiWorkerRecentError: msg });
|
printLog(msg);
|
||||||
|
printLog('[Miss-hai Worker] stopped wrongly.');
|
||||||
} finally {
|
} finally {
|
||||||
Store.dispatch({ nowCalculating: false });
|
Store.dispatch({ nowCalculating: false });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const clearLog = () => {
|
||||||
|
Store.dispatch({ misshaiWorkerLog: [] });
|
||||||
|
};
|
||||||
|
|
||||||
|
const printLog = (log: any) => {
|
||||||
|
Store.dispatch({ misshaiWorkerLog: [
|
||||||
|
...Store.getState().misshaiWorkerLog,
|
||||||
|
String(log),
|
||||||
|
] });
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* アラートを送信します。
|
* アラートを送信します。
|
||||||
* @param user アラートの送信先ユーザー
|
* @param user アラートの送信先ユーザー
|
||||||
|
@ -60,13 +77,13 @@ const handleError = async (user: User, e: any) => {
|
||||||
if (e.code) {
|
if (e.code) {
|
||||||
if (e.code === 'NO_SUCH_USER' || e.code === 'AUTHENTICATION_FAILED') {
|
if (e.code === 'NO_SUCH_USER' || e.code === 'AUTHENTICATION_FAILED') {
|
||||||
// ユーザーが削除されている場合、レコードからも消してとりやめ
|
// ユーザーが削除されている場合、レコードからも消してとりやめ
|
||||||
console.info(`${user.username}@${user.host} is deleted, so delete this user from the system`);
|
printLog(`${user.username}@${user.host} is deleted, so delete this user from the system`);
|
||||||
await deleteUser(user.username, user.host);
|
await deleteUser(user.username, user.host);
|
||||||
} else {
|
} else {
|
||||||
console.error(`Misskey Error: ${JSON.stringify(e)}`);
|
printLog(`Misskey Error: ${JSON.stringify(e)}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// おそらく通信エラー
|
// おそらく通信エラー
|
||||||
console.error(`Unknown error: ${e.name} ${e.message}`);
|
printLog(`Unknown error: ${e.name} ${e.message}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
const defaultState: State = {
|
const defaultState: State = {
|
||||||
nowCalculating: false,
|
nowCalculating: false,
|
||||||
misshaiWorkerRecentError: null,
|
misshaiWorkerLog: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
let _state: Readonly<State> = defaultState;
|
let _state: Readonly<State> = defaultState;
|
||||||
|
@ -17,7 +17,7 @@ let _state: Readonly<State> = defaultState;
|
||||||
*/
|
*/
|
||||||
export type State = {
|
export type State = {
|
||||||
nowCalculating: boolean,
|
nowCalculating: boolean,
|
||||||
misshaiWorkerRecentError: string | null,
|
misshaiWorkerLog: string[],
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,11 +7,14 @@ import { IAnnouncement } from '../../common/types/announcement';
|
||||||
import { $delete, $get, $post, $put } from '../misc/api';
|
import { $delete, $get, $post, $put } from '../misc/api';
|
||||||
import { Card } from './Card';
|
import { Card } from './Card';
|
||||||
import { showModal } from '../store/slices/screen';
|
import { showModal } from '../store/slices/screen';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
|
||||||
|
|
||||||
export const AdminPage: React.VFC = () => {
|
export const AdminPage: React.VFC = () => {
|
||||||
const { data, error } = useGetSessionQuery(undefined);
|
const { data, error } = useGetSessionQuery(undefined);
|
||||||
|
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const [announcements, setAnnouncements] = useState<IAnnouncement[]>([]);
|
const [announcements, setAnnouncements] = useState<IAnnouncement[]>([]);
|
||||||
const [selectedAnnouncement, selectAnnouncement] = useState<IAnnouncement | null>(null);
|
const [selectedAnnouncement, selectAnnouncement] = useState<IAnnouncement | null>(null);
|
||||||
const [isAnnouncementsLoaded, setAnnouncementsLoaded] = useState(false);
|
const [isAnnouncementsLoaded, setAnnouncementsLoaded] = useState(false);
|
||||||
|
@ -20,7 +23,7 @@ export const AdminPage: React.VFC = () => {
|
||||||
const [draftTitle, setDraftTitle] = useState('');
|
const [draftTitle, setDraftTitle] = useState('');
|
||||||
const [draftBody, setDraftBody] = useState('');
|
const [draftBody, setDraftBody] = useState('');
|
||||||
|
|
||||||
const [misshaiError, setMisshaiError] = useState<string | null>(null);
|
const [misshaiLog, setMisshaiLog] = useState<string[] | null>(null);
|
||||||
|
|
||||||
const submitAnnouncement = async () => {
|
const submitAnnouncement = async () => {
|
||||||
if (selectedAnnouncement) {
|
if (selectedAnnouncement) {
|
||||||
|
@ -55,7 +58,11 @@ export const AdminPage: React.VFC = () => {
|
||||||
setAnnouncements(announcements ?? []);
|
setAnnouncements(announcements ?? []);
|
||||||
setAnnouncementsLoaded(true);
|
setAnnouncementsLoaded(true);
|
||||||
});
|
});
|
||||||
$get<string | null>('admin/misshai/error').then(setMisshaiError);
|
fetchLog();
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchLog = () => {
|
||||||
|
$get<string[]>('admin/misshai/log').then(setMisshaiLog);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClickStartMisshaiAlertWorkerButton = () => {
|
const onClickStartMisshaiAlertWorkerButton = () => {
|
||||||
|
@ -192,7 +199,7 @@ export const AdminPage: React.VFC = () => {
|
||||||
ミス廃アラートワーカーを強制起動する
|
ミス廃アラートワーカーを強制起動する
|
||||||
</button>
|
</button>
|
||||||
<h3>直近のワーカーエラー</h3>
|
<h3>直近のワーカーエラー</h3>
|
||||||
<pre><code>{misshaiError ?? 'なし'}</code></pre>
|
<pre><code>{misshaiLog?.join('\n') ?? 'なし'}</code></pre>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
</>
|
</>
|
||||||
|
@ -201,9 +208,3 @@ export const AdminPage: React.VFC = () => {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function dispatch(arg0: any) {
|
|
||||||
throw new Error('Function not implemented.');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue