|
|
@ -1,9 +1,11 @@ |
|
|
|
package com.my.graphiteDigesterBg.diframe; |
|
|
|
import com.my.graphiteDigesterBg.diframe.model.DiMdbNotification; |
|
|
|
import com.my.graphiteDigesterBg.diframe.model.DiMdbTaskExecution; |
|
|
|
import com.my.graphiteDigesterBg.diframe.model.DiMdbUser; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import javax.management.Notification; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
@ -47,6 +49,11 @@ abstract public class DiTaskBase implements DiTask { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void prepare() { |
|
|
|
// implement this method in subclass |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void init() { |
|
|
|
Task task = this.getClass().getAnnotation(Task.class); |
|
|
|
this.execution.name = task.name(); |
|
|
@ -66,6 +73,12 @@ abstract public class DiTaskBase implements DiTask { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// set runtime message |
|
|
|
protected void setRuntimeMessage( String message ) { |
|
|
|
this.execution.message = message; |
|
|
|
this.execution.save(); |
|
|
|
} |
|
|
|
|
|
|
|
// set runtime status |
|
|
|
protected void setRuntimeStatus( String status ) { |
|
|
|
this.execution.runtimeStatus = status; |
|
|
@ -114,10 +127,12 @@ abstract public class DiTaskBase implements DiTask { |
|
|
|
try { |
|
|
|
this.execute(); |
|
|
|
} catch ( Exception e ) { |
|
|
|
this.onError(e); |
|
|
|
this.execution.status = "ERROR"; |
|
|
|
this.execution.message = e.getMessage(); |
|
|
|
this.execution.save(); |
|
|
|
this.status = TaskStatus.FINISHED; |
|
|
|
DiMdbNotification.taskError(this, e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -171,4 +186,14 @@ abstract public class DiTaskBase implements DiTask { |
|
|
|
public DiTaskAction getAction(String name) { |
|
|
|
return this.actions.get(name); |
|
|
|
} |
|
|
|
|
|
|
|
// error handler |
|
|
|
protected void onError( Exception e ) { |
|
|
|
// implement this method in subclass |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public DiTaskStep getStep() { |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |