Skip to content

Commit

Permalink
Issue #139: Add a sleep input to executeForEachEntryOf
Browse files Browse the repository at this point in the history
Correction after PR review
  • Loading branch information
TNohaic committed Mar 29, 2024
1 parent 206c124 commit c00718c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.sentrysoftware.metricshub.engine.connector.deserializer.custom.NonBlankDeserializer;
import org.sentrysoftware.metricshub.engine.connector.deserializer.custom.PositiveIntegerDeserializer;

/**
* Represents a configuration for executing an operation for each entry of a specified source.
Expand Down Expand Up @@ -65,6 +66,7 @@ public class ExecuteForEachEntryOf implements Serializable {
/**
* The sleep integer in ms.
*/
@JsonDeserialize(using = PositiveIntegerDeserializer.class)
@JsonSetter(nulls = SKIP)
private Integer sleep;

Expand All @@ -84,7 +86,7 @@ public ExecuteForEachEntryOf(
) {
this.source = source;
this.concatMethod = concatMethod == null ? EntryConcatMethod.LIST : concatMethod;
this.sleep = sleep == null ? 0 : sleep;
this.sleep = sleep;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,14 @@ private SourceTable processExecuteForEachEntryOf(final Source source, final Stri
copy.update(value -> replaceSourceReference(value, copy));

concatEntryResult(source, result, row, copy.accept(sourceProcessor));
if (sleep != null && sleep > 0) {
if (sleep != null && sleep != 0) {
try {
Thread.sleep(sleep);
} catch (InterruptedException e) {
log.error("threadSleep", "Thread interrupted during sleep between two requests.");
log.error(
"Hostname {} - Thread interrupted during sleep between two 'execute for each entry' requests.",
hostname
);
Thread.currentThread().interrupt();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void testProcessHTTPSourceExecuteForEachEntrySleep() {
ExecuteForEachEntryOf.builder().source(ENCLOSURE_COLLECT_SOURCE_1).concatMethod(EntryConcatMethod.LIST).build()
);

assertEquals(0, httpSource.getSleepExecuteForEachEntryOf());
assertEquals(null, httpSource.getSleepExecuteForEachEntryOf());

httpSource.setExecuteForEachEntryOf(
ExecuteForEachEntryOf
Expand Down

0 comments on commit c00718c

Please sign in to comment.