Skip to content

Commit

Permalink
Merge pull request #10 from zhongwencool/fixed-dialyzer
Browse files Browse the repository at this point in the history
Fixed dialyzer
  • Loading branch information
zhongwencool authored Jan 14, 2020
2 parents 01f6918 + 4ae313b commit 6e8cdfa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ otp_release:
- 21.0
script:
- ./rebar3 as test get-deps
- ./rebar3 xref
- epmd -daemon
- ./rebar3 as test proper -c
- ./rebar3 as test ct -c
- ./rebar3 as test cover
- ./rebar3 as test coveralls send
- ./rebar3 as test coveralls send
7 changes: 7 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@
{cover_export_enabled , true}.
{coveralls_coverdata , "_build/test/cover/*.coverdata"}. % or a string with wildcards or a list of files
{coveralls_service_name , "travis-ci"}.


{xref_warnings,true}.
{xref_extra_paths,[]}.
{xref_checks,[undefined_function_calls,undefined_functions,locals_not_used,
deprecated_function_calls,
deprecated_functions]}.
2 changes: 1 addition & 1 deletion src/ecron.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, ecron,
[{description, "cron-like/crontab job scheduling library"},
{vsn, "0.5.2"},
{vsn, "0.5.3"},
{registered, [ecron_sup, ecron, ecron_monitor]},
{mod, {ecron_app, []}},
{applications, [kernel, stdlib, telemetry]},
Expand Down
28 changes: 15 additions & 13 deletions src/ecron.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ month => '*' | [1..12 | {1..11, 2..12}, ...],
day_of_month => '*' | [1..31 | {1..30, 2..31}, ...],
day_of_week => '*' | [0..6 | {0..5, 1..6}, ...]}.

-type mfargs() :: {M :: module(), F :: atom(), A :: [term()]}.
-type ecron() :: #{name => name(),
crontab => crontab(),
start_time => calendar:rfc3339_string() | unlimited,
end_time => calendar:rfc3339_string() | unlimited,
mfa => mfa(),
mfa => mfargs(),
type => cron | every}.

-type status() :: deactivate | activate.
Expand All @@ -49,31 +50,31 @@ next => [calendar:datetime()]}.
-type options() :: [option()].

%% @equiv add(JobName, Spec, MFA, unlimited, unlimited, [])
-spec add(name(), crontab_spec(), mfa()) ->
-spec add(name(), crontab_spec(), mfargs()) ->
{ok, name()} | {error, parse_error(), term()} | {error, already_exist}.
add(JobName, Spec, MFA) ->
add(JobName, Spec, MFA, unlimited, unlimited, []).

%% @equiv add_with_count(make_ref(), Spec, MFA, RunCount)
-spec add_with_count(crontab_spec(), mfa(), pos_integer()) ->
-spec add_with_count(crontab_spec(), mfargs(), pos_integer()) ->
{ok, name()} | {error, parse_error(), term()}.
add_with_count(Spec, MFA, RunCount) when is_integer(RunCount) ->
add_with_count(make_ref(), Spec, MFA, RunCount).

%% @equiv add(make_ref(), Spec, MFA, unlimited, unlimited, [{max_count, RunCount}])
-spec add_with_count(name(), crontab_spec(), mfa(), pos_integer()) ->
-spec add_with_count(name(), crontab_spec(), mfargs(), pos_integer()) ->
{ok, name()} | {error, parse_error(), term()}.
add_with_count(JobName, Spec, MFA, RunCount) when is_integer(RunCount) ->
add(JobName, Spec, MFA, unlimited, unlimited, [{max_count, RunCount}]).

%% @equiv add(make_ref(), Spec, MFA, Start, End, [])
-spec add_with_datetime(crontab_spec(), mfa(), start_datetime(), end_datetime()) ->
-spec add_with_datetime(crontab_spec(), mfargs(), start_datetime(), end_datetime()) ->
{ok, name()} | {error, parse_error(), term()}.
add_with_datetime(Spec, MFA, Start, End) ->
add(make_ref(), Spec, MFA, Start, End, []).

%% @equiv add(JobName, Spec, MFA, Start, End, [])
-spec add_with_datetime(name(), crontab_spec(), mfa(), start_datetime(), end_datetime()) ->
-spec add_with_datetime(name(), crontab_spec(), mfargs(), start_datetime(), end_datetime()) ->
{ok, name()} | {error, parse_error(), term()} | {error, already_exist}.
add_with_datetime(JobName, Spec, MFA, Start, End) ->
add(JobName, Spec, MFA, Start, End, []).
Expand All @@ -91,7 +92,7 @@ add_with_datetime(JobName, Spec, MFA, Start, End) ->
%% </li>
%% </ul>
%%
-spec add(name(), crontab_spec(), mfa(), start_datetime(), end_datetime(), options()) ->
-spec add(name(), crontab_spec(), mfargs(), start_datetime(), end_datetime(), options()) ->
{ok, name()} | {error, parse_error(), term()} | {error, already_exist}.
add(JobName, Spec, MFA, Start, End, Option) ->
case valid_datetime(Start, End) of
Expand Down Expand Up @@ -203,17 +204,18 @@ reload() ->
-spec parse_spec(crontab_spec(), pos_integer()) ->
{ok, #{type => cron | every, crontab => crontab_spec(), next => [calendar:rfc3339_string()]}} |
{error, atom(), term()}.
parse_spec({ok, Type, JobSpec}, Num) ->
Job = #{type => Type, crontab => JobSpec},
Next = ecron_tick:predict_datetime(Job, Num),
{ok, Job#{next => Next}};
parse_spec({error, _Field, _Value} = Error, _Num) -> Error;
parse_spec(Spec, Num) when is_integer(Num) andalso Num > 0 ->
parse_spec(parse_spec(Spec), Num).
parse_spec_2(parse_spec(Spec), Num).

%%%===================================================================
%%% Internal functions
%%%===================================================================
parse_spec_2({ok, Type, JobSpec}, Num) ->
Job = #{type => Type, crontab => JobSpec},
Next = ecron_tick:predict_datetime(Job, Num),
{ok, Job#{next => Next}};
parse_spec_2({error, _Field, _Value} = Error, _Num) -> Error.

%% @private
valid_datetime(Start, End) ->
case valid_datetime(Start) andalso valid_datetime(End) of
Expand Down

0 comments on commit 6e8cdfa

Please sign in to comment.