Skip to content

Commit

Permalink
Merge pull request #77 from drteeth/show-retry-details
Browse files Browse the repository at this point in the history
Add visibility into failed jobs
  • Loading branch information
akira authored Nov 4, 2019
2 parents fbd2a00 + f911f47 commit d5553a0
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 9 deletions.
25 changes: 25 additions & 0 deletions priv/ember/app/controllers/retries/show.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Ember from "ember";
var ShowController;

ShowController = Ember.Controller.extend({
actions: {
removeRetry: function(retry) {
var self;
self = this;
retry.deleteRecord();
return retry.save().then(function(_f) {
return self.send('reloadStats');
});
},
requeueRetry: function(retry) {
var self;
self = this;
return retry.save().then(function(_f) {
self.send('reloadStats');
return self.store.unloadRecord(retry);
});
}
}
});

export default ShowController;
9 changes: 7 additions & 2 deletions priv/ember/app/models/retry.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import DS from 'ember-data';
import Ember from 'ember';

var Retry = DS.Model.extend({
queue: DS.attr('string'),
"class": DS.attr('string'),
args: DS.attr('string'),
args: DS.attr(),
failed_at: DS.attr('date'),
error_message: DS.attr('string'),
retry: DS.attr('boolean'),
retry_count: DS.attr('number')
retry_count: DS.attr('number'),

prettyArgs: Ember.computed('args', function(){
return JSON.stringify(this.get('args'), null, 2);
})
});

export default Retry;
1 change: 1 addition & 0 deletions priv/ember/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Router.map(function() {

this.route('retries', {resetNamespace: true }, function() {
this.route('index', {path: '/'});
this.route('show', {path: '/:id'});
});

this.route('failures', {resetNamespace: true }, function() {
Expand Down
10 changes: 10 additions & 0 deletions priv/ember/app/routes/retries/show.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var ShowRoute;
import Ember from "ember";

ShowRoute = Ember.Route.extend({
model: function(params) {
return this.store.findRecord('retry', params.id);
}
});

export default ShowRoute;
6 changes: 4 additions & 2 deletions priv/ember/app/templates/retries/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
<tbody>
{{#each model as |retry|}}
<tr>
<td>{{retry.queue}}</td>
<td>
{{#link-to 'retries.show' retry.id}}{{retry.queue}}{{/link-to}}
</td>
<td>{{retry.class}}</td>
<td>{{retry.args}}</td>
<td>{{retry.prettyArgs}}</td>
<td>{{retry.failed_at}}</td>
<td>{{retry.retry_count}}</td>
<td><button {{action 'removeRetry' retry on="click"}} class="btn btn-danger btn-xs">Delete</button><button {{action 'requeueRetry' retry on="click"}} class="btn btn-secondary btn-xs">Retry</button></td>
Expand Down
28 changes: 28 additions & 0 deletions priv/ember/app/templates/retries/show.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<h1>{{model.class}}</h1>
<dl>
<dt>Queue</dt>
<dd>{{model.queue}}</dd>
</dl>

<dl>
<dt>Failed at</dt>
<dd>{{model.failed_at}}</dd>
</dl>

<dl>
<dt>Retry count</dt>
<dd>{{model.retry_count}}</dd>
</dl>

<dl>
<dt>Error</dt>
<dd><pre>{{model.error_message}}</pre></dd>
</dl>

<dl>
<dt>Arguments</dt>
<dd><pre>{{model.prettyArgs}}</pre></dd>
</dl>

<button {{action 'removeRetry' model on="click"}} class="btn btn-danger btn-xs">Delete</button>
<button {{action 'requeueRetry' model on="click"}} class="btn btn-secondary btn-xs">Retry</button>
2 changes: 1 addition & 1 deletion priv/ember/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">


<meta name="exqui/config/environment" content="%7B%22modulePrefix%22%3A%22exqui%22%2C%22environment%22%3A%22development%22%2C%22rootURL%22%3A%22/%22%2C%22locationType%22%3A%22auto%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%7D%7D%2C%22APP%22%3A%7B%22name%22%3A%22exqui%22%2C%22version%22%3A%22v0.9.0%22%7D%2C%22exportApplicationGlobal%22%3Atrue%7D" />
<meta name="exqui/config/environment" content="%7B%22modulePrefix%22%3A%22exqui%22%2C%22environment%22%3A%22development%22%2C%22rootURL%22%3A%22/%22%2C%22locationType%22%3A%22auto%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%7D%7D%2C%22APP%22%3A%7B%22name%22%3A%22exqui%22%2C%22version%22%3A%220.0.0+630ab6d9%22%7D%2C%22exportApplicationGlobal%22%3Atrue%7D" />

<base href="/<%= assigns[:base] %>" />

Expand Down
10 changes: 10 additions & 0 deletions test/ui_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ defmodule Exq.ApiTest do
assert json |> Map.get("retries") |> hd |> Map.get("jid") == "1234"
end

test "serves a retry" do
state = :sys.get_state(Exq.Api)
JobQueue.retry_job(state.redis, state.namespace, %Job{jid: "1234"}, 1, "this is an error")
conn = conn(:get, "/api/retries/1234") |> call
assert conn.status == 200

json = Config.serializer.decode!(conn.resp_body)
assert json |> Map.get("retry") |> Map.get("jid") == "1234"
end

test "serves the queue" do
conn = conn(:get, "/api/queues/default") |> call
assert conn.status == 200
Expand Down
20 changes: 16 additions & 4 deletions web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ defmodule ExqUi.RouterPlug do
conn |> send_resp(200, json) |> halt
end

get "/api/retries/:id" do
{:ok, retry} = Exq.Api.find_retry(conn.assigns[:exq_name], id)
retry = retry |> map_jid_to_id |> convert_results_to_times(:failed_at)
{:ok, json} = Poison.encode(%{retry: retry})

conn |> send_resp(200, json) |> halt
end

get "/api/failures" do
{:ok, failures} = Exq.Api.failed(conn.assigns[:exq_name])
failures = failures |> map_jid_to_id |> convert_results_to_times(:failed_at)
Expand Down Expand Up @@ -199,17 +207,21 @@ defmodule ExqUi.RouterPlug do
|> halt
end

def map_jid_to_id(jobs) do
def map_jid_to_id(jobs) when is_list(jobs) do
for job <- jobs do
Map.put(job, :id, job.jid)
map_jid_to_id(job)
end
end
def map_jid_to_id(job), do: Map.put(job, :id, job.jid)

def convert_results_to_times(jobs, score_key) do
def convert_results_to_times(jobs, score_key) when is_list(jobs) do
for job <- jobs do
Map.put(job, score_key, score_to_time(Map.get(job, score_key)))
convert_results_to_times(job, score_key)
end
end
def convert_results_to_times(job, score_key) do
Map.put(job, score_key, score_to_time(Map.get(job, score_key)))
end

def score_to_time(score) when is_float(score) do
round(score * 1_000_000)
Expand Down

0 comments on commit d5553a0

Please sign in to comment.