First time posting - I’m following along with Pluralsight’s Elixir intro tutorial that’s having me build some type of cron scheduler.
In the tutorial they’re using quantom to schedule cron jobs but I decided to use Cronex. I followed the Cronex docs but I can’t get the file to compile.
scheduler.ex
defmodule PluralsightTweet.Scheduler do
use Cronex.Scheduler
def schedule_file(file) do
every :minute do
PluralsightTweet.FileReader.get_string_to_tweet(file)
end
end
end
error:
== Compilation error in file lib/pluralsight_tweet/scheduler.ex ==
** (ArgumentError) cannot set attribute @doc inside function/macro
You are not using the right syntax… see the example in the documentation.
defmodule MyApp.Scheduler do
use Cronex.Scheduler
every :hour do
IO.puts "Every hour job"
end
every :day, at: "10:00" do
IO.puts "Every day job at 10:00"
end
end
As You can see, it is not wrapped inside def block…
Thanks for the reply, I noticed the difference in syntax as well.
However, what I wanted to do was wrap the every in another function so that I could call it from another module (or from iex like so >> PluralsightTweet.Scheduler.schedule_file("/my/path/to/file.txt") )
In this case the wrapping function would be “schedule_file”. Is something like that possible?
I have not seen any clear way to pass parameters to every, but I guess the block it executes could simply work with parameterized jobs, within a queue, and other modules could push any job to the queue, with customized params.
BTW cron is also working like this… at a given time, it will trigger a script, and there is no way to pass a parameter to it.