Skip to content

Hi! I cleaned up your code for you! #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Introduction –

Octobot is a task queue worker designed for reliability, ease of use, and
Octobot is a task queue worker designed for reliability, ease of use, and
throughput.

Octobot can listen on any number of queues, with any number of workers
processing messages from each. Each queue can be set at a custom priority to
Octobot can listen on any number of queues, with any number of workers
processing messages from each. Each queue can be set at a custom priority to
ensure that more system resources are available for more important tasks. AMQP
/ RabbitMQ, Redis, and Beanstalk are supported as backends, with an extensible
/ RabbitMQ, Redis, and Beanstalk are supported as backends, with an extensible
architecture to allow for additional backends to be added as needed.


Architecture –

Octobotʼs internal architecture is a shared-nothing, threadsafe design that
Octobotʼs internal architecture is a shared-nothing, threadsafe design that
allows for any number of concurrent queues and tasks to be processed at once,
limited only by system resources. Taking full advantage of parallel execution,
Octobotʼs ability to spawn multiple workers on multiple queues can be used to
Expand Down
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<zipgroupfileset dir="lib" includes="*.jar"/>
</jar>
</target>

<target name="compile_tests" depends="jar">
<mkdir dir="test/build" />
<exec executable="/bin/sh">
Expand Down
14 changes: 7 additions & 7 deletions src/com/urbanairship/octobot/Introspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void run() {
}

logger.info("Introspector launched on port: " + port);

while (true) {
try {
Socket socket = server.accept();
Expand All @@ -64,7 +64,7 @@ public void run() {
@SuppressWarnings("unchecked")
public String introspect() {
HashMap<String, Object> metrics = new HashMap<String, Object>();

// Make a quick copy of our runtime metrics data.
ArrayList<String> instrumentedTasks;
HashMap<String, LinkedList<Long>> executionTimes;
Expand All @@ -85,21 +85,21 @@ public String introspect() {
task.put("failures", taskFailures.get(taskName));
task.put("retries", taskRetries.get(taskName));
task.put("average_time", average(executionTimes.get(taskName)));

metrics.put("task_" + taskName, task);
}

metrics.put("tasks_instrumented", instrumentedTasks.size());
metrics.put("alive_since", mx.getUptime() / (new Long("1000")));

return JSONValue.toJSONString(metrics);
}


// Calculate and return the mean execution time of our sample.
private float average(LinkedList<Long> times) {
if (times == null) return 0;

long timeSum = 0;
for (long time : times) timeSum += time;

Expand Down
2 changes: 1 addition & 1 deletion src/com/urbanairship/octobot/MailQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static int remainingCapacity() {
// As this thread runs, it consumes messages from the internal queue and
// delivers each to the recipients configured in the YML file.
public void run() {

if (!validSettings()) {
logger.error("Email settings invalid; check your configuration.");
return;
Expand Down
8 changes: 4 additions & 4 deletions src/com/urbanairship/octobot/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Metrics {

// Keep track of all tasks we've seen executed.
protected static final ArrayList<String> instrumentedTasks = new ArrayList<String>();

// Keep track of average task throughput (last 10k runs per task).
protected static final HashMap<String, LinkedList<Long>> executionTimes =
new HashMap<String, LinkedList<Long>>();
Expand All @@ -20,7 +20,7 @@ public class Metrics {
// Keep track of total failures by task.
protected static final HashMap<String, Integer> taskFailures =
new HashMap<String, Integer>();

// Keep track of total retries by task.
protected static final HashMap<String, Integer> taskRetries =
new HashMap<String, Integer>();
Expand All @@ -34,7 +34,7 @@ public static void update(String task, long time,

synchronized(metricsLock) {
if (!instrumentedTasks.contains(task)) instrumentedTasks.add(task);

updateExecutionTimes(task, time);
updateTaskRetries(task, retries);
updateTaskResults(task, status);
Expand Down Expand Up @@ -67,7 +67,7 @@ private static void updateTaskRetries(String task, int retries) {
retriesForTask += retries;
taskRetries.put(task, retriesForTask);
}
}
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/com/urbanairship/octobot/Octobot.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void main(String[] args) {

logger.info("Launching Introspector...");
new Thread(new Introspector(), "Introspector").start();

logger.info("Launching Workers...");
List<HashMap<String, Object>> queues = null;
try {
Expand Down
8 changes: 4 additions & 4 deletions src/com/urbanairship/octobot/QueueConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void consumeFromBeanstalk() {
try { job = beanstalkClient.reserve(1); }
catch (BeanstalkException e) {
logger.error("Beanstalk connection error.", e);
beanstalkClient = Beanstalk.getBeanstalkChannel(queue.host,
beanstalkClient = Beanstalk.getBeanstalkChannel(queue.host,
queue.port, queue.queueName);
continue;
}
Expand All @@ -105,7 +105,7 @@ private void consumeFromBeanstalk() {
try { beanstalkClient.delete(job.getJobId()); }
catch (BeanstalkException e) {
logger.error("Error sending message receipt.", e);
beanstalkClient = Beanstalk.getBeanstalkChannel(queue.host,
beanstalkClient = Beanstalk.getBeanstalkChannel(queue.host,
queue.port, queue.queueName);
}
}
Expand Down Expand Up @@ -210,7 +210,7 @@ public boolean invokeTask(String rawMessage) {
errorMessage = "An error occurred while running the task.";
logger.error(errorMessage, e);
}

if (executedSuccessfully) break;
else retryCount++;
}
Expand All @@ -229,7 +229,7 @@ public boolean invokeTask(String rawMessage) {

long finishedAt = System.nanoTime();
Metrics.update(taskName, finishedAt - startedAt, executedSuccessfully, retryCount);

return executedSuccessfully;
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/urbanairship/octobot/TaskExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TaskExecutor {
new HashMap<String, Method>();

@SuppressWarnings("unchecked")
public static void execute(String taskName, JSONObject message)
public static void execute(String taskName, JSONObject message)
throws ClassNotFoundException,
NoSuchMethodException,
IllegalAccessException,
Expand Down