diff options
author | David Underwood <davefp@gmail.com> | 2013-06-21 08:35:32 -0700 |
---|---|---|
committer | David Underwood <davefp@gmail.com> | 2013-06-21 08:35:32 -0700 |
commit | 7d7a07e51bb65d0c98243cb71918515671749ff0 (patch) | |
tree | 89b2eaaae5bd218b65bbc20a148ed83e98f54482 | |
parent | 6f2b57596819f6ecf9f61f161db8d8a7620a5ea8 (diff) | |
parent | b1b0b3c18d6ee05e42a043dde8d48058841df35c (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
-rw-r--r-- | lib/dashing.rb | 17 |
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 |