Skip to content
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

Make assets watchers run as singletons #171

Merged
merged 4 commits into from
Jun 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ These are notable changes in edx-platform. This is a rolling list of changes,
in roughly chronological order, most recent first. Add your entries at or near
the top. Include a label indicating the component affected.

Common: Make asset watchers run as singletons (so they won't start if the
watcher is already running in another shell).

Common: Make rake provide better error messages if packages are missing.

Common: Repairs development documentation generation by sphinx.

LMS: Problem rescoring. Added options on the Grades tab of the
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ gem 'sass', '3.1.15'
gem 'bourbon', '~> 1.3.6'
gem 'colorize', '~> 0.5.8'
gem 'launchy', '~> 2.1.2'
gem 'sys-proctable', '~> 0.9.3'
14 changes: 8 additions & 6 deletions rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require 'json'
require 'rake/clean'
require './rakefiles/helpers.rb'

Dir['rakefiles/*.rake'].each do |rakefile|
import rakefile
begin
require 'json'
require 'rake/clean'
require './rakelib/helpers.rb'
rescue LoadError => error
puts "Import faild (#{error})"
puts "Please run `bundle install` to bootstrap ruby dependencies"
exit 1
end

# Build Constants
Expand Down
13 changes: 8 additions & 5 deletions rakefiles/assets.rake → rakelib/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def sass_cmd(watch=false, debug=false)
"#{watch ? '--watch' : '--update'} -E utf-8 #{sass_watch_paths.join(' ')}"
end

# This task takes arguments purely to pass them via dependencies to the preprocess task
desc "Compile all assets"
multitask :assets => 'assets:all'
task :assets, [:system, :env] => 'assets:all'

namespace :assets do

Expand All @@ -80,8 +81,9 @@ namespace :assets do
{:xmodule => [:install_python_prereqs],
:coffee => [:install_node_prereqs, :'assets:coffee:clobber'],
:sass => [:install_ruby_prereqs, :preprocess]}.each_pair do |asset_type, prereq_tasks|
# This task takes arguments purely to pass them via dependencies to the preprocess task
desc "Compile all #{asset_type} assets"
task asset_type => prereq_tasks do
task asset_type, [:system, :env] => prereq_tasks do |t, args|
cmd = send(asset_type.to_s + "_cmd", watch=false, debug=false)
if cmd.kind_of?(Array)
cmd.each {|c| sh(c)}
Expand All @@ -90,7 +92,8 @@ namespace :assets do
end
end

multitask :all => asset_type
# This task takes arguments purely to pass them via dependencies to the preprocess task
multitask :all, [:system, :env] => asset_type
multitask :debug => "assets:#{asset_type}:debug"
multitask :_watch => "assets:#{asset_type}:_watch"

Expand All @@ -111,9 +114,9 @@ namespace :assets do
task :_watch => (prereq_tasks + ["assets:#{asset_type}:debug"]) do
cmd = send(asset_type.to_s + "_cmd", watch=true, debug=true)
if cmd.kind_of?(Array)
cmd.each {|c| background_process(c)}
cmd.each {|c| singleton_process(c)}
else
background_process(cmd)
singleton_process(cmd)
end
end
end
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions rakefiles/helpers.rb → rakelib/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'digest/md5'
require 'sys/proctable'
require 'colorize'

def find_executable(exec)
path = %x(which #{exec}).strip
Expand Down Expand Up @@ -84,6 +86,16 @@ def background_process(*command)
end
end

# Runs a command as a background process, as long as no other processes
# tagged with the same tag are running
def singleton_process(*command)
if Sys::ProcTable.ps.select {|proc| proc.cmdline.include?(command.join(' '))}.empty?
background_process(*command)
else
puts "Process '#{command.join(' ')} already running, skipping".blue
end
end

def environments(system)
Dir["#{system}/envs/**/*.py"].select{|file| ! (/__init__.py$/ =~ file)}.map do |env_file|
env_file.gsub("#{system}/envs/", '').gsub(/\.py/, '').gsub('/', '.')
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions rakefiles/prereqs.rake → rakelib/prereqs.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require './rakefiles/helpers.rb'

PREREQS_MD5_DIR = ENV["PREREQ_CACHE_DIR"] || File.join(REPO_ROOT, '.prereqs_cache')

CLOBBER.include(PREREQS_MD5_DIR)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.