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.
defmodule PluralsightTweet.Scheduler do
def schedule_file(file) do
every :minute do
== Compilation error in file lib/pluralsight_tweet/scheduler.ex ==
** (ArgumentError) cannot set attribute @doc inside function/macro
Could anyone point out what I’m doing wrong?
Hi, welcome to the forum,
You are not using the right syntax… see the example in the documentation.
defmodule MyApp.Scheduler do
every :hour do
IO.puts "Every hour job"
every :day, at: "10:00" do
IO.puts "Every day job at 10:00"
As You can see, it is not wrapped inside def block…
I get the same error if I use your syntax.
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.