修改日期打印

This commit is contained in:
whyour 2022-06-18 12:43:23 +08:00
parent 19afbd06c0
commit 6d2edaaaf8
4 changed files with 22 additions and 29 deletions

View File

@ -10,6 +10,7 @@ import { promises, existsSync } from 'fs';
import { promisify } from 'util'; import { promisify } from 'util';
import { Op } from 'sequelize'; import { Op } from 'sequelize';
import path from 'path'; import path from 'path';
import dayjs from 'dayjs';
@Service() @Service()
export default class CronService { export default class CronService {
@ -201,9 +202,7 @@ export default class CronService {
const str = err ? `\n${err}` : ''; const str = err ? `\n${err}` : '';
fs.appendFileSync( fs.appendFileSync(
`${absolutePath}`, `${absolutePath}`,
`${str}\n## 执行结束... ${new Date() `${str}\n## 执行结束... ${dayjs().format('YYYY-MM-DD HH:mm:ss')} `,
.toLocaleString('zh', { hour12: false })
.replace(' 24:', ' 00:')} `,
); );
} }
} }

View File

@ -14,6 +14,7 @@ import { spawn } from 'child_process';
import SockService from './sock'; import SockService from './sock';
import { Op } from 'sequelize'; import { Op } from 'sequelize';
import { concurrentRun } from '../config/util'; import { concurrentRun } from '../config/util';
import dayjs from 'dayjs';
@Service() @Service()
export default class DependenceService { export default class DependenceService {
@ -161,20 +162,17 @@ export default class DependenceService {
)[dependencies[0].type as any]; )[dependencies[0].type as any];
const actionText = isInstall ? '安装' : '删除'; const actionText = isInstall ? '安装' : '删除';
const depIds = dependencies.map((x) => x.id) as number[]; const depIds = dependencies.map((x) => x.id) as number[];
const startTime = Date.now(); const startTime = dayjs();
const message = `开始${actionText}依赖 ${depNames},开始时间 ${startTime.format(
'YYYY-MM-DD HH:mm:ss',
)}\n\n`;
this.sockService.sendMessage({ this.sockService.sendMessage({
type: socketMessageType, type: socketMessageType,
message: `开始${actionText}依赖 ${depNames},开始时间 ${new Date( message,
startTime,
).toLocaleString()}\n\n`,
references: depIds, references: depIds,
}); });
await this.updateLog( await this.updateLog(depIds, message);
depIds,
`开始${actionText}依赖 ${depNames},开始时间 ${new Date(
startTime,
).toLocaleString()}\n\n`,
);
const cp = spawn(`${depRunCommand} ${depNames}`, { shell: '/bin/bash' }); const cp = spawn(`${depRunCommand} ${depNames}`, { shell: '/bin/bash' });
@ -207,23 +205,19 @@ export default class DependenceService {
}); });
cp.on('close', async (code) => { cp.on('close', async (code) => {
const endTime = Date.now(); const endTime = dayjs();
const isSucceed = code === 0; const isSucceed = code === 0;
const resultText = isSucceed ? '成功' : '失败'; const resultText = isSucceed ? '成功' : '失败';
const message = `\n依赖${actionText}${resultText},结束时间 ${endTime.format(
'YYYY-MM-DD HH:mm:ss',
)} ${endTime.diff(startTime, 'second')} `;
this.sockService.sendMessage({ this.sockService.sendMessage({
type: socketMessageType, type: socketMessageType,
message: `\n依赖${actionText}${resultText},结束时间 ${new Date( message,
endTime,
).toLocaleString()} ${(endTime - startTime) / 1000} `,
references: depIds, references: depIds,
}); });
await this.updateLog( await this.updateLog(depIds, message);
depIds,
`\n依赖${actionText}${resultText},结束时间 ${new Date(
endTime,
).toLocaleString()} ${(endTime - startTime) / 1000} `,
);
let status = null; let status = null;
if (isSucceed) { if (isSucceed) {

View File

@ -28,6 +28,7 @@ import ScheduleService, { TaskCallbacks } from './schedule';
import { SimpleIntervalSchedule } from 'toad-scheduler'; import { SimpleIntervalSchedule } from 'toad-scheduler';
import SockService from './sock'; import SockService from './sock';
import SshKeyService from './sshKey'; import SshKeyService from './sshKey';
import dayjs from 'dayjs';
@Service() @Service()
export default class SubscriptionService { export default class SubscriptionService {
@ -371,11 +372,10 @@ export default class SubscriptionService {
const err = await this.killTask(command); const err = await this.killTask(command);
const absolutePath = await this.handleLogPath(doc.log_path as string); const absolutePath = await this.handleLogPath(doc.log_path as string);
const str = err ? `\n${err}` : ''; const str = err ? `\n${err}` : '';
fs.appendFileSync( fs.appendFileSync(
`${absolutePath}`, `${absolutePath}`,
`${str}\n## 执行结束... ${new Date() `${str}\n## 执行结束... ${dayjs().format('YYYY-MM-DD HH:mm:ss')} `,
.toLocaleString('zh', { hour12: false })
.replace(' 24:', ' 00:')} `,
); );
} }

View File

@ -13,7 +13,7 @@ import { Request } from 'express';
import ScheduleService from './schedule'; import ScheduleService from './schedule';
import { spawn } from 'child_process'; import { spawn } from 'child_process';
import SockService from './sock'; import SockService from './sock';
import got from 'got'; import dayjs from 'dayjs';
@Service() @Service()
export default class UserService { export default class UserService {
@ -111,7 +111,7 @@ export default class UserService {
}); });
await this.notificationService.notify( await this.notificationService.notify(
'登录通知', '登录通知',
`你于${new Date(timestamp).toLocaleString()}${address} ${ `你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}${address} ${
req.platform req.platform
} ip地址 ${ip}`, } ip地址 ${ip}`,
); );
@ -140,7 +140,7 @@ export default class UserService {
}); });
await this.notificationService.notify( await this.notificationService.notify(
'登录通知', '登录通知',
`你于${new Date(timestamp).toLocaleString()}${address} ${ `你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}${address} ${
req.platform req.platform
} ip地址 ${ip}`, } ip地址 ${ip}`,
); );