Permalink
Browse files

Merge pull request #40 from greyorange/master

Fix specs for OTP 19
  • Loading branch information...
RandomSeeded committed Apr 20, 2017
2 parents 9a3b5cc + 194110a commit 5c50aedfb33f9c3c08d98afe56d2b6ad2e2c811d
Showing with 45 additions and 44 deletions.
  1. +1 −0 .travis.yml
  2. +20 −20 src/ecrn_agent.erl
  3. +5 −5 src/ecrn_control.erl
  4. +2 −2 src/ecrn_cron_sup.erl
  5. +6 −6 src/ecrn_reg.erl
  6. +1 −1 src/ecrn_sup.erl
  7. +1 −1 src/ecrn_util.erl
  8. +9 −9 src/erlcron.erl
View
@@ -6,6 +6,7 @@ otp_release:
- 17.5
- 18.0
- 18.1
+ - 19.0
before_script: "make get-deps"
script: "make test"
View
@@ -45,30 +45,30 @@
%% @doc
%% Starts the server with the apropriate job and the appropriate ref
--spec start_link/2 ::(erlcron:job_ref(), erlcron:job()) ->
+-spec start_link(erlcron:job_ref(), erlcron:job()) ->
ignore | {error, Reason::term()} | {ok, pid()}.
start_link(JobRef, Job) ->
gen_server:start_link(?MODULE, [JobRef, Job], []).
--spec get_datetime/1 :: (pid()) -> calendar:datetime().
+-spec get_datetime(pid()) -> calendar:datetime().
get_datetime(Pid) ->
gen_server:call(Pid, get_datetime).
--spec cancel/1 :: (pid()) -> ok.
+-spec cancel(pid()) -> ok.
cancel(Pid) ->
gen_server:cast(Pid, shutdown).
--spec set_datetime/3 :: (pid(), calendar:datetime(), erlcron:seconds()) -> ok.
+-spec set_datetime(pid(), calendar:datetime(), erlcron:seconds()) -> ok.
set_datetime(Pid, DateTime, Actual) ->
gen_server:cast(Pid, {set_datetime, DateTime, Actual}).
--spec recalculate/1 :: (pid()) -> ok.
+-spec recalculate(pid()) -> ok.
recalculate(Pid) ->
gen_server:cast(Pid, recalculate).
%% @doc
%% Validate that a run_when spec specified is correct.
--spec validate/1 :: (erlcron:run_when()) -> valid | invalid.
+-spec validate(erlcron:run_when()) -> valid | invalid.
validate(Spec) ->
State = #state{job=undefined,
alarm_ref=undefined},
@@ -164,7 +164,7 @@ do_job_run(State, {_, {M, F, A}})
proc_lib:spawn(M, F, A).
%% @doc Returns the current time, in seconds past midnight.
--spec current_time/1 :: (state()) -> erlcron:seconds().
+-spec current_time(state()) -> erlcron:seconds().
current_time(State) ->
{_, {H,M,S}} = current_date(State),
S + M * 60 + H * 3600.
@@ -178,7 +178,7 @@ current_date(State) ->
%% @doc Calculates the duration in milliseconds until the next time
%% a job is to be run.
--spec until_next_milliseconds/2 :: (state(), erlcron:job()) ->
+-spec until_next_milliseconds(state(), erlcron:job()) ->
{ok, erlcron:seconds()} | {error, invalid_one_exception}.
until_next_milliseconds(State, Job) ->
try
@@ -200,7 +200,7 @@ normalize_seconds(State, Seconds) ->
%% @doc Calculates the duration in seconds until the next time
%% a job is to be run.
--spec until_next_time/2 :: (state(), {erlcron:run_when(), term()}) ->
+-spec until_next_time(state(), {erlcron:run_when(), term()}) ->
erlcron:seconds().
until_next_time(_State, {{once, Seconds}, _What}) when is_integer(Seconds) ->
Seconds;
@@ -244,7 +244,7 @@ until_next_time(State, {{monthly, DoM, Period}, _What}) ->
%% @doc Calculates the duration in seconds until the next time this
%% period is to occur during the day.
--spec until_next_daytime/2 :: (state(), erlcron:period()) -> erlcron:seconds().
+-spec until_next_daytime(state(), erlcron:period()) -> erlcron:seconds().
until_next_daytime(State, Period) ->
StartTime = first_time(Period),
EndTime = last_time(Period),
@@ -256,18 +256,18 @@ until_next_daytime(State, Period) ->
end.
%% @doc Calculates the last time in a given period.
--spec last_time/1 :: (erlcron:period()) -> erlcron:seconds().
+-spec last_time(erlcron:period()) -> erlcron:seconds().
last_time(Period) ->
hd(lists:reverse(lists:sort(resolve_period(Period)))).
%% @doc Calculates the first time in a given period.
--spec first_time/1 :: (erlcron:period()) -> erlcron:seconds().
+-spec first_time(erlcron:period()) -> erlcron:seconds().
first_time(Period) ->
hd(lists:sort(resolve_period(Period))).
%% @doc Calculates the first time in the given period after the given time.
--spec next_time/2 :: (erlcron:period(), erlcron:seconds()) -> erlcron:seconds().
+-spec next_time(erlcron:period(), erlcron:seconds()) -> erlcron:seconds().
next_time(Period, Time) ->
R = lists:sort(resolve_period(Period)),
lists:foldl(fun(X, A) ->
@@ -280,7 +280,7 @@ next_time(Period, Time) ->
end, 24*3600, R).
%% @doc Returns a list of times given a periodic specification.
--spec resolve_period/1 :: ([erlcron:period()] | erlcron:period()) -> [erlcron:seconds()].
+-spec resolve_period([erlcron:period()] | erlcron:period()) -> [erlcron:seconds()].
resolve_period([]) ->
[];
resolve_period([H | T]) ->
@@ -299,7 +299,7 @@ resolve_period0(Period, Time, EndTime, Acc) ->
resolve_period0(Period, Time + Period, EndTime, [Time | Acc]).
%% @doc Returns seconds past midnight for a given time.
--spec resolve_time/1 :: (erlcron:cron_time()) -> erlcron:seconds().
+-spec resolve_time(erlcron:cron_time()) -> erlcron:seconds().
resolve_time({H, M, S}) when H < 24, M < 60, S < 60 ->
S + M * 60 + H * 3600;
resolve_time({H, M, S, X}) when H < 24, M < 60, S < 60, is_atom(X) ->
@@ -316,7 +316,7 @@ resolve_time({H, pm}) when H < 12->
(H + 12) * 3600.
%% @doc Returns seconds for a given duration.
--spec resolve_dur/1 :: (erlcron:duration()) -> erlcron:seconds().
+-spec resolve_dur(erlcron:duration()) -> erlcron:seconds().
resolve_dur({Hour, hr}) ->
Hour * 3600;
resolve_dur({Min, min}) ->
@@ -326,7 +326,7 @@ resolve_dur({Sec, sec}) ->
%% @doc Returns the number of the given day of the week. See the calendar
%% module for day numbers.
--spec resolve_dow/1 :: (erlcron:dow()) -> integer().
+-spec resolve_dow(erlcron:dow()) -> integer().
resolve_dow(mon) ->
1;
resolve_dow(tue) ->
@@ -344,20 +344,20 @@ resolve_dow(sun) ->
%% @doc Calculates the duration in seconds until the given time occurs
%% tomorrow.
--spec until_tomorrow/2 :: (state(), erlcron:seconds()) -> erlcron:seconds().
+-spec until_tomorrow(state(), erlcron:seconds()) -> erlcron:seconds().
until_tomorrow(State, StartTime) ->
(StartTime + 24*3600) - current_time(State).
%% @doc Calculates the duration in seconds until the given period
%% occurs several days from now.
--spec until_days_from_now/3 :: (state(), erlcron:period(), integer()) ->
+-spec until_days_from_now(state(), erlcron:period(), integer()) ->
erlcron:seconds().
until_days_from_now(State, Period, Days) ->
Days * 24 * 3600 + until_next_daytime(State, Period).
%% @doc Calculates the duration in seconds until the given period
%% occurs, which may be today or several days from now.
--spec until_next_daytime_or_days_from_now/3 :: (state(), erlcron:period(), integer()) ->
+-spec until_next_daytime_or_days_from_now(state(), erlcron:period(), integer()) ->
erlcron:seconds().
until_next_daytime_or_days_from_now(State, Period, Days) ->
CurrentTime = current_time(State),
View
@@ -31,25 +31,25 @@
%%% API
%%%===================================================================
--spec start_link/0 :: () -> {ok, pid()} | ignore | {error, Error::term()}.
+-spec start_link() -> {ok, pid()} | ignore | {error, Error::term()}.
start_link() ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
--spec cancel/1 :: (erlcron:job_ref()) -> ok | undefined.
+-spec cancel(erlcron:job_ref()) -> ok | undefined.
cancel(AlarmRef) ->
gen_server:call(?SERVER, {cancel, AlarmRef}).
--spec datetime/0 :: () -> {calendar:datetime(), erlcron:seconds()}.
+-spec datetime() -> {calendar:datetime(), erlcron:seconds()}.
datetime() ->
gen_server:call(?SERVER, get_datetime).
%% @doc sets the date-time for the erlcron
--spec set_datetime/1 :: (calendar:datetime()) -> ok.
+-spec set_datetime(calendar:datetime()) -> ok.
set_datetime(DateTime={_,_}) ->
gen_server:call(?SERVER, {set_datetime, DateTime}, infinity).
%% @doc sets the date-time with the erlcron on all nodes
--spec multi_set_datetime/2 :: ([node()], calendar:datetime()) -> ok.
+-spec multi_set_datetime([node()], calendar:datetime()) -> ok.
multi_set_datetime(Nodes, DateTime={_,_}) ->
gen_server:multi_call(Nodes, ?SERVER, {set_datetime, DateTime}).
View
@@ -22,14 +22,14 @@
%%% API functions
%%%===================================================================
--spec start_link/0 :: () -> {ok, pid()} | ignore | {error, Error::term()}.
+-spec start_link() -> {ok, pid()} | ignore | {error, Error::term()}.
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
%% @doc
%% Add a chron job to be supervised
--spec add_job/2 :: (erlcron:job_ref(), erlcron:job()) -> erlcron:job_ref().
+-spec add_job(erlcron:job_ref(), erlcron:job()) -> erlcron:job_ref().
add_job(JobRef, Task) ->
{ok, _} = supervisor:start_child(?SERVER, [JobRef, Task]),
JobRef.
View
@@ -31,41 +31,41 @@
%%% API
%%%===================================================================
--spec start_link/0 :: () -> {ok, Pid::pid()} | ignore | {error, Error::term()}.
+-spec start_link() -> {ok, Pid::pid()} | ignore | {error, Error::term()}.
start_link() ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
%% @doc
%% Register an arbitrary value with the system, under a set of keys
--spec register/2 :: (term() | [term()], term()) -> ok | {discarded_keys, [term()]}.
+-spec register(term() | [term()], term()) -> ok | {discarded_keys, [term()]}.
register(Keys, Body) when is_list(Keys) ->
gen_server:call(?SERVER, {register, Keys, Body});
register(Key, Body) ->
gen_server:call(?SERVER, {register, [Key], Body}).
%% @doc
%% Remove the value registered under a que or set of keys
--spec unregister/1 :: (term() | [term()]) -> ok.
+-spec unregister(term() | [term()]) -> ok.
unregister(Keys) when is_list(Keys) ->
gen_server:call(?SERVER, {unregister, Keys});
unregister(Key) ->
gen_server:call(?SERVER, {unregister, [Key]}).
%% @doc
%% Get a value buy key.
--spec get/1 :: (term()) -> {ok, term()} | undefined.
+-spec get(term()) -> {ok, term()} | undefined.
get(Key) ->
gen_server:call(?SERVER, {get, Key}).
%% @doc
%% Get all the values.
--spec get_all/0 :: () -> [{term(), term()}].
+-spec get_all() -> [{term(), term()}].
get_all() ->
gen_server:call(?SERVER, get_all).
%% @doc
%% stop this server
--spec stop/0 :: () -> ok.
+-spec stop() -> ok.
stop() ->
gen_server:call(?SERVER, stop).
View
@@ -18,7 +18,7 @@
%%% API functions
%%%===================================================================
--spec start_link/0 :: () -> {ok, Pid::term()} | ignore | {error, Error::term()}.
+-spec start_link() -> {ok, Pid::term()} | ignore | {error, Error::term()}.
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
View
@@ -12,7 +12,7 @@
%%%===================================================================
%%% API
%%%===================================================================
--spec epoch_seconds/0 :: () -> erlcron:seconds().
+-spec epoch_seconds() -> erlcron:seconds().
epoch_seconds() ->
{Megasecs, Secs, Microsecs} = os:timestamp(),
erlang:trunc((Megasecs * 1000000) + Secs + (Microsecs / 1000000)).
View
@@ -60,7 +60,7 @@
%% @doc
%% Check that the spec specified is valid or invalid
--spec validate/1 :: (run_when()) -> valid | invalid.
+-spec validate(run_when()) -> valid | invalid.
validate(Spec) ->
ecrn_agent:validate(Spec).
@@ -69,52 +69,52 @@ validate(Spec) ->
%% spec. It returns the JobRef that can be used to manipulate the job
%% after it is created.
--spec cron/1 :: (job()) -> job_ref().
+-spec cron(job()) -> job_ref().
cron(Job) ->
JobRef = make_ref(),
ecrn_cron_sup:add_job(JobRef, Job).
%% @doc
%% Convienience method to specify a job run to run on a daily basis
%% at a specific time.
--spec at/2 :: (cron_time() | seconds(), function()) -> job_ref().
+-spec at(cron_time() | seconds(), function()) -> job_ref().
at(When, Fun) ->
Job = {{daily, When}, Fun},
cron(Job).
%% @doc
%% Run the specified job once after the amount of time specifed.
--spec once/2 :: (cron_time() | seconds(), function()) -> job_ref().
+-spec once(cron_time() | seconds(), function()) -> job_ref().
once(When, Fun) ->
Job = {{once, When}, Fun},
cron(Job).
%% @doc
%% Cancel the job specified by the jobref.
--spec cancel/1 :: (job_ref()) -> ok | undefined.
+-spec cancel(job_ref()) -> ok | undefined.
cancel(JobRef) ->
ecrn_control:cancel(JobRef).
%% @doc
%% Get the current date time of the running erlcron system.
--spec datetime/0 :: () -> {calendar:datetime(), seconds()}.
+-spec datetime() -> {calendar:datetime(), seconds()}.
datetime() ->
ecrn_control:datetime().
%% @doc
%% Set the current date time of the running erlcron system.
--spec set_datetime/1 :: (calendar:datetime()) -> ok.
+-spec set_datetime(calendar:datetime()) -> ok.
set_datetime(DateTime) ->
ecrn_control:set_datetime(DateTime).
%% @doc
%% Set the current date time of the erlcron system running on different nodes.
--spec multi_set_datetime/1 :: (calendar:datetime()) -> ok.
+-spec multi_set_datetime(calendar:datetime()) -> ok.
multi_set_datetime(DateTime) ->
ecrn_control:multi_set_datetime([node()|nodes()], DateTime).
%% @doc
%% Set the current date time of the erlcron system running on the
%% specified nodes
--spec multi_set_datetime/2 :: ([node()], calendar:datetime()) -> ok.
+-spec multi_set_datetime([node()], calendar:datetime()) -> ok.
multi_set_datetime(Nodes, DateTime) when is_list(Nodes) ->
ecrn_control:multi_set_datetime(Nodes, DateTime).

0 comments on commit 5c50aed

Please sign in to comment.