log file name modify
This commit is contained in:
parent
8978fa44fc
commit
252420b167
2 changed files with 29 additions and 24 deletions
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cron/cron.dart';
|
||||
|
|
@ -28,7 +27,7 @@ class IsolateScheduler extends IsolateBase {
|
|||
late DataBuild build;
|
||||
SchedulerInterval? schedulerInterval;
|
||||
CommandExe commandExe = CommandExe();
|
||||
|
||||
|
||||
Cron? cron;
|
||||
int nextStartTime = 0;
|
||||
|
||||
|
|
@ -41,18 +40,18 @@ class IsolateScheduler extends IsolateBase {
|
|||
|
||||
@override
|
||||
void onReady(Object? initData) async {
|
||||
while(true) {
|
||||
while (true) {
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
|
||||
if(file.existsSync()) {
|
||||
if (file.existsSync()) {
|
||||
var updated = false;
|
||||
var hash = await FileHasher.hash(file);
|
||||
if(hash != fileHash) {
|
||||
if (hash != fileHash) {
|
||||
updated = true;
|
||||
fileHash = hash;
|
||||
//파일 내용이 바뀔때 마다 새로 읽어 들임
|
||||
var map = Application.getMapFromYamlA(await file.readAsString());
|
||||
|
||||
|
||||
//============ Validate yaml format ============//
|
||||
try {
|
||||
build = DataBuild.fromJson(map!);
|
||||
|
|
@ -60,44 +59,47 @@ class IsolateScheduler extends IsolateBase {
|
|||
onError('Failed to parse yaml file.');
|
||||
return;
|
||||
}
|
||||
if(build.scheduler == null) {
|
||||
if (build.scheduler == null) {
|
||||
onError('Scheduler entry does not exist within yaml.');
|
||||
return;
|
||||
}
|
||||
|
||||
var scheduler = build.scheduler!;
|
||||
if(scheduler.cron == null && scheduler.interval == null) {
|
||||
onError('A scheduler script must have either a cron entry or an interval entry.');
|
||||
if (scheduler.cron == null && scheduler.interval == null) {
|
||||
onError(
|
||||
'A scheduler script must have either a cron entry or an interval entry.');
|
||||
return;
|
||||
}
|
||||
|
||||
if(scheduler.cron != null) {
|
||||
if (scheduler.cron != null) {
|
||||
try {
|
||||
Schedule.parse(scheduler.cron!);
|
||||
cronExpress = scheduler.cron!;
|
||||
} on Error {
|
||||
onError("Cron express '${build.scheduler!.cron}' is not a suitable format.");
|
||||
onError(
|
||||
"Cron express '${build.scheduler!.cron}' is not a suitable format.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(scheduler.interval != null) {
|
||||
if (scheduler.interval != null) {
|
||||
interval = scheduler.interval!;
|
||||
}
|
||||
|
||||
logEnable = scheduler.enableLog == null ? false : scheduler.enableLog!;
|
||||
logEnable =
|
||||
scheduler.enableLog == null ? false : scheduler.enableLog!;
|
||||
|
||||
schedulerInterval?.activate = false;
|
||||
}
|
||||
|
||||
//============ execute cron/interval ============//
|
||||
if(cronExpress != null) {
|
||||
if (cronExpress != null) {
|
||||
//Use cron
|
||||
if(cronClosed) {
|
||||
if (cronClosed) {
|
||||
cronClosed = false;
|
||||
cron = Cron();
|
||||
cron!.schedule(Schedule.parse(cronExpress!), () async {
|
||||
if(notProgress) {
|
||||
if (notProgress) {
|
||||
await execute(build);
|
||||
cronClosed = true;
|
||||
await cron!.close();
|
||||
|
|
@ -106,14 +108,14 @@ class IsolateScheduler extends IsolateBase {
|
|||
}
|
||||
} else {
|
||||
//Use interval
|
||||
if(updated) {
|
||||
if (updated) {
|
||||
schedulerInterval = SchedulerInterval(interval!, build, execute);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//file이 없을시 종료
|
||||
onError("The file '${file.path}' does not exist.");
|
||||
if(cron != null) await cron?.close();
|
||||
if (cron != null) await cron?.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -122,8 +124,9 @@ class IsolateScheduler extends IsolateBase {
|
|||
Future execute(DataBuild data) async {
|
||||
send(IsoMessege('log', data: "Scheduler '$alias' has started."));
|
||||
notProgress = false;
|
||||
logFile = File('$logsPath/${alias}_${getDate()}_${getTime().replaceAll(':', '')}_[$pid].txt');
|
||||
if(data.scheduler!.enableLog ?? false) {
|
||||
logFile = File(
|
||||
'$logsPath/[$pid]_${alias}_${getDate()}_${getTime().replaceAll(':', '')}.txt');
|
||||
if (data.scheduler!.enableLog ?? false) {
|
||||
log('Start process on pid [$pid]');
|
||||
}
|
||||
await commandExe.executeScheduler(data, logEnable, logFile.path);
|
||||
|
|
@ -133,7 +136,8 @@ class IsolateScheduler extends IsolateBase {
|
|||
}
|
||||
|
||||
void log(String message) {
|
||||
logFile.writeAsStringSync('[${getDates()}] $message\n', mode: FileMode.append, flush: true);
|
||||
logFile.writeAsStringSync('[${getDates()}] $message\n',
|
||||
mode: FileMode.append, flush: true);
|
||||
}
|
||||
|
||||
void logError(Exception e, StackTrace stacktace) {
|
||||
|
|
@ -149,6 +153,7 @@ class IsolateScheduler extends IsolateBase {
|
|||
}
|
||||
|
||||
void sendTerminated(String type, String message) {
|
||||
send(IsoMessege('terminated', data: {'type': type, 'message': message, 'alias': alias}));
|
||||
send(IsoMessege('terminated',
|
||||
data: {'type': type, 'message': message, 'alias': alias}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class SchedulerManager {
|
|||
ProcessInfo? _currentScheduler;
|
||||
final Map<String, IsolateHandler> _map = {};
|
||||
final logFile = File(
|
||||
'$_logsPath/scheduler_${getDate()}_${getTime().replaceAll(':', '')}_[$pid].txt');
|
||||
'$_logsPath/[$pid]_scheduler_${getDate()}_${getTime().replaceAll(':', '')}.txt');
|
||||
|
||||
String get exePath {
|
||||
return throw UnimplementedError('Unimplemented exePath');
|
||||
|
|
|
|||
Loading…
Reference in a new issue