Skip to content

Instantly share code, notes, and snippets.

Created August 24, 2015 17:23
Show Gist options
  • Save anonymous/a3c8bd4faadcf762440d to your computer and use it in GitHub Desktop.
Save anonymous/a3c8bd4faadcf762440d to your computer and use it in GitHub Desktop.
Example Rake tasks for @avdi (.NET Web Development with Cygwin)
sln = Dir.glob("*.sln").first
msbuild = "/cygdrive/c/Program Files (x86)/MSBuild/14.0/Bin/MSBuild.exe"
desc "msbuild the solution"
task :build do
sh msbuild, sln
end
desc "runs nunit on valid UnitTests.*.dll assemblies"
task :test => [:build] do
tests = Dir.glob("**/UnitTests.*.dll").lazy
.reject { |t| /Release/.match t }
.reject { |t| /obj/.match t }
.reject { |t| /Scripts/.match t}.to_a
sh "nunit-console", *tests
end
desc "builds and deploys the files"
task :deploy => [:test, :fast_deploy] do
end
desc "deploy without running tests or separate build"
task :fast_deploy do
sh msbuild, sln, "/p:DeployOnBuild=true", "/p:PublishProfile=localhost"
end
desc "build, test, deploy, and wakeup"
task :default => [:deploy, :wakeup]
# Sometimes the deploy doesn't work, I think because timestamps get messed up
# this goes through and touches them so they have more recent updated times
desc "touch all asset files to force deployment"
task :touch do
files = Dir.glob("**/*.cshtml").to_a
sh "touch", *files
files = Dir.glob("**/*.js").to_a
sh "touch", *files
end
# In .NET web apps, after updating config files or executables in the bin
# directory, the AppPool gets recycled, meaning the entire application is reloaded.
# in large applications or CMS projects, this can cause a significant delay.
#
# View files (*.cshtml) are also compiled on the fly during the first request that uses them.
# This also represents a non-negligible delay.
#
# This tasks hits a list of predefined URLS in parallel to both wake up the AppPool
# and also force compilation of various view files that typically impact my testing
# process
require 'thread'
require 'net/http'
class Time
def to_ms
(self.to_f * 1000.0).to_i
end
end
# Change this to your local host domain
host = "myclient.local"
paths = %w(
/
/subscribe
/shop
/shop/some-product
/shopping-cart
/get-and-share-items
/other-shopping/something-you-can-share
/workflow/create-account
)
desc "wakes up the AppPool by making #{paths.count} concurrent requests"
task :wakeup do
threads = []
puts "Hitting #{paths.count} pages on #{host} to force compilation..."
process_start = Time.now.to_ms
paths.each do |path|
threads << Thread.new(path) do |path|
url = "http://" + host + path
start_time = Time.now.to_ms
Net::HTTP.get_response(URI.parse(url))
end_time = Time.now.to_ms
ellapsed = end_time - start_time
puts "HIT: #{path} (#{ellapsed})"
end
end
threads.each(&:join)
process_end = Time.now.to_ms
ellapsed = process_end - process_start
puts "Finished. (#{ellapsed} total)"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment