diff --git a/lib/cronex/every.ex b/lib/cronex/every.ex index db0c23a..6e88446 100644 --- a/lib/cronex/every.ex +++ b/lib/cronex/every.ex @@ -1,4 +1,5 @@ defmodule Cronex.Every do + require IEx @moduledoc """ This module defines scheduling macros. """ @@ -94,6 +95,26 @@ defmodule Cronex.Every do end end + defmacro every(arg1, [at: time] = arg2, [do: block] = job) + when is_list(arg1) and is_bitstring(time) do + Enum.map arg1, fn item -> + job_name = String.to_atom("job_every_#{item}_at_#{time}") + quote do + @jobs unquote(job_name) + + @doc false + def unquote(job_name)() do + Cronex.Job.new( + unquote(item), + unquote(time), + fn -> unquote(block) end + ) + |> Cronex.Job.validate! + end + end + end + end + defmacro every(arg1, arg2, [do: block] = _job) when is_integer(arg1) and is_atom(arg2) do job_name = String.to_atom("job_every_#{arg1}_#{arg2}") diff --git a/lib/cronex/table.ex b/lib/cronex/table.ex index 7bf3270..a913a81 100644 --- a/lib/cronex/table.ex +++ b/lib/cronex/table.ex @@ -130,6 +130,6 @@ defmodule Cronex.Table do end defp ping_interval do - Application.get_env(:cronex, :ping_interval, 30000) + Application.get_env(:cronex, :ping_interval, 60000) end end diff --git a/mix.exs b/mix.exs index 6efae13..6c3c9f3 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule Cronex.Mixfile do [app: :cronex, version: "0.4.0", - elixir: "~> 1.5.2", + elixir: "~> 1.6", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod,