diff options
author | Nathan Broadbent <nathan.f77@gmail.com> | 2013-05-18 11:48:22 +1200 |
---|---|---|
committer | Nathan Broadbent <nathan.f77@gmail.com> | 2013-05-18 12:04:50 +1200 |
commit | b1b0b3c18d6ee05e42a043dde8d48058841df35c (patch) | |
tree | 11b723e6583cccff5345ffd11f22b20cc3c511d0 /lib | |
parent | 56b3ac96521c2630fde811b0f5fdf045a4ab7ff3 (diff) |
Persist history at exit and load on start, so that server restarts don't lose all pushed events
Diffstat (limited to 'lib')
-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 952b614..63fdc37 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 |