Skip to content

Commit e5bc27f

Browse files
gartensvogti
authored andcommitted
Add option to only execute a single given job
1 parent 8add3a7 commit e5bc27f

1 file changed

Lines changed: 45 additions & 31 deletions

File tree

src/main/java/ch/unibas/dmi/dbis/chronos/agent/AbstractChronosAgent.java

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ of this software and associated documentation files (the "Software"), to deal
4646
import java.util.concurrent.ConcurrentHashMap;
4747
import java.util.concurrent.TimeUnit;
4848
import java.util.concurrent.atomic.AtomicInteger;
49+
import lombok.Getter;
50+
import lombok.Setter;
4951
import lombok.extern.slf4j.Slf4j;
5052
import net.lingala.zip4j.ZipFile;
5153
import net.lingala.zip4j.model.ZipParameters;
@@ -72,6 +74,10 @@ public abstract class AbstractChronosAgent extends Thread {
7274
private final AbortedMonitor abortedMonitor = new AbortedMonitor();
7375
private final ChronosHttpClient chronos;
7476

77+
@Getter
78+
@Setter
79+
private Integer singleJobId = null;
80+
7581
private volatile boolean running = true;
7682
private volatile Thread agent;
7783

@@ -148,40 +154,45 @@ public void run() {
148154

149155
// (1) Requesting new job
150156
final ChronosJob job;
151-
try {
152-
if ( !alreadyPrintedWaitingForJob ) {
153-
log.info( "Requesting new job." );
154-
}
155-
job = this.chronos.getNextJob( getSupportedSystemNames(), getEnvironment() ); // throws NoSuchElementException, ChronosException, IOException, InterruptedException
156-
} catch ( NoSuchElementException ex ) {
157-
if ( !alreadyPrintedWaitingForJob ) {
158-
log.debug( "No job scheduled.", ex );
159-
System.out.print( "Waiting for job" );
160-
alreadyPrintedWaitingForJob = true;
161-
} else {
162-
System.out.print( "." );
163-
}
164-
157+
if ( singleJobId == null ) {
165158
try {
166-
SLEEPING_TIME_UNIT.sleep( SLEEPING_TIME_VALUE );
167-
} catch ( InterruptedException ignored2 ) {
168-
// Ignore. Maybe this agent is to be shutdown.
169-
}
170-
171-
continue mainLoop; // !! Important !! -- Reloop
172-
173-
} catch ( Exception ex ) {
174-
log.error( "IOException for chronos.getNextJob(" + Arrays.toString( getSupportedSystemNames() ) + "," + getEnvironment() + ")", ex );
159+
if ( !alreadyPrintedWaitingForJob ) {
160+
log.info( "Requesting new job." );
161+
}
162+
job = this.chronos.getNextJob( getSupportedSystemNames(), getEnvironment() ); // throws NoSuchElementException, ChronosException, IOException, InterruptedException
163+
} catch ( NoSuchElementException ex ) {
164+
if ( !alreadyPrintedWaitingForJob ) {
165+
log.debug( "No job scheduled.", ex );
166+
System.out.print( "Waiting for job" );
167+
alreadyPrintedWaitingForJob = true;
168+
} else {
169+
System.out.print( "." );
170+
}
171+
172+
try {
173+
SLEEPING_TIME_UNIT.sleep( SLEEPING_TIME_VALUE );
174+
} catch ( InterruptedException ignored2 ) {
175+
// Ignore. Maybe this agent is to be shutdown.
176+
}
177+
178+
continue mainLoop; // !! Important !! -- Reloop
179+
180+
} catch ( Exception ex ) {
181+
log.error( "IOException for chronos.getNextJob(" + Arrays.toString( getSupportedSystemNames() ) + "," + getEnvironment() + ")", ex );
182+
183+
try {
184+
SLEEPING_TIME_UNIT.sleep( SLEEPING_TIME_VALUE );
185+
} catch ( InterruptedException ignored ) {
186+
// Ignore. Maybe this agent is to be shutdown.
187+
}
188+
189+
alreadyPrintedWaitingForJob = false;
190+
continue mainLoop; // !! Important !! -- Reloop
175191

176-
try {
177-
SLEEPING_TIME_UNIT.sleep( SLEEPING_TIME_VALUE );
178-
} catch ( InterruptedException ignored ) {
179-
// Ignore. Maybe this agent is to be shutdown.
180192
}
181-
182-
alreadyPrintedWaitingForJob = false;
183-
continue mainLoop; // !! Important !! -- Reloop
184-
193+
} else {
194+
job = this.chronos.getJob( singleJobId );
195+
this.running = false; // only execute loop once
185196
}
186197
alreadyPrintedWaitingForJob = false;
187198

@@ -732,6 +743,9 @@ private void cancelAndRemoveObservable() {
732743
AbortedMonitor.this.tasks.remove( this.observable );
733744
this.cancel();
734745
}
746+
735747
}
748+
736749
}
750+
737751
}

0 commit comments

Comments
 (0)