Skip to content

Instantly share code, notes, and snippets.

@gmontard
Created April 20, 2012 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmontard/2428488 to your computer and use it in GitHub Desktop.
Save gmontard/2428488 to your computer and use it in GitHub Desktop.
Sync asset cached file to Windows Azure using waz-sync gem
#####
## Add this line to your environment.rb file
# require 'lib/override_assetfile_cache.rb'
####
module ActionView
module Helpers
module AssetTagHelper
def write_asset_file_contents(joined_asset_path, asset_paths)
FileUtils.mkdir_p(File.dirname(joined_asset_path))
File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) }
# Set mtime to the latest of the combined files to allow for
# consistent ETag without a shared filesystem.
mt = asset_paths.map { |p| File.mtime(asset_file_path(p)) }.max
File.utime(mt, mt, joined_asset_path)
######################
### Azure CDN Sync ###
######################
begin
azure = WazSync.new()
folder = joined_asset_path.match(/^.*public\/([^\/]*)\/(.*)$/)[1]
filename = joined_asset_path.match(/^.*public\/([^\/]*)\/(.*)$/)[2]
container = azure.find_or_create_container(folder)
azure.send_or_update(container, joined_asset_path, filename)
rescue
logger.info("Azure Sync Failed")
end
######################
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment