mirror of https://github.com/reiseburo/whoas
Merge from pull request #23
This commit is contained in:
commit
8b3010fce6
|
@ -35,9 +35,12 @@ dependencies {
|
|||
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.3+'
|
||||
/* Needed for better time management/sanity */
|
||||
compile 'joda-time:joda-time:2.6+'
|
||||
/* redis client */
|
||||
/* Needed for redis client */
|
||||
compile 'redis.clients:jedis:2.6+'
|
||||
testCompile 'com.fiftyonred:mock-jedis:0.4.0'
|
||||
/* Needed for logback */
|
||||
compile 'org.slf4j:slf4j-api:1.7.10'
|
||||
compile 'ch.qos.logback:logback-classic:1.1.2'
|
||||
|
||||
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
|
||||
testCompile 'cglib:cglib-nodep:2.2.+'
|
||||
|
|
|
@ -570,7 +570,7 @@ See the example below</p>
|
|||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Last updated 2015-03-19 17:23:59 EDT
|
||||
Last updated 2015-03-23 11:00:34 EDT
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 11:00:01 PDT 2015 -->
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 14:03:01 EDT 2015 -->
|
||||
<title>AbstractHookQueue (whoas 0.1.5 API)</title>
|
||||
<meta name="date" content="2015-03-25">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 11:00:01 PDT 2015 -->
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 14:03:01 EDT 2015 -->
|
||||
<title>AbstractHookRunner (whoas 0.1.5 API)</title>
|
||||
<meta name="date" content="2015-03-25">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 11:00:01 PDT 2015 -->
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 14:03:01 EDT 2015 -->
|
||||
<title>HookRequest (whoas 0.1.5 API)</title>
|
||||
<meta name="date" content="2015-03-25">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
|
@ -120,8 +120,8 @@ if (location.href.indexOf('is-external=true') == -1) {
|
|||
|
||||
<tr class="rowColor">
|
||||
<td class="colFirst">
|
||||
<code><a href="#HookRequest(java.lang.String, java.lang.String, java.lang.String)">HookRequest</a></strong>
|
||||
(java.lang.String hookUrl, java.lang.String hookData, java.lang.String contentType)</code><br>Default constructor for creating a simple HookRequest with a URL and the
|
||||
<code><a href="#HookRequest(java.lang.String, java.lang.String)">HookRequest</a></strong>
|
||||
(java.lang.String hookUrl, java.lang.String hookData)</code><br>Default constructor for creating a simple HookRequest with a URL and the
|
||||
POST data to be delivered to that URL</td>
|
||||
</tr>
|
||||
|
||||
|
@ -186,10 +186,10 @@ if (location.href.indexOf('is-external=true') == -1) {
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<a name="HookRequest(java.lang.String, java.lang.String, java.lang.String)"><!-- --></a>
|
||||
<a name="HookRequest(java.lang.String, java.lang.String)"><!-- --></a>
|
||||
<ul class="blockListLast">
|
||||
<li class="blockList">
|
||||
<h4><strong>HookRequest</strong>(java.lang.String hookUrl, java.lang.String hookData, java.lang.String contentType)</h4>
|
||||
<h4><strong>HookRequest</strong>(java.lang.String hookUrl, java.lang.String hookData)</h4>
|
||||
<p> Default constructor for creating a simple HookRequest with a URL and the
|
||||
POST data to be delivered to that URL
|
||||
</p>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 11:00:01 PDT 2015 -->
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 14:03:01 EDT 2015 -->
|
||||
<title>InMemoryQueue (whoas 0.1.5 API)</title>
|
||||
<meta name="date" content="2015-03-25">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 11:00:01 PDT 2015 -->
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 14:03:02 EDT 2015 -->
|
||||
<title>Publisher (whoas 0.1.5 API)</title>
|
||||
<meta name="date" content="2015-03-25">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 11:00:01 PDT 2015 -->
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 14:03:02 EDT 2015 -->
|
||||
<title>RedisQueue (whoas 0.1.5 API)</title>
|
||||
<meta name="date" content="2015-03-25">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
|
@ -195,7 +195,7 @@ if (location.href.indexOf('is-external=true') == -1) {
|
|||
|
||||
<tr class="rowColor">
|
||||
<td class="colFirst"><code>java.lang.Object</strong></code></td>
|
||||
<td class="colLast"><code><strong><a href="#withRedis(groovy.lang.Closure)">withRedis</a></strong>(groovy.lang.Closure closure)</code><br></td>
|
||||
<td class="colLast"><code><strong><a href="#withRedis(groovy.lang.Closure)">withRedis</a></strong>(groovy.lang.Closure closure)</code><br>Allocate redis client from the pool</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
@ -340,7 +340,7 @@ void <strong>stop</strong>()</h4>
|
|||
<ul class="blockListLast">
|
||||
<li class="blockList">
|
||||
<h4>java.lang.Object <strong>withRedis</strong>(groovy.lang.Closure closure)</h4>
|
||||
<p></p>
|
||||
<p> Allocate redis client from the pool </p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 11:00:01 PDT 2015 -->
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 14:03:02 EDT 2015 -->
|
||||
<title>SequentialHookRunner (whoas 0.1.5 API)</title>
|
||||
<meta name="date" content="2015-03-25">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 11:00:01 PDT 2015 -->
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 14:03:02 EDT 2015 -->
|
||||
<title>WhoasConfiguration (whoas 0.1.5 API)</title>
|
||||
<meta name="date" content="2015-03-25">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 11:00:01 PDT 2015 -->
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 14:03:02 EDT 2015 -->
|
||||
<title>WhoasFactory (whoas 0.1.5 API)</title>
|
||||
<meta name="date" content="2015-03-25">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
|
@ -268,7 +268,7 @@ java.lang.String <strong>runnerType</strong></h4>
|
|||
InstantiationException - if this Class represents an abstract class, an interface,
|
||||
an array class, a primitive type, or void
|
||||
or if the class has no nullary constructor
|
||||
or if the instantiation fails for some other reason. <DL><DT><B>Returns:</B></DT><DD></DD></DL><DL><DT><B>Parameters:</B></DT><DD><code>hookQueue</code> - queue to associate with allocated runner</DD></DL></p>
|
||||
or if the instantiation fails for some other reason. <DL><DT><B>Parameters:</B></DT><DD><code>hookQueue</code> - queue to associate with allocated runner</DD></DL><DL><DT><B>Returns:</B></DT><DD></DD></DL></p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 11:00:01 PDT 2015 -->
|
||||
<!-- Generated by groovydoc (2.4.0) on Wed Mar 25 14:03:02 EDT 2015 -->
|
||||
<title>WhoasQueueConfig (whoas 0.1.5 API)</title>
|
||||
<meta name="date" content="2015-03-25">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
|
|
|
@ -180,7 +180,7 @@ if (location.href.indexOf('is-external=true') == -1) {
|
|||
|
||||
<dt><span class="strong"><a href="com/github/lookout/whoas/HookRequest.html" title="Class in com.github.lookout.whoas">HookRequest</a></span> - Class in <a href="./com/github/lookout/whoas/package-summary.html">com.github.lookout.whoas</a>
|
||||
</dt><dd><div class="block"></div></dd>
|
||||
<dt><span class="strong"><a href="com/github/lookout/whoas/HookRequest.html#HookRequest(java.lang.String, java.lang.String, java.lang.String)" title="Constructor in HookRequest">HookRequest(String, String, String)</a></span> - Constructor in <a href="com/github/lookout/whoas/HookRequest.html">HookRequest</a>
|
||||
<dt><span class="strong"><a href="com/github/lookout/whoas/HookRequest.html#HookRequest(java.lang.String, java.lang.String)" title="Constructor in HookRequest">HookRequest(String, String)</a></span> - Constructor in <a href="com/github/lookout/whoas/HookRequest.html">HookRequest</a>
|
||||
</dt><dd> <div class="block">Default constructor for creating a simple HookRequest with a URL and the
|
||||
POST data to be delivered to that URL</div></dd>
|
||||
</dl>
|
||||
|
@ -355,7 +355,7 @@ if (location.href.indexOf('is-external=true') == -1) {
|
|||
<dt><span class="strong"><a href="com/github/lookout/whoas/WhoasQueueConfig.html" title="Class in com.github.lookout.whoas">WhoasQueueConfig</a></span> - Class in <a href="./com/github/lookout/whoas/package-summary.html">com.github.lookout.whoas</a>
|
||||
</dt><dd><div class="block">Whoas Queue Configuration</div></dd>
|
||||
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisQueue.html#withRedis(groovy.lang.Closure)" title="Method in RedisQueue">withRedis(Closure)</a></span> - Method in <a href="com/github/lookout/whoas/RedisQueue.html">RedisQueue</a>
|
||||
</dt><dd> <div class="block"></div></dd>
|
||||
</dt><dd> <div class="block">Allocate redis client from the pool</div></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
|
|
@ -2,12 +2,16 @@ package com.github.lookout.whoas
|
|||
|
||||
import java.util.Queue
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
|
||||
/**
|
||||
* A simple in-memory queue that offers no persistence between process restarts
|
||||
*/
|
||||
class InMemoryQueue extends AbstractHookQueue {
|
||||
private Queue<HookRequest> internalQueue
|
||||
private Logger logger = LoggerFactory.getLogger(InMemoryQueue.class)
|
||||
|
||||
/**
|
||||
* Create the InMemoryQueue from configuration
|
||||
|
@ -55,7 +59,9 @@ class InMemoryQueue extends AbstractHookQueue {
|
|||
action.call(item)
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
/* Put this back on the tail end of the queue */
|
||||
logger.info("\"Pop\" on in-memory queue failed, putting it back on the tail-end", ex)
|
||||
this.internalQueue.put(item)
|
||||
}
|
||||
finally {
|
||||
|
|
|
@ -6,6 +6,8 @@ import javax.ws.rs.client.Entity
|
|||
import javax.ws.rs.client.Invocation
|
||||
import javax.ws.rs.core.Response
|
||||
import javax.ws.rs.ProcessingException
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
|
||||
/**
|
||||
|
@ -22,13 +24,13 @@ class Publisher {
|
|||
|
||||
private Client jerseyClient
|
||||
private int maxRetries
|
||||
private Logger logger = LoggerFactory.getLogger(Publisher.class)
|
||||
|
||||
Publisher() {
|
||||
this.jerseyClient = ClientBuilder.newClient()
|
||||
this.maxRetries = DEFAULT_MAX_RETRIES
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Publish the request using the appropriate backoff and retry logic
|
||||
* defined in the Whoas documentation
|
||||
|
@ -39,18 +41,17 @@ class Publisher {
|
|||
Invocation inv = buildInvocationFrom(request)
|
||||
try {
|
||||
response = inv.invoke()
|
||||
|
||||
/* LOG: response */
|
||||
String responseBody = response.readEntity(String.class)
|
||||
}
|
||||
catch (ProcessingException exc) {
|
||||
/* LOG: warn on this exception */
|
||||
logger.warn("\"POST\" to url: \"${request.url}\" failed", exc)
|
||||
retryableExc = true
|
||||
}
|
||||
|
||||
if ((retryableExc) || (shouldRetry(response))) {
|
||||
if (request.retries >= this.maxRetries) {
|
||||
/* TODO: Log that we're giving up on this request */
|
||||
logger.error("Giving up on \"POST\" to url: \"${request.url}\" " +
|
||||
"after ${request.retries} retries")
|
||||
return false
|
||||
}
|
||||
request.retries = (request.retries + 1)
|
||||
|
@ -58,10 +59,10 @@ class Publisher {
|
|||
return this.publish(request)
|
||||
}
|
||||
|
||||
logger.debug("\"POST\" to url: \"${request.url}\" succeeded")
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether this response meets our criteria for retry
|
||||
*/
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
|||
import redis.clients.jedis.Jedis
|
||||
import redis.clients.jedis.JedisPool
|
||||
import redis.clients.jedis.JedisPoolConfig
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
|
||||
/**
|
||||
|
@ -15,6 +17,7 @@ class RedisQueue extends AbstractHookQueue {
|
|||
private static Integer maxActiveConnections = 10
|
||||
private static Integer maxIdleConnections = 5
|
||||
private static Integer minIdleConnections = 1
|
||||
private Logger logger = LoggerFactory.getLogger(RedisQueue.class)
|
||||
|
||||
/**
|
||||
* Create the RedisQueue with valid config
|
||||
|
@ -49,6 +52,9 @@ class RedisQueue extends AbstractHookQueue {
|
|||
void start() {
|
||||
super.start()
|
||||
|
||||
logger.debug("Setting up redis queue \"${this.queueConfig.key}\" on the server " +
|
||||
"\"${this.queueConfig.hostname}:${this.queueConfig.port}")
|
||||
|
||||
/**
|
||||
* Setup jedis pool
|
||||
*
|
||||
|
@ -79,6 +85,7 @@ class RedisQueue extends AbstractHookQueue {
|
|||
pool = null
|
||||
}
|
||||
|
||||
/** Allocate redis client from the pool */
|
||||
Object withRedis(Closure closure) {
|
||||
Jedis redisClient = pool.resource
|
||||
try {
|
||||
|
@ -120,8 +127,8 @@ class RedisQueue extends AbstractHookQueue {
|
|||
action.call(request)
|
||||
} catch (Exception ex) {
|
||||
/* Put this back on the front of the queue */
|
||||
logger.info("\"Pop\" on redis queue failed, pushing it back on front of the queue", ex)
|
||||
redisClient.lpush(this.queueConfig.key, messages.get(1))
|
||||
throw ex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,12 +80,12 @@ class InMemoryQueueSpecWithMessage extends InMemoryQueueWithGivenQueueSpec {
|
|||
}
|
||||
|
||||
def "pop() should requeue on exceptions"() {
|
||||
setup:
|
||||
when:
|
||||
queue.pop {
|
||||
throw new Exception("Spock'd!")
|
||||
}
|
||||
|
||||
expect:
|
||||
then:
|
||||
queue.size == 1
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,6 @@ class RedisQueueSpec extends Specification {
|
|||
queue.pop() { throw new Exception("Test Exception") }
|
||||
|
||||
then:
|
||||
thrown Exception
|
||||
queue.getSize() == 1
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue