Skip to content

Commit

Permalink
Add option to only execute a single given job
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens authored and vogti committed Jul 30, 2024
1 parent 8add3a7 commit e5bc27f
Showing 1 changed file with 45 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.model.ZipParameters;
Expand All @@ -72,6 +74,10 @@ public abstract class AbstractChronosAgent extends Thread {
private final AbortedMonitor abortedMonitor = new AbortedMonitor();
private final ChronosHttpClient chronos;

@Getter
@Setter
private Integer singleJobId = null;

private volatile boolean running = true;
private volatile Thread agent;

Expand Down Expand Up @@ -148,40 +154,45 @@ public void run() {

// (1) Requesting new job
final ChronosJob job;
try {
if ( !alreadyPrintedWaitingForJob ) {
log.info( "Requesting new job." );
}
job = this.chronos.getNextJob( getSupportedSystemNames(), getEnvironment() ); // throws NoSuchElementException, ChronosException, IOException, InterruptedException
} catch ( NoSuchElementException ex ) {
if ( !alreadyPrintedWaitingForJob ) {
log.debug( "No job scheduled.", ex );
System.out.print( "Waiting for job" );
alreadyPrintedWaitingForJob = true;
} else {
System.out.print( "." );
}

if ( singleJobId == null ) {
try {
SLEEPING_TIME_UNIT.sleep( SLEEPING_TIME_VALUE );
} catch ( InterruptedException ignored2 ) {
// Ignore. Maybe this agent is to be shutdown.
}

continue mainLoop; // !! Important !! -- Reloop

} catch ( Exception ex ) {
log.error( "IOException for chronos.getNextJob(" + Arrays.toString( getSupportedSystemNames() ) + "," + getEnvironment() + ")", ex );
if ( !alreadyPrintedWaitingForJob ) {
log.info( "Requesting new job." );
}
job = this.chronos.getNextJob( getSupportedSystemNames(), getEnvironment() ); // throws NoSuchElementException, ChronosException, IOException, InterruptedException
} catch ( NoSuchElementException ex ) {
if ( !alreadyPrintedWaitingForJob ) {
log.debug( "No job scheduled.", ex );
System.out.print( "Waiting for job" );
alreadyPrintedWaitingForJob = true;
} else {
System.out.print( "." );
}

try {
SLEEPING_TIME_UNIT.sleep( SLEEPING_TIME_VALUE );
} catch ( InterruptedException ignored2 ) {
// Ignore. Maybe this agent is to be shutdown.
}

continue mainLoop; // !! Important !! -- Reloop

} catch ( Exception ex ) {
log.error( "IOException for chronos.getNextJob(" + Arrays.toString( getSupportedSystemNames() ) + "," + getEnvironment() + ")", ex );

try {
SLEEPING_TIME_UNIT.sleep( SLEEPING_TIME_VALUE );
} catch ( InterruptedException ignored ) {
// Ignore. Maybe this agent is to be shutdown.
}

alreadyPrintedWaitingForJob = false;
continue mainLoop; // !! Important !! -- Reloop

try {
SLEEPING_TIME_UNIT.sleep( SLEEPING_TIME_VALUE );
} catch ( InterruptedException ignored ) {
// Ignore. Maybe this agent is to be shutdown.
}

alreadyPrintedWaitingForJob = false;
continue mainLoop; // !! Important !! -- Reloop

} else {
job = this.chronos.getJob( singleJobId );
this.running = false; // only execute loop once
}
alreadyPrintedWaitingForJob = false;

Expand Down Expand Up @@ -732,6 +743,9 @@ private void cancelAndRemoveObservable() {
AbortedMonitor.this.tasks.remove( this.observable );
this.cancel();
}

}

}

}

0 comments on commit e5bc27f

Please sign in to comment.