Skip to content
Browse files

Fix calculation of the oldest job.

The oldest job is *always* the first element in the queue if present.
So just look it up rather than trying to be smart here.
  • Loading branch information...
1 parent 1b3f8e0 commit be118e26b866fd3688f86d3b7ed274a2c6872f26 @jlouis committed Mar 12, 2012
Showing with 11 additions and 7 deletions.
  1. +11 −7 src/jobs_queue.erl
View
18 src/jobs_queue.erl
@@ -183,7 +183,11 @@ timedout(#queue{max_time = TO} = Q) ->
timedout(_ , #queue{oldest_job = undefined}) -> [];
timedout(TO, #queue{st = #st{table = Tab}} = Q) ->
Now = timestamp(),
- {Objs, OJ} = find_expired(Tab, Now, TO),
+ Objs = find_expired(Tab, Now, TO),
+ OJ = case ets:first(Tab) of
+ '$end_of_table' -> undefined;
+ {TS, _} -> TS
+ end,
{Objs, Q#queue{oldest_job = OJ}}.
@@ -232,18 +236,18 @@ set_oldest_job(#queue{st = #st{table = Tab}} = Q) ->
find_expired(Tab, Now, TO) ->
- find_expired(ets:first(Tab), Tab, Now, TO, [], undefined).
+ find_expired(ets:first(Tab), Tab, Now, TO, []).
%% we return the reversed list, but I don't think that matters here.
-find_expired('$end_of_table', _, _, _, Acc, OJ) ->
- {Acc, OJ};
-find_expired({TS, _} = Key, Tab, Now, TO, Acc, _OJ) ->
+find_expired('$end_of_table', _, _, _, Acc) ->
+ Acc;
+find_expired({TS, _} = Key, Tab, Now, TO, Acc) ->
case is_expired(TS, Now, TO) of
true ->
ets:delete(Tab, Key),
- find_expired(ets:first(Tab), Tab, Now, TO, [Key|Acc], TS);
+ find_expired(ets:first(Tab), Tab, Now, TO, [Key|Acc]);
false ->
- {Acc, TS}
+ Acc
end.
empty(#queue{st = #st{table = T}} = Q) ->

0 comments on commit be118e2

Please sign in to comment.
Something went wrong with that request. Please try again.