execache 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/execache.gemspec +1 -1
  2. data/lib/execache.rb +24 -19
  3. metadata +8 -8
data/execache.gemspec CHANGED
@@ -6,7 +6,7 @@ $:.unshift lib unless $:.include?(lib)
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "execache"
9
- s.version = '0.1.8'
9
+ s.version = '0.1.9'
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.authors = [ "Winton Welsh" ]
12
12
  s.email = [ "mail@wintoni.us" ]
data/lib/execache.rb CHANGED
@@ -69,29 +69,34 @@ class Execache
69
69
 
70
70
  if pending
71
71
  # Execute command in thread, cache results
72
- Thread.new do
73
- Timeout.timeout(60) do
74
- request.each do |cmd_type, cmd_options|
75
- if cmd_options['cmd']
76
- separators = options[cmd_type]['separators'] || {}
77
- separators['group'] ||= "[END]"
78
- separators['result'] ||= "\n"
79
- output = `#{cmd_options['cmd']}`
80
- output = output.split(separators['group'] + separators['result'])
81
- output = output.collect { |r| r.split(separators['result']) }
82
- end
72
+ unless redis.get('execache:wait')
73
+ Thread.new do
74
+ Timeout.timeout(60) do
75
+ redis.set('execache:wait', '1')
76
+ redis.expire('execache:wait', 120)
77
+ request.each do |cmd_type, cmd_options|
78
+ if cmd_options['cmd']
79
+ separators = options[cmd_type]['separators'] || {}
80
+ separators['group'] ||= "[END]"
81
+ separators['result'] ||= "\n"
82
+ output = `#{cmd_options['cmd']}`
83
+ output = output.split(separators['group'] + separators['result'])
84
+ output = output.collect { |r| r.split(separators['result']) }
85
+ end
83
86
 
84
- cmd_options['groups'].each do |group|
85
- unless group['result']
86
- redis.set(
87
- group['cache_key'],
88
- Yajl::Encoder.encode(output.shift)
89
- )
90
- if group['ttl']
91
- redis.expire(group['cache_key'], group['ttl'])
87
+ cmd_options['groups'].each do |group|
88
+ unless group['result']
89
+ redis.set(
90
+ group['cache_key'],
91
+ Yajl::Encoder.encode(output.shift)
92
+ )
93
+ if group['ttl']
94
+ redis.expire(group['cache_key'], group['ttl'])
95
+ end
92
96
  end
93
97
  end
94
98
  end
99
+ redis.del('execache:wait')
95
100
  end
96
101
  end
97
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: execache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-10 00:00:00.000000000Z
12
+ date: 2011-11-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70248493876240 !ruby/object:Gem::Requirement
16
+ requirement: &70180953040920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70248493876240
24
+ version_requirements: *70180953040920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis
27
- requirement: &70248493875640 !ruby/object:Gem::Requirement
27
+ requirement: &70180953040440 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.2.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70248493875640
35
+ version_requirements: *70180953040440
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yajl-ruby
38
- requirement: &70248493875060 !ruby/object:Gem::Requirement
38
+ requirement: &70180953039980 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70248493875060
46
+ version_requirements: *70180953039980
47
47
  description: Run commands in parallel and cache the output. Redis queues jobs and
48
48
  stores the result.
49
49
  email: