Created
May 15, 2015 14:26
-
-
Save michaelowens/a478a89455271ada37a4 to your computer and use it in GitHub Desktop.
Amnesia transactions not running
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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