summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Underwood <davefp@gmail.com>2013-06-21 08:35:32 -0700
committerDavid Underwood <davefp@gmail.com>2013-06-21 08:35:32 -0700
commit7d7a07e51bb65d0c98243cb71918515671749ff0 (patch)
tree89b2eaaae5bd218b65bbc20a148ed83e98f54482 /lib
parent6f2b57596819f6ecf9f61f161db8d8a7620a5ea8 (diff)
parentb1b0b3c18d6ee05e42a043dde8d48058841df35c (diff)
Merge pull request #142 from ndbroadbent/persist_history
Persist and load history using a YAML file, so that server restarts don't lose pushed data
Diffstat (limited to 'lib')
-rw-r--r--lib/dashing.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/dashing.rb b/lib/dashing.rb
index 04921fe..24b191c 100644
--- a/lib/dashing.rb
+++ b/lib/dashing.rb
@@ -5,6 +5,7 @@ require 'rufus/scheduler'
require 'coffee-script'
require 'sass'
require 'json'
+require 'yaml'
SCHEDULER = Rufus::Scheduler.start_new
@@ -17,7 +18,21 @@ set :digest_assets, false
settings.sprockets.append_path path
end
-set server: 'thin', connections: [], history: {}
+set server: 'thin', connections: [], history_file: 'tmp/history.yml'
+
+# Persist history in tmp file at exit
+at_exit do
+ File.open(settings.history_file, 'w') do |f|
+ f.puts settings.history.to_yaml
+ end
+end
+
+if File.exists?(settings.history_file)
+ set history: YAML.load_file(settings.history_file)
+else
+ set history: {}
+end
+
set :public_folder, File.join(settings.root, 'public')
set :views, File.join(settings.root, 'dashboards')
set :default_dashboard, nil