tengine_job_agent 0.3.17 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,22 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  source "http://rubygems.org"
3
3
 
4
- # Add dependencies required to use your gem here.
5
- # Example:
6
- # gem "activesupport", ">= 2.3.5"
7
-
8
- gem "tengine_support", "~> 0.3.0"
9
- gem "tengine_event", "~> 0.4.0"
10
-
11
- # Add dependencies to develop your gem here.
12
- # Include everything needed to run rake, tests, features, etc.
13
- group :development do
14
- gem "rspec", "~> 2.6.0"
15
- gem "yard", "~> 0.7.2"
16
- gem "bundler", "~> 1.0.18"
17
- gem "jeweler", "~> 1.6.4"
18
- # gem "rcov", ">= 0"
19
- gem "simplecov", "~> 0.5.3"
20
- gem "ZenTest", "~> 4.6.2"
21
- gem "ci_reporter", "~>1.6.5"
22
- end
4
+ gemspec
@@ -1,8 +1,15 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tengine_job_agent (1.1.0)
5
+ tengine_event (~> 1.1.0)
6
+ tengine_support (~> 1.1.0)
7
+
1
8
  GEM
2
9
  remote: http://rubygems.org/
3
10
  specs:
4
- ZenTest (4.6.2)
5
- activesupport (3.2.1)
11
+ ZenTest (4.8.2)
12
+ activesupport (3.2.9)
6
13
  i18n (~> 0.6)
7
14
  multi_json (~> 1.0)
8
15
  amq-client (0.8.7)
@@ -13,55 +20,53 @@ GEM
13
20
  amq-client (~> 0.8.7)
14
21
  amq-protocol (~> 0.8.4)
15
22
  eventmachine
16
- builder (3.0.0)
23
+ autotest (4.4.6)
24
+ ZenTest (>= 4.4.1)
25
+ builder (3.1.3)
17
26
  ci_reporter (1.6.9)
18
27
  builder (>= 2.1.2)
19
28
  diff-lcs (1.1.3)
20
- eventmachine (0.12.10)
21
- git (1.2.5)
22
- i18n (0.6.0)
23
- jeweler (1.6.4)
24
- bundler (~> 1.0)
25
- git (>= 1.2.5)
26
- rake
27
- macaddr (1.5.0)
28
- systemu (>= 2.4.0)
29
- multi_json (1.0.4)
29
+ eventmachine (1.0.0)
30
+ i18n (0.6.1)
31
+ macaddr (1.6.1)
32
+ systemu (~> 2.5.0)
33
+ multi_json (1.3.6)
30
34
  rake (0.9.2.2)
31
- rspec (2.6.0)
32
- rspec-core (~> 2.6.0)
33
- rspec-expectations (~> 2.6.0)
34
- rspec-mocks (~> 2.6.0)
35
- rspec-core (2.6.4)
36
- rspec-expectations (2.6.0)
37
- diff-lcs (~> 1.1.2)
38
- rspec-mocks (2.6.0)
39
- simplecov (0.5.4)
40
- multi_json (~> 1.0.3)
35
+ rdiscount (1.6.8)
36
+ rspec (2.10.0)
37
+ rspec-core (~> 2.10.0)
38
+ rspec-expectations (~> 2.10.0)
39
+ rspec-mocks (~> 2.10.0)
40
+ rspec-core (2.10.1)
41
+ rspec-expectations (2.10.0)
42
+ diff-lcs (~> 1.1.3)
43
+ rspec-mocks (2.10.1)
44
+ simplecov (0.6.4)
45
+ multi_json (~> 1.0)
41
46
  simplecov-html (~> 0.5.3)
42
47
  simplecov-html (0.5.3)
43
- systemu (2.4.2)
44
- tengine_event (0.4.6)
48
+ systemu (2.5.2)
49
+ tengine_event (1.1.0)
45
50
  activesupport (>= 3.0.0)
46
51
  amqp (~> 0.8.0)
47
- tengine_support (>= 0.3.24)
52
+ tengine_support (~> 1.1.0)
48
53
  uuid (~> 2.3.4)
49
- tengine_support (0.3.24)
54
+ tengine_support (1.1.0)
50
55
  activesupport (>= 3.0.0)
51
56
  uuid (2.3.5)
52
57
  macaddr (~> 1.0)
53
- yard (0.7.5)
58
+ yard (0.8.2.1)
54
59
 
55
60
  PLATFORMS
56
61
  ruby
57
62
 
58
63
  DEPENDENCIES
59
- ZenTest (~> 4.6.2)
60
- bundler (~> 1.0.18)
64
+ autotest
65
+ bundler
61
66
  ci_reporter (~> 1.6.5)
62
- jeweler (~> 1.6.4)
63
- rspec (~> 2.6.0)
64
- simplecov (~> 0.5.3)
65
- tengine_event (~> 0.4.0)
66
- tengine_support (~> 0.3.0)
67
- yard (~> 0.7.2)
67
+ rake (~> 0.9.2.2)
68
+ rdiscount
69
+ rspec (~> 2.10.0)
70
+ simplecov (~> 0.6.4)
71
+ tengine_job_agent!
72
+ yard (~> 0.8.1)
@@ -17,4 +17,4 @@ tengine_job_agent is distributed under the MPL2.0 or LGPLv3 or the dual license
17
17
 
18
18
  == Copyright
19
19
 
20
- Copyright (c) 2011 nautilus-technologies.com
20
+ Copyright (c) 2012 Groovenauts, Inc.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tengine_job_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.17
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,99 +13,155 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2012-02-09 00:00:00.000000000Z
16
+ date: 2012-12-19 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: tengine_support
20
- requirement: &2156137340 !ruby/object:Gem::Requirement
20
+ requirement: !ruby/object:Gem::Requirement
21
21
  none: false
22
22
  requirements:
23
23
  - - ~>
24
24
  - !ruby/object:Gem::Version
25
- version: 0.3.0
25
+ version: 1.1.0
26
26
  type: :runtime
27
27
  prerelease: false
28
- version_requirements: *2156137340
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.0
29
34
  - !ruby/object:Gem::Dependency
30
35
  name: tengine_event
31
- requirement: &2156087460 !ruby/object:Gem::Requirement
36
+ requirement: !ruby/object:Gem::Requirement
32
37
  none: false
33
38
  requirements:
34
39
  - - ~>
35
40
  - !ruby/object:Gem::Version
36
- version: 0.4.0
41
+ version: 1.1.0
37
42
  type: :runtime
38
43
  prerelease: false
39
- version_requirements: *2156087460
40
- - !ruby/object:Gem::Dependency
41
- name: rspec
42
- requirement: &2156073520 !ruby/object:Gem::Requirement
44
+ version_requirements: !ruby/object:Gem::Requirement
43
45
  none: false
44
46
  requirements:
45
47
  - - ~>
46
48
  - !ruby/object:Gem::Version
47
- version: 2.6.0
49
+ version: 1.1.0
50
+ - !ruby/object:Gem::Dependency
51
+ name: bundler
52
+ requirement: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
48
58
  type: :development
49
59
  prerelease: false
50
- version_requirements: *2156073520
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
51
66
  - !ruby/object:Gem::Dependency
52
- name: yard
53
- requirement: &2156062440 !ruby/object:Gem::Requirement
67
+ name: rake
68
+ requirement: !ruby/object:Gem::Requirement
54
69
  none: false
55
70
  requirements:
56
71
  - - ~>
57
72
  - !ruby/object:Gem::Version
58
- version: 0.7.2
73
+ version: 0.9.2.2
59
74
  type: :development
60
75
  prerelease: false
61
- version_requirements: *2156062440
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: 0.9.2.2
62
82
  - !ruby/object:Gem::Dependency
63
- name: bundler
64
- requirement: &2156054940 !ruby/object:Gem::Requirement
83
+ name: rspec
84
+ requirement: !ruby/object:Gem::Requirement
65
85
  none: false
66
86
  requirements:
67
87
  - - ~>
68
88
  - !ruby/object:Gem::Version
69
- version: 1.0.18
89
+ version: 2.10.0
70
90
  type: :development
71
91
  prerelease: false
72
- version_requirements: *2156054940
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: 2.10.0
73
98
  - !ruby/object:Gem::Dependency
74
- name: jeweler
75
- requirement: &2156048520 !ruby/object:Gem::Requirement
99
+ name: yard
100
+ requirement: !ruby/object:Gem::Requirement
76
101
  none: false
77
102
  requirements:
78
103
  - - ~>
79
104
  - !ruby/object:Gem::Version
80
- version: 1.6.4
105
+ version: 0.8.1
81
106
  type: :development
82
107
  prerelease: false
83
- version_requirements: *2156048520
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ~>
112
+ - !ruby/object:Gem::Version
113
+ version: 0.8.1
84
114
  - !ruby/object:Gem::Dependency
85
115
  name: simplecov
86
- requirement: &2156033760 !ruby/object:Gem::Requirement
116
+ requirement: !ruby/object:Gem::Requirement
87
117
  none: false
88
118
  requirements:
89
119
  - - ~>
90
120
  - !ruby/object:Gem::Version
91
- version: 0.5.3
121
+ version: 0.6.4
92
122
  type: :development
93
123
  prerelease: false
94
- version_requirements: *2156033760
95
- - !ruby/object:Gem::Dependency
96
- name: ZenTest
97
- requirement: &2156020140 !ruby/object:Gem::Requirement
124
+ version_requirements: !ruby/object:Gem::Requirement
98
125
  none: false
99
126
  requirements:
100
127
  - - ~>
101
128
  - !ruby/object:Gem::Version
102
- version: 4.6.2
129
+ version: 0.6.4
130
+ - !ruby/object:Gem::Dependency
131
+ name: autotest
132
+ requirement: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
103
138
  type: :development
104
139
  prerelease: false
105
- version_requirements: *2156020140
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ - !ruby/object:Gem::Dependency
147
+ name: rdiscount
148
+ requirement: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
106
162
  - !ruby/object:Gem::Dependency
107
163
  name: ci_reporter
108
- requirement: &2156011300 !ruby/object:Gem::Requirement
164
+ requirement: !ruby/object:Gem::Requirement
109
165
  none: false
110
166
  requirements:
111
167
  - - ~>
@@ -113,9 +169,14 @@ dependencies:
113
169
  version: 1.6.5
114
170
  type: :development
115
171
  prerelease: false
116
- version_requirements: *2156011300
172
+ version_requirements: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ~>
176
+ - !ruby/object:Gem::Version
177
+ version: 1.6.5
117
178
  description: tengine_job_agent works with tengine_job
118
- email: tengine@nautilus-technologies.com
179
+ email: tengine-info@groovenauts.jp
119
180
  executables:
120
181
  - tengine_job_agent_kill
121
182
  - tengine_job_agent_run
@@ -124,30 +185,16 @@ extensions: []
124
185
  extra_rdoc_files:
125
186
  - README.rdoc
126
187
  files:
127
- - .document
128
- - .rspec
129
188
  - Gemfile
130
189
  - Gemfile.lock
131
190
  - README.rdoc
132
- - Rakefile
133
- - VERSION
134
191
  - bin/tengine_job_agent_kill
135
192
  - bin/tengine_job_agent_run
136
193
  - bin/tengine_job_agent_watchdog
137
- - lib/tengine_job_agent.rb
138
194
  - lib/tengine_job_agent/command_utils.rb
139
195
  - lib/tengine_job_agent/run.rb
140
196
  - lib/tengine_job_agent/watchdog.rb
141
- - spec/.gitignore
142
- - spec/config/tengine_job_agent.yml.erb
143
- - spec/log/.gitignore
144
- - spec/spec_helper.rb
145
- - spec/tengine_job_agent/command_utils_spec.rb
146
- - spec/tengine_job_agent/run_spec.rb
147
- - spec/tengine_job_agent/scripts/echo_foo.sh
148
- - spec/tengine_job_agent/scripts/sleep.sh
149
- - spec/tengine_job_agent/watchdog_spec.rb
150
- - tengine_job_agent.gemspec
197
+ - lib/tengine_job_agent.rb
151
198
  homepage: http://github.com/tengine/tengine_job_agent
152
199
  licenses:
153
200
  - MPL2.0/LGPLv3
@@ -163,7 +210,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
210
  version: '0'
164
211
  segments:
165
212
  - 0
166
- hash: 2510971988355542702
213
+ hash: -739102963510828694
167
214
  required_rubygems_version: !ruby/object:Gem::Requirement
168
215
  none: false
169
216
  requirements:
@@ -172,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
219
  version: '0'
173
220
  requirements: []
174
221
  rubyforge_project:
175
- rubygems_version: 1.8.12
222
+ rubygems_version: 1.8.23
176
223
  signing_key:
177
224
  specification_version: 3
178
225
  summary: tengine_job_agent invoke job, watches it and notify its finish to tengine
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/Rakefile DELETED
@@ -1,42 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "tengine_job_agent"
18
- gem.homepage = "http://github.com/tengine/tengine_job_agent"
19
- gem.license = "MPL2.0/LGPLv3"
20
- gem.summary = %Q{tengine_job_agent invoke job, watches it and notify its finish to tengine server}
21
- gem.description = %Q{tengine_job_agent works with tengine_job}
22
- gem.email = "tengine@nautilus-technologies.com"
23
- gem.authors = %w[taigou totty g-morita shyouhei akm]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- require 'rspec/core'
29
- require 'rspec/core/rake_task'
30
- RSpec::Core::RakeTask.new(:spec) do |spec|
31
- spec.pattern = FileList['spec/**/*_spec.rb']
32
- end
33
-
34
- RSpec::Core::RakeTask.new(:rcov) do |spec|
35
- spec.pattern = 'spec/**/*_spec.rb'
36
- spec.rcov = true
37
- end
38
-
39
- task :default => :spec
40
-
41
- require 'yard'
42
- YARD::Rake::YardocTask.new
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.17
@@ -1 +0,0 @@
1
- /pid_for_*
@@ -1,17 +0,0 @@
1
- ---
2
- timeout: 1
3
- # log_dir: "log"
4
- logfile: "<%= %!log/#{File.basename($PROGRAM_NAME)}-#{`hostname`.strip}-#{Process.pid}.log! %>"
5
- connection:
6
- host: 'localhost'
7
- port: 5672
8
- # vhost:
9
- # user:
10
- # pass:
11
- exchange:
12
- name: 'tengine_event_exchange'
13
- type: 'direct'
14
- durable: true
15
- heartbeat:
16
- job:
17
- interval: 1
@@ -1,14 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'simplecov'
4
- SimpleCov.start if ENV["COVERAGE"]
5
- require 'rspec'
6
- require 'tengine_job_agent'
7
-
8
- # Requires supporting files with custom matchers and macros, etc,
9
- # in ./support/ and its subdirectories.
10
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
-
12
- RSpec.configure do |config|
13
-
14
- end
@@ -1,124 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
- require 'tmpdir'
4
- require 'tempfile'
5
-
6
- describe TengineJobAgent::CommandUtils do
7
- describe ".included" do
8
- it "ClassMethodsを追加" do
9
- foo = Class.new do
10
- include TengineJobAgent::CommandUtils
11
- end
12
- foo.singleton_class.ancestors.should include(TengineJobAgent::CommandUtils::ClassMethods)
13
- end
14
- end
15
-
16
- context "::ClassMethods" do
17
- describe "#load_config" do
18
- subject { Class.new { include TengineJobAgent::CommandUtils::ClassMethods }.new }
19
-
20
- it "Hashをかえす" do
21
- Dir.chdir File.expand_path("../..", __FILE__) do
22
- subject.load_config.should be_kind_of(Hash)
23
- end
24
- end
25
-
26
- it "./tengine_job_agent.ymlを読む" do
27
- Dir.mktmpdir do |nam|
28
- Dir.chdir nam do
29
- File.open("tengine_job_agent.yml", "wb") {|f| f.puts "foo: bar\n" }
30
- subject.load_config.should == { "foo" => "bar" }
31
- end
32
- end
33
- end
34
-
35
- it "./config/tengine_job_agent.ymlを読む" do
36
- Dir.mktmpdir do |nam|
37
- Dir.chdir nam do
38
- Dir.mkdir "config"
39
- File.open("config/tengine_job_agent.yml", "wb") {|f| f.puts "foo: bar\n" }
40
- subject.load_config.should == { "foo" => "bar" }
41
- end
42
- end
43
- end
44
-
45
- it "/etc/tengine_job_agent.ymlを読む" do
46
- begin
47
- if File.exist? "/etc/tengine_job_agent.yml"
48
- obj = YAML.load_file "/etc/tengine_job_agent.yml"
49
- subject.load_config.should == obj
50
- else
51
- File.open("/etc/tengine_job_agent.yml", "wb") {|f| f.puts "foo: bar\n" }
52
- subject.load_config.should == { "foo" => "bar" }
53
- end
54
- rescue Errno::EACCES
55
- pending $!.message
56
- end
57
- end
58
- end
59
-
60
- describe "#new_logger" do
61
- subject { Class.new { include TengineJobAgent::CommandUtils::ClassMethods }.new }
62
- before { subject.stub(:name).and_return("foobar") }
63
-
64
- it "logfileを指定する場合" do
65
- Dir.mktmpdir do |nam|
66
- Logger.should_receive(:new).with("foo/bar/baz.log")
67
- subject.new_logger('logfile' => "foo/bar/baz.log")
68
- end
69
- end
70
-
71
- it "logfileもlog_dirも指定する場合" do
72
- Dir.mktmpdir do |nam|
73
- Logger.should_receive(:new).with(/\/foobar-\d+?.log$/)
74
- subject.new_logger({})
75
- end
76
- end
77
-
78
- it "Loggerを返す" do
79
- Dir.mktmpdir do |nam|
80
- subject.new_logger('log_dir' => nam).should be_kind_of(Logger)
81
- end
82
- end
83
-
84
- it "引数はディレクトリである" do
85
- Tempfile.new("") do |f|
86
- subject.new_logger('log_dir' => "nonexistent").should raise_exception(Errno::ENOENT)
87
- subject.new_logger('log_dir' => f.path).should raise_exception(Errno::ENOENT)
88
- end
89
- end
90
-
91
- it "ログファイルは引数のディレクトリの中にできる" do
92
- Dir.mktmpdir do |nam|
93
- subject.new_logger('log_dir' => nam)
94
- nam.should have_at_least(3).files
95
- end
96
- end
97
-
98
- end
99
-
100
- describe "#process" do
101
- subject { Class.new { include TengineJobAgent::CommandUtils } }
102
- let(:instance) { mock(subject.new) }
103
- before do
104
- instance
105
- subject.stub(:new).with(anything, anything, anything).and_return(instance)
106
- subject.stub(:name).and_return(File.basename(__FILE__, ".rb"))
107
- end
108
-
109
- it "インスタンスを生成してprocessを呼ぶ" do
110
- instance.should_receive(:process)
111
- Dir.chdir File.expand_path("../..", __FILE__) do
112
- subject.process
113
- end
114
- end
115
-
116
- it "失敗するとfalseを返す" do
117
- instance.should_receive(:process).and_raise(RuntimeError)
118
- Dir.chdir File.expand_path("../..", __FILE__) do
119
- subject.process.should == false
120
- end
121
- end
122
- end
123
- end
124
- end
@@ -1,107 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- require 'yaml'
5
- require 'tengine/support/yaml_with_erb'
6
- require 'rbconfig'
7
-
8
- describe TengineJobAgent::Run do
9
-
10
- before do
11
- @log_buffer = StringIO.new
12
- @logger = Logger.new(@log_buffer)
13
- config = YAML.load_file(File.expand_path("../config/tengine_job_agent.yml.erb",
14
- File.dirname(__FILE__)))
15
- @config = config.inject({}) {|r, (k, v)| r.update k.intern => v }
16
- end
17
-
18
- subject do
19
- Dir.chdir File.expand_path("../..", __FILE__) do
20
- TengineJobAgent::Run.new(@logger, %w"scripts/echo_foo.sh", @config)
21
- end
22
- end
23
-
24
- it { should_not be_nil }
25
-
26
- describe "#process" do
27
-
28
- let(:f) { mock(File.open("/dev/null")) }
29
-
30
- before do
31
- subject.stub(:spawn_watchdog).and_return mock(Numeric.new)
32
- f
33
- File.stub(:open).with(an_instance_of(String), "r").and_yield(f)
34
- File.stub(:open).with(an_instance_of(String), "w")
35
- end
36
-
37
- context "正常起動" do
38
- it "EXIT_SUCCESS" do
39
- STDOUT.stub(:puts).with(an_instance_of(String))
40
- f.stub(:gets).and_return("0\n")
41
- subject.process.should == true
42
- end
43
- end
44
-
45
- context "spawnできない" do
46
- it "EXIT_FAILURE" do
47
- STDERR.stub(:puts) do |arg|
48
- arg.should =~ /foo bar/
49
- end
50
- f.stub(:read).and_return("foo bar")
51
- f.stub(:gets).and_return("foo bar")
52
- f.stub(:rewind)
53
- subject.process.should == false
54
- end
55
- end
56
-
57
- context "timeout" do
58
- it "EXIT_FAILURE" do
59
- f.stub(:gets)
60
- lambda { subject.process }.should raise_exception(Timeout::Error)
61
- end
62
- end
63
- end
64
-
65
- describe "#spawn_watchdog" do
66
- it "tengine_job_agent_watchdogを起動する" do
67
- watchdog = File.expand_path("../../bin/tengine_job_agent_watchdog", File.dirname(__FILE__))
68
- Process.should_receive(:spawn).with(RbConfig.ruby, watchdog, an_instance_of(String), anything)
69
- subject.spawn_watchdog
70
- end
71
-
72
- it "pidを返す" do
73
- pid = mock(Numeric.new)
74
- Process.stub(:spawn).with(RbConfig.ruby, anything, anything, anything).and_return(pid)
75
- subject.spawn_watchdog.should == pid
76
- end
77
-
78
- it "終了を待たない" do
79
- Process.stub(:spawn).with(RbConfig.ruby, anything, anything, anything)
80
- Process.should_not_receive :wait
81
- Process.should_not_receive :waitpid
82
- Process.should_not_receive :waitpid2
83
- subject.spawn_watchdog
84
- end
85
- end
86
-
87
- describe "#initialize" do
88
- it "第一引数にlogger" do
89
- watchdog = File.expand_path("../../bin/tengine_job_agent_watchdog", File.dirname(__FILE__))
90
- Process.should_receive(:spawn).with(RbConfig.ruby, watchdog, an_instance_of(String), anything)
91
- subject.spawn_watchdog
92
- @log_buffer.string.should_not be_empty
93
- end
94
-
95
- it "第二引数は起動するプロセスへの引数の配列" do
96
- watchdog = File.expand_path("../../bin/tengine_job_agent_watchdog", File.dirname(__FILE__))
97
- Process.should_receive(:spawn).with(RbConfig.ruby, watchdog, an_instance_of(String), "scripts/echo_foo.sh")
98
- subject.spawn_watchdog
99
- end
100
-
101
- it "第三引数はconfig" do
102
- subject.stub(:timeout) do |tim|
103
- tim.should == @config[:timeout]
104
- end
105
- end
106
- end
107
- end
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- echo 'foo'
4
- exit 0
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- typeset -i time=$1
4
- echo "`date` sleep.sh start"
5
- sleep `expr 1 + $time`
6
- echo "`date` sleep.sh finish"
@@ -1,307 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
- require 'amqp'
4
-
5
- require 'timeout'
6
-
7
- require 'yaml'
8
- require 'tengine/support/yaml_with_erb'
9
-
10
- describe TengineJobAgent::Watchdog do
11
-
12
- before do
13
- @log_buffer = StringIO.new
14
- @logger = Logger.new(@log_buffer)
15
- @config = YAML.load_file(File.expand_path("../config/tengine_job_agent.yml.erb",
16
- File.dirname(__FILE__)))
17
- end
18
-
19
- subject do
20
- @pid_path = "/dev/null"
21
- echo_foo = File.expand_path "../scripts/echo_foo.sh", __FILE__
22
- TengineJobAgent::Watchdog.new(@logger, [@pid_path, echo_foo], @config)
23
- end
24
-
25
- it { should_not be_nil }
26
-
27
- describe "#process" do
28
- let(:pid) { mock(Numeric.new) }
29
- let(:stat) { mock($?) }
30
- before do
31
- bigzero = (1 << 1024).coerce(0)[0]
32
- pid.stub(:to_int).and_return(bigzero)
33
- stat.stub(:exitstatus).and_return(bigzero)
34
- end
35
-
36
- it "spawnする" do
37
- subject.should_receive(:spawn_process).and_return(pid)
38
- subject.stub(:detach_and_wait_process).with(pid).and_return(stat)
39
- subject.stub(:fire_finished).with(pid, stat)
40
- sender = mock(:sender)
41
- sender.stub_chain(:mq_suite, :ensures).with(:connection).and_yield
42
- subject.stub(:sender).and_return(sender)
43
- sender.stub(:wait_for_connection).and_yield
44
- EM.run do
45
- EM.add_timer(0.1) { EM.stop }
46
- subject.process
47
- end
48
- end
49
-
50
- it "子プロセスを待つ" do
51
- subject.stub(:spawn_process).and_return(pid)
52
- subject.should_receive(:detach_and_wait_process).and_return(stat)
53
- subject.stub(:fire_finished).with(pid, stat)
54
- sender = mock(:sender)
55
- sender.stub_chain(:mq_suite, :ensures).with(:connection).and_yield
56
- subject.stub(:sender).and_return(sender)
57
- sender.stub(:wait_for_connection).and_yield
58
- EM.run do
59
- EM.add_timer(0.1) { EM.stop }
60
- subject.process
61
- end
62
- end
63
-
64
- context "ファイルへの出力" do
65
- before do
66
- @echo_foo = File.expand_path "../scripts/echo_foo.sh", __FILE__
67
- mock_stdout = mock(:stdout, :path => "/tmp/stdout")
68
- mock_stderr = mock(:stderr, :path => "/tmp/stderr")
69
- subject.should_receive(:with_tmp_outs).and_yield(mock_stdout, mock_stderr)
70
- sender = mock(:sender)
71
- sender.stub_chain(:mq_suite, :ensures).with(:connection).and_yield
72
- subject.stub(:sender).and_return(sender)
73
- sender.stub(:wait_for_connection).and_yield
74
- end
75
-
76
- it "実行に成功した場合はPIDが出力される" do
77
- subject.should_receive(:spawn_process).and_return(pid)
78
- mock_pid_file = mock(:pid_file)
79
- File.should_receive(:open).with(@pid_path, "a").and_yield(mock_pid_file)
80
- mock_pid_file.should_receive(:puts).with(pid)
81
- subject.should_receive(:detach_and_wait_process).with(pid)
82
- EM.run do
83
- EM.add_timer(0.1) { EM.stop }
84
- subject.process
85
- end
86
- end
87
-
88
- it "ファイルが存在せずspawnに失敗した場合、エラーを出力する" do
89
- subject.should_receive(:spawn_process).and_raise(Errno::ENOENT.new(@echo_foo))
90
- mock_pid_file = mock(:pid_file)
91
- File.should_receive(:open).with(@pid_path, "a").and_yield(mock_pid_file)
92
- mock_pid_file.should_receive(:puts).with("[Errno::ENOENT] No such file or directory - #{@echo_foo}")
93
- timeout(0.5) do
94
- EM.run do
95
- # EM.add_timer(0.1) { EM.stop } # 起動に失敗したらEMは自動でstopされる
96
- subject.process
97
- end
98
- end
99
- end
100
- end
101
-
102
- end
103
-
104
- describe "#spawn_process" do
105
- let(:pid) { mock(Numeric.new) }
106
- let(:thr) { mock(Thread.start do Thread.stop end) }
107
- let(:stat) { mock($?) }
108
- before do
109
- o = mock(STDOUT)
110
- e = mock(STDERR)
111
- o.stub(:path).and_return(String.new)
112
- e.stub(:path).and_return(String.new)
113
- subject.instance_eval do
114
- @stdout = o
115
- @stderr = e
116
- end
117
- end
118
-
119
- it "spawnする" do
120
- echo_foo = File.expand_path "../scripts/echo_foo.sh", __FILE__
121
- Process.should_receive(:spawn).with(echo_foo, an_instance_of(Hash)).and_return(pid)
122
- subject.spawn_process.should == pid
123
- end
124
-
125
- it "No such file or directoryで失敗する" do
126
- echo_foo = File.expand_path "../scripts/echo_foo.sh", __FILE__
127
- Process.should_receive(:spawn).with(echo_foo, an_instance_of(Hash)).
128
- and_raise(Errno::ENOENT.new(echo_foo))
129
- expect {
130
- subject.spawn_process
131
- }.to raise_error(Errno::ENOENT)
132
- end
133
- end
134
-
135
- describe "#detach_and_wait_process" do
136
- let(:pid) { mock(Numeric.new) }
137
- let(:stat) { mock($?) }
138
- before do
139
- bigzero = (1 << 1024).coerce(0).first
140
- stat.stub(:exitstatus).and_return(bigzero)
141
- pid.stub(:to_int).and_return(bigzero)
142
- Process.stub(:waitpid2).with(pid) do
143
- sleep 3
144
- [pid, stat]
145
- end
146
- subject.stub(:fire_finished) do EM.stop end
147
- subject.stub(:fire_heartbeat).with(pid).and_yield
148
- end
149
-
150
- it "pidを待つ" do
151
- EM.run do
152
- subject.should_receive(:fire_finished) do EM.stop end
153
- subject.detach_and_wait_process(pid)
154
- end
155
- end
156
-
157
- it "heartbeatをfireしつづける" do
158
- EM.run do
159
- subject.should_receive(:fire_heartbeat).at_least(2).times.and_yield
160
- subject.detach_and_wait_process(pid)
161
- end
162
- end
163
-
164
- it "https://www.pivotaltracker.com/story/show/21515847" do
165
- EM.run do
166
- subject.instance_eval { @config["heartbeat"]["job"]["interval"] = 0 }
167
- subject.unstub(:fire_heartbeat)
168
- subject.should_receive(:fire_heartbeat).at_least(1).times.and_yield
169
- subject.detach_and_wait_process(pid)
170
- end
171
- end
172
-
173
- context "プロセスは正常に動き続けているがfireに失敗した場合" do
174
- it "その回のfireはあきらめる。例外などで死なない" do
175
- EM.run do
176
- subject.unstub(:fire_heartbeat)
177
- s = mock(Tengine::Event::Sender.new)
178
- subject.stub(:sender).and_return(s)
179
- def s.fire e, h, &b
180
- h[:retry_count].should_not == nil
181
- h[:retry_count].should == 0
182
- b.yield if b
183
- end
184
- expect {
185
- subject.detach_and_wait_process(pid)
186
- }.to_not raise_exception(Tengine::Event::Sender::RetryError)
187
- end
188
- end
189
- end
190
-
191
- context "finishしたときのtimerの挙動" do
192
- def live_timers_count
193
- # これはひどい...
194
- ObjectSpace.each_object(EM::PeriodicTimer).reject do |i|
195
- i.instance_eval do
196
- @cancelled
197
- end
198
- end
199
- end
200
- it "https://www.pivotaltracker.com/story/show/21466285" do
201
- n = live_timers_count
202
- EM.run do
203
- subject.detach_and_wait_process(pid)
204
- end
205
- live_timers_count.should == n
206
- end
207
- end
208
- end
209
-
210
- describe "#fire_finished" do
211
- let(:pid) { mock(Numeric.new) }
212
- let(:stat) { mock($?) }
213
- before do
214
- pid.stub(:to_int).and_return(-0.0/1.0)
215
- conn = mock(:connection)
216
- ch = Object.new
217
-
218
- AMQP.stub(:connect).with(an_instance_of(Hash)).and_return(conn)
219
- AMQP::Channel.stub(:new).with(conn, :prefetch => 1, :auto_recovery => true).and_return(ch)
220
- AMQP::Exchange.stub(:new).with(ch, "direct", "exchange1",
221
- :passive=>false, :durable=>true, :auto_delete=>false, :internal=>false, :nowait=>true)
222
- conn.stub(:on_tcp_connection_loss)
223
- conn.stub(:after_recovery)
224
- conn.stub(:on_closed)
225
- sender = mock(:sender)
226
- subject.stub(:sender).and_return(sender)
227
- sender.stub(:wait_for_connection).and_yield
228
-
229
- o = mock(STDOUT)
230
- e = mock(STDERR)
231
- o.stub(:path).and_return(String.new)
232
- e.stub(:path).and_return(String.new)
233
- subject.instance_eval do
234
- @stdout = o
235
- @stderr = e
236
- end
237
- end
238
-
239
- it "finished.process.job.tengineをfire" do
240
- EM.run do
241
- FileUtils.stub(:cp).with(an_instance_of(String), an_instance_of(String))
242
- stat.stub(:exitstatus).and_return(0)
243
- s = mock(Tengine::Event::Sender.new)
244
- subject.stub(:sender).and_return s
245
- s.stub(:stop)
246
- s.should_receive(:fire) do |k, v|
247
- k.should == "finished.process.job.tengine"
248
- v[:level_key].should == :info
249
- v[:properties]["pid"].should == pid
250
- v[:properties]["exit_status"].should == stat.exitstatus
251
- end
252
- subject.fire_finished(pid, stat)
253
- EM.add_timer(0.1) { EM.stop }
254
- end
255
- end
256
-
257
- it "プロセスが失敗していた場合" do
258
- EM.run do
259
- FileUtils.stub(:cp).with(an_instance_of(String), an_instance_of(String))
260
- stat.stub(:exitstatus).and_return(256)
261
- s = mock(Tengine::Event::Sender.new)
262
- subject.stub(:sender).and_return s
263
- s.stub(:stop)
264
- s.should_receive(:fire) do |k, v|
265
- k.should == "finished.process.job.tengine"
266
- v[:level_key].should == :error
267
- v[:properties][:message].should =~ /^Job process failed./
268
- end
269
- subject.fire_finished(pid, stat)
270
- EM.add_timer(0.1) { EM.stop }
271
- end
272
- end
273
-
274
- context "プロセスは正常に終了したがfireに失敗した場合" do
275
- it "fireできるようになるまでリトライを続ける" do
276
- EM.run do
277
- stat.stub(:exitstatus).and_return(0)
278
- s = mock(Tengine::Event::Sender.new)
279
- n = 0
280
- subject.stub(:sender).and_return(s)
281
- s.stub(:stop)
282
- s.stub(:fire).with("finished.process.job.tengine", an_instance_of(Hash)) do |e, h|
283
- if h[:retry_count]
284
- h[:retry_count].should > 0
285
- end
286
- end
287
- expect {
288
- subject.fire_finished(pid, stat)
289
- }.to_not raise_exception(Tengine::Event::Sender::RetryError)
290
- EM.add_timer(0.1) { EM.stop }
291
- end
292
- end
293
- end
294
- end
295
-
296
- describe "#sender" do
297
- before do
298
- conn = mock(:connection)
299
- conn.stub(:on_tcp_connection_loss)
300
- conn.stub(:after_recovery)
301
- conn.stub(:on_closed)
302
- AMQP.stub(:connect).with(an_instance_of(Hash)).and_return(conn)
303
- end
304
- subject { TengineJobAgent::Watchdog.new(@logger, %w"", @config).sender }
305
- it { should be_kind_of(Tengine::Event::Sender) }
306
- end
307
- end
@@ -1,87 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "tengine_job_agent"
8
- s.version = "0.3.17"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["taigou", "totty", "g-morita", "shyouhei", "akm"]
12
- s.date = "2012-02-09"
13
- s.description = "tengine_job_agent works with tengine_job"
14
- s.email = "tengine@nautilus-technologies.com"
15
- s.executables = ["tengine_job_agent_kill", "tengine_job_agent_run", "tengine_job_agent_watchdog"]
16
- s.extra_rdoc_files = [
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".rspec",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "bin/tengine_job_agent_kill",
28
- "bin/tengine_job_agent_run",
29
- "bin/tengine_job_agent_watchdog",
30
- "lib/tengine_job_agent.rb",
31
- "lib/tengine_job_agent/command_utils.rb",
32
- "lib/tengine_job_agent/run.rb",
33
- "lib/tengine_job_agent/watchdog.rb",
34
- "spec/.gitignore",
35
- "spec/config/tengine_job_agent.yml.erb",
36
- "spec/log/.gitignore",
37
- "spec/spec_helper.rb",
38
- "spec/tengine_job_agent/command_utils_spec.rb",
39
- "spec/tengine_job_agent/run_spec.rb",
40
- "spec/tengine_job_agent/scripts/echo_foo.sh",
41
- "spec/tengine_job_agent/scripts/sleep.sh",
42
- "spec/tengine_job_agent/watchdog_spec.rb",
43
- "tengine_job_agent.gemspec"
44
- ]
45
- s.homepage = "http://github.com/tengine/tengine_job_agent"
46
- s.licenses = ["MPL2.0/LGPLv3"]
47
- s.require_paths = ["lib"]
48
- s.rubygems_version = "1.8.12"
49
- s.summary = "tengine_job_agent invoke job, watches it and notify its finish to tengine server"
50
-
51
- if s.respond_to? :specification_version then
52
- s.specification_version = 3
53
-
54
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<tengine_support>, ["~> 0.3.0"])
56
- s.add_runtime_dependency(%q<tengine_event>, ["~> 0.4.0"])
57
- s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
58
- s.add_development_dependency(%q<yard>, ["~> 0.7.2"])
59
- s.add_development_dependency(%q<bundler>, ["~> 1.0.18"])
60
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
61
- s.add_development_dependency(%q<simplecov>, ["~> 0.5.3"])
62
- s.add_development_dependency(%q<ZenTest>, ["~> 4.6.2"])
63
- s.add_development_dependency(%q<ci_reporter>, ["~> 1.6.5"])
64
- else
65
- s.add_dependency(%q<tengine_support>, ["~> 0.3.0"])
66
- s.add_dependency(%q<tengine_event>, ["~> 0.4.0"])
67
- s.add_dependency(%q<rspec>, ["~> 2.6.0"])
68
- s.add_dependency(%q<yard>, ["~> 0.7.2"])
69
- s.add_dependency(%q<bundler>, ["~> 1.0.18"])
70
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
71
- s.add_dependency(%q<simplecov>, ["~> 0.5.3"])
72
- s.add_dependency(%q<ZenTest>, ["~> 4.6.2"])
73
- s.add_dependency(%q<ci_reporter>, ["~> 1.6.5"])
74
- end
75
- else
76
- s.add_dependency(%q<tengine_support>, ["~> 0.3.0"])
77
- s.add_dependency(%q<tengine_event>, ["~> 0.4.0"])
78
- s.add_dependency(%q<rspec>, ["~> 2.6.0"])
79
- s.add_dependency(%q<yard>, ["~> 0.7.2"])
80
- s.add_dependency(%q<bundler>, ["~> 1.0.18"])
81
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
82
- s.add_dependency(%q<simplecov>, ["~> 0.5.3"])
83
- s.add_dependency(%q<ZenTest>, ["~> 4.6.2"])
84
- s.add_dependency(%q<ci_reporter>, ["~> 1.6.5"])
85
- end
86
- end
87
-