Permalink
Browse files

Add configuration options for Rails.

  • Loading branch information...
1 parent ca6fd0a commit 9bc21d5c9bae48c4f3cc8535eeae7a45d9eaf7aa @airhorns committed May 17, 2012
Showing with 20 additions and 33 deletions.
  1. +1 −1 LICENSE
  2. +8 −14 README.md
  3. +0 −7 Rakefile
  4. +0 −1 lib/sprockets-rails-parallel.rb
  5. +11 −4 lib/sprockets/rails/static_compiler_extensions.rb
  6. +0 −6 test/test_foo.rb
View
@@ -1,4 +1,4 @@
-Copyright (c) 2011 Joshua Peek
+Copyright (c) 2012 Shopify Inc
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
@@ -1,19 +1,13 @@
-Foo
-===
+# sprockets-rails-parallel
-Foo is a Ruby library that does something awesome.
+sprockets-rails-parallel is a dirty monkeypatchy hack to make `sprockets-rails` use many processes when precompiling assets. It uses zmq, so you'll need that.
-Installation
-------------
+## Installation
- gem install foo
+Add the gem to your gemfile and then in your `config/application.rb` or one of your environment files, add the following lines:
-Usage
------
+```ruby
+config.assets.parallel_precompile = true
+config.assets.precompile_workers = Integer `sysctl -n hw.ncpu 2>/dev/null` rescue 1 # or something like this
+```
-License
--------
-
-Copyright (c) 2011 Joshua Peek.
-
-Released under the MIT license. See `LICENSE` for details.
View
@@ -1,7 +0,0 @@
-require 'rake/testtask'
-
-task :default => :test
-
-Rake::TestTask.new do |t|
- t.warning = true
-end
@@ -1,4 +1,3 @@
require 'sprockets'
require 'sprockets-rails'
-
require 'sprockets/rails/static_compiler_extensions.rb'
@@ -3,16 +3,21 @@
module Sprockets
module Rails
class StaticCompiler
- WORKERS = 8
KILL_MESSAGE = "die die die!!!!"
- def compile
+ def compile_with_workers
+ unless ::Rails.application.config.assets.parallel_compile
+ return compile_with_workers
+ end
+
+ worker_count = (Rails.application.config.assets.compile_workers || 4).to_i
+
paths = env.each_logical_path.reject {|logical_path| !compile_path?(logical_path)}
total_count = paths.length
manifest = {}
begin
- workers = 1.upto(WORKERS).map do
+ workers = 1.upto(worker_count).map do
fork do
child_context = ZMQ::Context.new(1)
child_receiver = child_context.socket(ZMQ::PULL)
@@ -46,7 +51,7 @@ def compile
receiver.bind("tcp://127.0.0.1:55547")
# Sync workers by blocking on a recieve from each one
- WORKERS.times do
+ worker_count.times do
pid = ''
receiver.recv_string(pid)
end
@@ -69,6 +74,8 @@ def compile
manifest
end
+
+ alias_method_chain :compile, :workers
end
end
end
View
@@ -1,6 +0,0 @@
-require 'foo'
-
-require 'test/unit'
-
-class TestFoo < Test::Unit::TestCase
-end

0 comments on commit 9bc21d5

Please sign in to comment.