Skip to content
This repository was archived by the owner on Mar 7, 2018. It is now read-only.

Commit 7d7a07e

Browse files
committed
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
2 parents 6f2b575 + b1b0b3c commit 7d7a07e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/dashing.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require 'coffee-script'
66
require 'sass'
77
require 'json'
8+
require 'yaml'
89

910
SCHEDULER = Rufus::Scheduler.start_new
1011

@@ -17,7 +18,21 @@
1718
settings.sprockets.append_path path
1819
end
1920

20-
set server: 'thin', connections: [], history: {}
21+
set server: 'thin', connections: [], history_file: 'tmp/history.yml'
22+
23+
# Persist history in tmp file at exit
24+
at_exit do
25+
File.open(settings.history_file, 'w') do |f|
26+
f.puts settings.history.to_yaml
27+
end
28+
end
29+
30+
if File.exists?(settings.history_file)
31+
set history: YAML.load_file(settings.history_file)
32+
else
33+
set history: {}
34+
end
35+
2136
set :public_folder, File.join(settings.root, 'public')
2237
set :views, File.join(settings.root, 'dashboards')
2338
set :default_dashboard, nil

0 commit comments

Comments
 (0)