Skip to content

Commit

Permalink
Fixing a bug related to expired jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandonogueira committed Feb 21, 2018
1 parent df49b66 commit 87b14f3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.6.2</version>
<version>3.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/okra/OkraSyncImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
import okra.base.sync.AbstractOkraSync;
import okra.exception.InvalidOkraItemException;
import okra.exception.OkraItemNotFoundException;
import okra.exception.OkraRuntimeException;
import okra.index.IndexCreator;
import okra.serialization.DocumentSerializer;
import okra.util.DateUtil;
import okra.util.QueryUtil;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bson.types.ObjectId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;
import java.util.Date;
Expand All @@ -50,6 +51,7 @@ public class OkraSyncImpl<T extends OkraItem> extends AbstractOkraSync<T> {
private final Class<T> scheduleItemClass;
private final long defaultHeartbeatExpirationMillis;
private final DocumentSerializer serializer;
private static final Logger LOGGER = LoggerFactory.getLogger(OkraSyncImpl.class);

public OkraSyncImpl(final MongoClient client, final String database,
final String collection, final Class<T> scheduleItemClass,
Expand Down Expand Up @@ -78,8 +80,7 @@ public Optional<T> poll() {

@Override
public Optional<T> peek() {
final Bson peekQuery = QueryUtil.generatePeekQuery(defaultHeartbeatExpirationMillis);

final Bson peekQuery = QueryUtil.generatePeekQuery(defaultHeartbeatExpirationMillis / 1000);
final Document update = new Document();
update.put("heartbeat", new Date());
update.put("status", OkraStatus.PROCESSING.name());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/okra/util/QueryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static Document generateRunDateQueryPart() {
public static Document generateStatusProcessingAndHeartbeatExpiredQuery(final long secondsToGetExpired) {
final Document query = new Document();
query.put("status", OkraStatus.PROCESSING.name());
query.put("heartbeat", DateUtil.nowMinusSeconds(secondsToGetExpired));
query.put("heartbeat", new BasicDBObject("$lt", DateUtil.nowMinusSeconds(secondsToGetExpired)));
return query;
}

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/testcontainers.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
checks.disable=true

0 comments on commit 87b14f3

Please sign in to comment.