Skip to content

Instantly share code, notes, and snippets.

@michaelowens
Created May 15, 2015 14:26
Show Gist options
  • Save michaelowens/a478a89455271ada37a4 to your computer and use it in GitHub Desktop.
Save michaelowens/a478a89455271ada37a4 to your computer and use it in GitHub Desktop.
Amnesia transactions not running
use Amnesia
defdatabase XikBot.Database do
deftable Timer, [{ :id, autoincrement }, :cmd, :interval, :last_run], type: :bag do
@type t :: %Timer{id: non_neg_integer, cmd: String.t, interval: integer, last_run: integer}
end
end
defmodule Plugin do
alias Plugin
use XikBot.Database
def everyX(name, ms, cb) do
IO.puts "--- everyX ---"
Amnesia.transaction do
IO.puts "try to get data"
selection = Timer.where cmd == name
IO.puts "Got timer data:"
IO.puts IO.inspect selection
if !selection do
t = %Timer{cmd: name, interval: 0, last_run: 0}
|> Timer.write
cb.()
Stream.interval(ms) |> t.delete
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment