Skip to content

Instantly share code, notes, and snippets.

@michaelowens
Created May 15, 2015 15:23
Show Gist options
  • Save michaelowens/c6328df17d3131a294a2 to your computer and use it in GitHub Desktop.
Save michaelowens/c6328df17d3131a294a2 to your computer and use it in GitHub Desktop.
defmodule Plugin do
alias Plugin
use XikBot.Database
def everyX(name, ms, cb) do
IO.puts "--- everyX ---"
Amnesia.transaction do
selection = Timer.where cmd == name
IO.puts selection
if selection == nil do
t = %Timer{cmd: name, interval: 0, last_run: 0}
|> Timer.write
cb.()
Stream.timer(ms) |> Enum.take(1) |> deleteTimer(name, t)
end
end
end
def deleteTimer(s, name, t) do
IO.puts "Deleting timer: " <> name
Amnesia.transaction do
resp = Timer.delete!(t)
IO.puts resp
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment