Skip to content

Commit

Permalink
Updated AsyncResponseConsumer STOP logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lwj5 committed Mar 4, 2019
1 parent 568940b commit 8b55fcd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -10,7 +10,7 @@

<groupId>ai.preferred</groupId>
<artifactId>venom</artifactId>
<version>4.1.3</version>
<version>4.1.4-SNAPSHOT</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/ai/preferred/venom/Crawler.java
Expand Up @@ -16,10 +16,7 @@

package ai.preferred.venom;

import ai.preferred.venom.fetcher.AsyncFetcher;
import ai.preferred.venom.fetcher.Callback;
import ai.preferred.venom.fetcher.Fetcher;
import ai.preferred.venom.fetcher.StopCodeException;
import ai.preferred.venom.fetcher.*;
import ai.preferred.venom.job.AbstractQueueScheduler;
import ai.preferred.venom.job.Job;
import ai.preferred.venom.job.PriorityQueueScheduler;
Expand All @@ -28,6 +25,7 @@
import ai.preferred.venom.request.Request;
import ai.preferred.venom.response.Response;
import ai.preferred.venom.response.VResponse;
import ai.preferred.venom.validator.Validator;
import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -706,7 +704,8 @@ public void completed(final Request request, final Response response) {
public void failed(final Request request, final Exception ex) {
crawler.connections.release();
crawler.threadPool.execute(() -> {
if (ex instanceof StopCodeException) {
if (ex instanceof StopCodeException
|| (ex instanceof ValidationException && ((ValidationException) ex).getStatus() == Validator.Status.STOP)) {
crawler.pendingJobs.remove(job);
} else {
synchronized (crawler.pendingJobs) {
Expand Down
Expand Up @@ -265,7 +265,7 @@ protected final BaseResponse buildResult(final HttpContext context) throws Excep
}

if (status == Validator.Status.STOP) {
throw new StopCodeException(statusCode, "Validator stopped the request.");
throw new ValidationException(status, response, "Validator stopped the request.");
} else if (status != Validator.Status.VALID) {
throw new ValidationException(status, response, "Invalid response.");
}
Expand Down

0 comments on commit 8b55fcd

Please sign in to comment.