HOOK-58:Fix resend policy (#32)

* HOOK-58:Fix resend policy

* Fixed test

* Fixed delays count
This commit is contained in:
Inal Arsanukaev 2017-10-18 18:56:26 +03:00 committed by GitHub
parent 7155ccb555
commit 1f874c3940
3 changed files with 13 additions and 6 deletions

View File

@ -27,7 +27,11 @@ public class SimpleRetryPolicy implements RetryPolicy<SimpleRetryPolicyRecord> {
@Autowired
TaskDao taskDao;
private long[] delays = {30, 300, 900, 3600}; //in seconds
private long[] delays = {30, 300, 900, 3600,
3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600,
3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600,
3600, 3600, 3600, 3600
}; //in seconds
@Override
public RetryPolicyType getType() {

View File

@ -11,6 +11,7 @@ import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.List;
/**
@ -43,15 +44,17 @@ public class MessageSender implements Runnable {
final String signature = signer.sign(messageJson, hook.getPrivKey());
int statusCode = postSender.doPost(hook.getUrl(), messageJson, signature);
if (statusCode != HttpStatus.SC_OK) {
log.warn("Wrong status code " + statusCode + " from merchant. Message id = " + message.getId());
throw new PostRequestException("Internal server error for message id = " + message.getId());
log.warn("Wrong status code {} from merchant, but we don't try to resend it. MessageId {}, invoiceId {}", statusCode, message.getId(), message.getInvoice().getId());
//TODO RESTORE IT
// throw new PostRequestException("Internal server error for message id = " + message.getId());
} else {
log.info("{} is sent to {}", message, hook);
}
log.info("{} is sent to {}", message, hook);
taskDao.remove(hook.getId(), message.getId()); //required after message is sent
}
workerTaskScheduler.done(hook); // required after all messages processed
} catch (Exception e) {
log.warn("Couldn't send message to hook: " + hook.toString(), e);
log.warn("Couldn't send message to hook {}. We'll try to resend it", hook.toString(), e);
workerTaskScheduler.fail(hook); // required if fail to send message
}
}

View File

@ -133,7 +133,7 @@ public class DataflowTest extends AbstractIntegrationTest {
Thread.sleep(1000);
hook = hookDao.getHookById(hook.getId());
assertFalse(hook.isEnabled());
assertTrue(hook.isEnabled());
}
private static Hook hook(String partyId, String url, EventType... types) {