Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit be118e26b866fd3688f86d3b7ed274a2c6872f26 1 parent 1b3f8e0
Jesper Louis Andersen authored

Showing 1 changed file with 11 additions and 7 deletions. Show diff stats Hide diff stats

  1. +11 7 src/jobs_queue.erl
18 src/jobs_queue.erl
@@ -183,7 +183,11 @@ timedout(#queue{max_time = TO} = Q) ->
183 183 timedout(_ , #queue{oldest_job = undefined}) -> [];
184 184 timedout(TO, #queue{st = #st{table = Tab}} = Q) ->
185 185 Now = timestamp(),
186   - {Objs, OJ} = find_expired(Tab, Now, TO),
  186 + Objs = find_expired(Tab, Now, TO),
  187 + OJ = case ets:first(Tab) of
  188 + '$end_of_table' -> undefined;
  189 + {TS, _} -> TS
  190 + end,
187 191 {Objs, Q#queue{oldest_job = OJ}}.
188 192
189 193
@@ -232,18 +236,18 @@ set_oldest_job(#queue{st = #st{table = Tab}} = Q) ->
232 236
233 237
234 238 find_expired(Tab, Now, TO) ->
235   - find_expired(ets:first(Tab), Tab, Now, TO, [], undefined).
  239 + find_expired(ets:first(Tab), Tab, Now, TO, []).
236 240
237 241 %% we return the reversed list, but I don't think that matters here.
238   -find_expired('$end_of_table', _, _, _, Acc, OJ) ->
239   - {Acc, OJ};
240   -find_expired({TS, _} = Key, Tab, Now, TO, Acc, _OJ) ->
  242 +find_expired('$end_of_table', _, _, _, Acc) ->
  243 + Acc;
  244 +find_expired({TS, _} = Key, Tab, Now, TO, Acc) ->
241 245 case is_expired(TS, Now, TO) of
242 246 true ->
243 247 ets:delete(Tab, Key),
244   - find_expired(ets:first(Tab), Tab, Now, TO, [Key|Acc], TS);
  248 + find_expired(ets:first(Tab), Tab, Now, TO, [Key|Acc]);
245 249 false ->
246   - {Acc, TS}
  250 + Acc
247 251 end.
248 252
249 253 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.