Permalink
Browse files

Version 0.1.9 - Adding queue

  • Loading branch information...
1 parent e698fa9 commit b936d2472106eaf3bf716750763c4fdfc4a05b0b @winton committed Nov 18, 2011
Showing with 25 additions and 20 deletions.
  1. +1 −1 execache.gemspec
  2. +24 −19 lib/execache.rb
View
@@ -6,7 +6,7 @@ $:.unshift lib unless $:.include?(lib)
Gem::Specification.new do |s|
s.name = "execache"
- s.version = '0.1.8'
+ s.version = '0.1.9'
s.platform = Gem::Platform::RUBY
s.authors = [ "Winton Welsh" ]
s.email = [ "mail@wintoni.us" ]
View
@@ -69,29 +69,34 @@ def initialize(yaml)
if pending
# Execute command in thread, cache results
- Thread.new do
- Timeout.timeout(60) do
- request.each do |cmd_type, cmd_options|
- if cmd_options['cmd']
- separators = options[cmd_type]['separators'] || {}
- separators['group'] ||= "[END]"
- separators['result'] ||= "\n"
- output = `#{cmd_options['cmd']}`
- output = output.split(separators['group'] + separators['result'])
- output = output.collect { |r| r.split(separators['result']) }
- end
+ unless redis.get('execache:wait')
+ Thread.new do
+ Timeout.timeout(60) do
+ redis.set('execache:wait', '1')
+ redis.expire('execache:wait', 120)
+ request.each do |cmd_type, cmd_options|
+ if cmd_options['cmd']
+ separators = options[cmd_type]['separators'] || {}
+ separators['group'] ||= "[END]"
+ separators['result'] ||= "\n"
+ output = `#{cmd_options['cmd']}`
+ output = output.split(separators['group'] + separators['result'])
+ output = output.collect { |r| r.split(separators['result']) }
+ end
- cmd_options['groups'].each do |group|
- unless group['result']
- redis.set(
- group['cache_key'],
- Yajl::Encoder.encode(output.shift)
- )
- if group['ttl']
- redis.expire(group['cache_key'], group['ttl'])
+ cmd_options['groups'].each do |group|
+ unless group['result']
+ redis.set(
+ group['cache_key'],
+ Yajl::Encoder.encode(output.shift)
+ )
+ if group['ttl']
+ redis.expire(group['cache_key'], group['ttl'])
+ end
end
end
end
+ redis.del('execache:wait')
end
end
end

0 comments on commit b936d24

Please sign in to comment.