@@ -23,11 +23,12 @@ month => '*' | [1..12 | {1..11, 2..12}, ...],
2323day_of_month => '*' | [1 ..31 | {1 ..30 , 2 ..31 }, ...],
2424day_of_week => '*' | [0 ..6 | {0 ..5 , 1 ..6 }, ...]}.
2525
26+ -type mfargs () :: {M :: module (), F :: atom (), A :: [term ()]}.
2627-type ecron () :: #{name => name (),
2728crontab => crontab (),
2829start_time => calendar :rfc3339_string () | unlimited ,
2930end_time => calendar :rfc3339_string () | unlimited ,
30- mfa => mfa (),
31+ mfa => mfargs (),
3132type => cron | every }.
3233
3334-type status () :: deactivate | activate .
@@ -49,31 +50,31 @@ next => [calendar:datetime()]}.
4950-type options () :: [option ()].
5051
5152% % @equiv add(JobName, Spec, MFA, unlimited, unlimited, [])
52- -spec add (name (), crontab_spec (), mfa ()) ->
53+ -spec add (name (), crontab_spec (), mfargs ()) ->
5354 {ok , name ()} | {error , parse_error (), term ()} | {error , already_exist }.
5455add (JobName , Spec , MFA ) ->
5556 add (JobName , Spec , MFA , unlimited , unlimited , []).
5657
5758% % @equiv add_with_count(make_ref(), Spec, MFA, RunCount)
58- -spec add_with_count (crontab_spec (), mfa (), pos_integer ()) ->
59+ -spec add_with_count (crontab_spec (), mfargs (), pos_integer ()) ->
5960 {ok , name ()} | {error , parse_error (), term ()}.
6061add_with_count (Spec , MFA , RunCount ) when is_integer (RunCount ) ->
6162 add_with_count (make_ref (), Spec , MFA , RunCount ).
6263
6364% % @equiv add(make_ref(), Spec, MFA, unlimited, unlimited, [{max_count, RunCount}])
64- -spec add_with_count (name (), crontab_spec (), mfa (), pos_integer ()) ->
65+ -spec add_with_count (name (), crontab_spec (), mfargs (), pos_integer ()) ->
6566 {ok , name ()} | {error , parse_error (), term ()}.
6667add_with_count (JobName , Spec , MFA , RunCount ) when is_integer (RunCount ) ->
6768 add (JobName , Spec , MFA , unlimited , unlimited , [{max_count , RunCount }]).
6869
6970% % @equiv add(make_ref(), Spec, MFA, Start, End, [])
70- -spec add_with_datetime (crontab_spec (), mfa (), start_datetime (), end_datetime ()) ->
71+ -spec add_with_datetime (crontab_spec (), mfargs (), start_datetime (), end_datetime ()) ->
7172 {ok , name ()} | {error , parse_error (), term ()}.
7273add_with_datetime (Spec , MFA , Start , End ) ->
7374 add (make_ref (), Spec , MFA , Start , End , []).
7475
7576% % @equiv add(JobName, Spec, MFA, Start, End, [])
76- -spec add_with_datetime (name (), crontab_spec (), mfa (), start_datetime (), end_datetime ()) ->
77+ -spec add_with_datetime (name (), crontab_spec (), mfargs (), start_datetime (), end_datetime ()) ->
7778 {ok , name ()} | {error , parse_error (), term ()} | {error , already_exist }.
7879add_with_datetime (JobName , Spec , MFA , Start , End ) ->
7980 add (JobName , Spec , MFA , Start , End , []).
@@ -91,7 +92,7 @@ add_with_datetime(JobName, Spec, MFA, Start, End) ->
9192% % </li>
9293% % </ul>
9394% %
94- -spec add (name (), crontab_spec (), mfa (), start_datetime (), end_datetime (), options ()) ->
95+ -spec add (name (), crontab_spec (), mfargs (), start_datetime (), end_datetime (), options ()) ->
9596 {ok , name ()} | {error , parse_error (), term ()} | {error , already_exist }.
9697add (JobName , Spec , MFA , Start , End , Option ) ->
9798 case valid_datetime (Start , End ) of
@@ -203,17 +204,18 @@ reload() ->
203204-spec parse_spec (crontab_spec (), pos_integer ()) ->
204205 {ok , #{type => cron | every , crontab => crontab_spec (), next => [calendar :rfc3339_string ()]}} |
205206 {error , atom (), term ()}.
206- parse_spec ({ok , Type , JobSpec }, Num ) ->
207- Job = #{type => Type , crontab => JobSpec },
208- Next = ecron_tick :predict_datetime (Job , Num ),
209- {ok , Job #{next => Next }};
210- parse_spec ({error , _Field , _Value } = Error , _Num ) -> Error ;
211207parse_spec (Spec , Num ) when is_integer (Num ) andalso Num > 0 ->
212- parse_spec (parse_spec (Spec ), Num ).
208+ parse_spec_2 (parse_spec (Spec ), Num ).
213209
214210% %%===================================================================
215211% %% Internal functions
216212% %%===================================================================
213+ parse_spec_2 ({ok , Type , JobSpec }, Num ) ->
214+ Job = #{type => Type , crontab => JobSpec },
215+ Next = ecron_tick :predict_datetime (Job , Num ),
216+ {ok , Job #{next => Next }};
217+ parse_spec_2 ({error , _Field , _Value } = Error , _Num ) -> Error .
218+
217219% % @private
218220valid_datetime (Start , End ) ->
219221 case valid_datetime (Start ) andalso valid_datetime (End ) of
0 commit comments