Packages

**The wrapper for `erlcron` to be used in Elixir projects.** Original erlang library: https://github.com/erlware/erlcron

Current section

Files

Jump to
johanna src ecrn_cron_sup.erl
Raw

src/ecrn_cron_sup.erl

%%% @copyright Erlware, LLC. All Rights Reserved.
%%%
%%% This file is provided to you under the BSD License; you may not use
%%% this file except in compliance with the License.
%%%-------------------------------------------------------------------
%%% @doc
%%% Simple one for one supervisor for ecd_chron jobs.
-module(ecrn_cron_sup).
-behaviour(supervisor).
%% API
-export([start_link/0,
add_job/2]).
%% Supervisor callbacks
-export([init/1]).
-define(SERVER, ?MODULE).
%%%===================================================================
%%% 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(JobRef,Task) -> Result when
JobRef :: erlcron:job_ref(),
Task :: erlcron:job(),
Result :: erlcron:job_ref().
add_job(JobRef, Task) ->
{ok, _} = supervisor:start_child(?SERVER, [JobRef, Task]),
JobRef.
%%%===================================================================
%%% Supervisor callbacks
%%%===================================================================
%% @private
init([]) ->
RestartStrategy = simple_one_for_one,
MaxRestarts = 1000,
MaxSecondsBetweenRestarts = 3600,
SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},
Restart = transient,
Shutdown = 2000,
Type = worker,
AChild = {ecrn_agent, {ecrn_agent, start_link, []},
Restart, Shutdown, Type, [ecrn_agent]},
{ok, {SupFlags, [AChild]}}.