-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge the forks #130
Merge the forks #130
Changes from 15 commits
7d51288
499c54d
bcd8bcd
507af82
915193e
14262e7
6c5516e
8277556
73f48bf
4476f0e
5066638
e059316
4633f82
1eac133
b3c0fb7
cd2ea63
6f11a82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'synapse/log' | ||
require 'fileutils' | ||
require 'tempfile' | ||
|
||
module Synapse | ||
class FileOutput | ||
include Logging | ||
attr_reader :opts, :name | ||
|
||
def initialize(opts) | ||
unless opts.has_key?("output_directory") | ||
raise ArgumentError, "flat file generation requires an output_directory key" | ||
end | ||
|
||
begin | ||
FileUtils.mkdir_p(opts['output_directory']) | ||
rescue SystemCallError => err | ||
raise ArgumentError, "provided output directory #{opts['output_directory']} is not present or creatable" | ||
end | ||
|
||
@opts = opts | ||
@name = 'file_output' | ||
end | ||
|
||
def tick(watchers) | ||
end | ||
|
||
def update_config(watchers) | ||
watchers.each do |watcher| | ||
write_backends_to_file(watcher.name, watcher.backends) | ||
end | ||
end | ||
|
||
def write_backends_to_file(service_name, new_backends) | ||
data_path = File.join(@opts['output_directory'], "#{service_name}.json") | ||
begin | ||
old_backends = JSON.load(File.read(data_path)) | ||
rescue Errno::ENOENT | ||
old_backends = nil | ||
end | ||
|
||
if old_backends == new_backends | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a comment explaining this might be helpful to avoid refactoring this away in the future. are you just trying to avoid modified timestamps/inotify events on the files? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, in case libraries watch these files for changes and react accordingly. I'll add a comment |
||
return false | ||
else | ||
# Atomically write new sevice configuration file | ||
temp_path = File.join(@opts['output_directory'], | ||
".#{service_name}.json.tmp") | ||
File.open(temp_path, 'w', 0644) {|f| f.write(new_backends.to_json)} | ||
FileUtils.mv(temp_path, data_path) | ||
return true | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh thank god, finally!