uwiger / jobs

Job scheduler for load regulation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect spec for jobs_server:add_queue

jwheare opened this issue · comments

Trying to add a queue with jobs:add_queue(Name, [{regulators, ...}]) throws a warning in dialyzer:

The call jobs:add_queue(Name, Props::[{'regulators',[any(),...]},...]) will never return since it differs in the 2nd argument from the success typing arguments: (any(), [{'config',atom() | [atom() | [any()] | char()]} | {'counters',[{_,_}]} | {'group_rates',[{_,_}]} | {'interval',integer()} | {'queues',[{_,_} | {_,_,_}]}])

The jobs_server:add_queue spec is defined here:

-spec add_queue(queue_name(), [option()]) -> ok.

And the option() type doesn't allow regulators as a top level option:

jobs/include/jobs.hrl

Lines 32 to 45 in a04e8d4

-type option() :: {queues, [q_spec()]}
| {config, file:name()}
| {group_rates, [{q_name(), [option()]}]}
| {counters, [{q_name(), [option()]}]}
| {interval, integer()}
| {max_time, integer() | undefined}
| {max_size, integer() | undefined}.
-type timestamp() :: integer(). % microseconds with a special epoch
-type q_name() :: any().
-type q_std_type() :: standard_rate | standard_counter.
-type q_opts() :: [{atom(), any()}].
-type q_spec() :: {q_name(), q_std_type(), q_opts()}
| {q_name(), q_opts()}.

From @uwiger on Slack:

the type spec for add_queue() is wrong. From a quick look at the code, I think it should be -spec add_queue(queue_name(), q_opts()) -> ok.
… and q_opts() could well be improved to be more precise.