log policying
This commit is contained in:
parent
6a6df5c8f5
commit
95c08139d7
1 changed files with 35 additions and 15 deletions
|
|
@ -109,10 +109,15 @@ class SchedulerManager {
|
|||
return throw Exception("There is no scheduler called '$alias'.");
|
||||
}
|
||||
|
||||
await checkTerminate();
|
||||
}
|
||||
|
||||
Future checkTerminate() async {
|
||||
if(schedulers.isEmpty) {
|
||||
await terminate();
|
||||
await unregistStartup();
|
||||
await terminate();
|
||||
}
|
||||
return simpleFuture;
|
||||
}
|
||||
|
||||
Future showList() async {
|
||||
|
|
@ -156,10 +161,6 @@ class SchedulerManager {
|
|||
return simpleFuture;
|
||||
}
|
||||
|
||||
Future checkSchedules() async {
|
||||
return simpleFuture;
|
||||
}
|
||||
|
||||
Future checkProcess() async {
|
||||
//process check
|
||||
var processes = await findProcess('scheduler -s');
|
||||
|
|
@ -205,15 +206,16 @@ class SchedulerManager {
|
|||
}
|
||||
|
||||
//======================== other process ========================//
|
||||
final logFile = File('$logsPath/scheduler.txt');
|
||||
final logFile = File('$logsPath/scheduler_${getDate()}_${getTime().replaceAll(':', '')}_[$pid].txt');
|
||||
Future start() async {
|
||||
log('Scheduler is running on pid [$pid].');
|
||||
while(true) {
|
||||
//매초 마다 등록된 파일이 있나 체크
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
var scheduleList = schedulers;
|
||||
for(var alias in scheduleList) {
|
||||
if(!_map.containsKey(alias)) {
|
||||
await logFile.writeAsString('Schduler started: $alias\n', mode: FileMode.append);
|
||||
log('Schduler started: $alias');
|
||||
var handler = IsolateManager.create(IsolateScheduler({'alias': alias, 'root': schedulerPath, 'logs': logsPath}));
|
||||
//To-do: 종료시 사유(by user, by error)에 따라 json에 내용을 기입하여 재실행 안하도록
|
||||
handler.addListener('terminated', onTerminated );
|
||||
|
|
@ -223,12 +225,29 @@ class SchedulerManager {
|
|||
}
|
||||
}
|
||||
|
||||
void onTerminated(Object? data) {
|
||||
void onTerminated(Object? data) async {
|
||||
var map = data as Map;
|
||||
var alias = data['alias'] as String;
|
||||
var type = data['type'] as String;
|
||||
var message = data['message'] as String;
|
||||
_map.remove(alias);
|
||||
var alias = map['alias'] as String;
|
||||
var type = map['type'] as String;
|
||||
var message = map['message'] as String;
|
||||
var handler = _map.remove(alias);
|
||||
handler!.exit();
|
||||
switch(type) {
|
||||
case 'error':
|
||||
log('[Error] $message');
|
||||
break;
|
||||
}
|
||||
|
||||
if(schedulers.isEmpty) log('Scheduler operation stopped.');
|
||||
await checkTerminate();
|
||||
}
|
||||
|
||||
void log(String message) {
|
||||
logFile.writeAsStringSync('[${getDates()}] $message\n', mode: FileMode.append, flush: true);
|
||||
}
|
||||
|
||||
void logError(Exception e, StackTrace stacktace) {
|
||||
log('[${e.toString()}]\n${stacktace.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -304,6 +323,7 @@ class IsolateScheduler extends IsolateBase {
|
|||
} else {
|
||||
//file이 없을시 종료
|
||||
onError("The file '${file.path}' does not exist.");
|
||||
if(cron != null) await cron?.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -311,9 +331,9 @@ class IsolateScheduler extends IsolateBase {
|
|||
|
||||
Future execute(DataBuild data) async {
|
||||
notProgress = false;
|
||||
logFile = File('$logsPath/${alias}_${getDate()}_${getTime().replaceAll(':', '.')}.txt');
|
||||
log('Execute task: ${DateTime.now().toString()}');
|
||||
await Future.delayed(Duration(minutes: 1, seconds: 30));
|
||||
logFile = File('$logsPath/${alias}_${getDate()}_${getTime().replaceAll(':', '')}_[$pid].txt');
|
||||
log('Start process on pid [$pid]');
|
||||
await Future.delayed(Duration(minutes: 1, seconds: 30)); //To-do: delete test, exe task
|
||||
notProgress = true;
|
||||
return simpleFuture;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue