Load plans to db

Stephen Paul Weber created

Change summary

sgx_jmp.rb | 11 +++++++++++
1 file changed, 11 insertions(+)

Detailed changes

sgx_jmp.rb 🔗

@@ -184,6 +184,15 @@ def poll_for_notify(db)
 	}.catch(&method(:panic))
 end
 
+def load_plans_to_db!
+	DB.transaction do
+		DB.exec("TRUNCATE plans")
+		CONFIG[:plans].each do |plan|
+			DB.exec("INSERT INTO plans VALUES ($1)", [plan.to_json])
+		end
+	end
+end
+
 when_ready do
 	LOG.info "Ready"
 	BLATHER = self
@@ -203,6 +212,8 @@ when_ready do
 		poll_for_notify(conn)
 	end
 
+	load_plans_to_db!
+
 	EM.add_periodic_timer(3600) do
 		ping = Blather::Stanza::Iq::Ping.new(:get, CONFIG[:server][:host])
 		ping.from = CONFIG[:component][:jid]