omf_rc_shm 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTM4MTc2MWI2YzI4ZTQ1NTVhYjJkNmY1ZWRjOWM2MWNkMTJhNmI5Yg==
4
+ MGVlZDhmOTQ2NzU5MWZhOTg0ODQ0MjAyMmVkODU0Mzg0ZDY3YmUyMA==
5
5
  data.tar.gz: !binary |-
6
- MWNiMDIzYWEzZDlmMmU2M2UzYTZlMjYwZjZjZjkxZGFiN2FmNDk4NQ==
6
+ OGE1NmNkOWJmMDFjMGNhOWMxNWU1ZGY3YmIyYTZjODE4NmQxNzQwYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ODNkZWU1YWEwYzk0NTIxMTJiMjFmZTg0NDY5Y2M0MWM0Mjk0N2U0NWVkOWM3
10
- MDYxNmRhNTFkYmZkYmJlYzljM2RjZTQyODk2NWJhYmNhZjJlZGJlZDQ5MmFm
11
- OWQ5MThkNGZlNWFhNzNkNjc4ODZhNjllNmFkODU3OTI3YWM1ZjE=
9
+ MjQwYWVkNjUwYzVlMWUwNTM3NTVkNzhlYzJjNDNiMjIxNWFjOTZkMmRhYTY2
10
+ MTg1Mjg2NzI0MWZhODVlNjU4MjAwNjQ3ZWNkYjViNjg2NTllM2RlOGFhZjYw
11
+ ZjAzYjA3ZjEwMGI4ZjgwNGUxNzUwNDUxYjlhZmYyODUyMTNiOTI=
12
12
  data.tar.gz: !binary |-
13
- NGVmNjY1ZTcxOTkzMzE1ZWJmZjAxZDgxNzg3YWUyNzljOWM5MDM2YTY2YTVl
14
- MjA2YmRiMjQ1NDlhNTEyYjMyNTcxNzIzM2Y4ZGQyMzQzN2VjZTFlYTRjNzEx
15
- NjFlMDZjNDIwNWRiMmRkZjU3ODhiNWRiMWQwYTgxNGI0ZTA5ZjQ=
13
+ YTE2MTMxYTgzMmNhMzdiNDZjOTc4YmQ0NzFmNzQ3Y2NkNjAyODczNmEzMjQ4
14
+ NzdjOGMzODY4YWQzZmIxOGI5YzYzMDljOTYzODZkMGE4NjIzNTJmY2QxMzEw
15
+ NDFhNWZjYmY0OGI0ZmE4MmJhYmUyYjNhZTBjMTBjNDk1M2EyNjY=
@@ -96,7 +96,7 @@ module OmfRc::ResourceProxy::ScheduledApplication
96
96
  property :oml, :default => Hashie::Mash.new
97
97
  property :oml_logfile, :default => nil
98
98
  property :oml_loglevel, :default => nil
99
- property :schedule, :default => nil
99
+ property :schedule, :default => "now"
100
100
  property :timeout, :default => 0
101
101
  property :timeout_kill_signal, :default => 'TERM'
102
102
  property :file_change_listener, :default => nil
@@ -304,15 +304,32 @@ module OmfRc::ResourceProxy::ScheduledApplication
304
304
  elsif res.property.schedule.nil?
305
305
  res.log_inform_warn "No schedule given!"
306
306
  else
307
+ # "now" schedules job to run once, two minutes from now
308
+ if res.property.schedule == "now"
309
+ t = Time.now()+120
310
+ res.property.schedule = t.strftime("%-M %-H %-d %-m *")
311
+ end
307
312
  Dir.mkdir(res.property.app_log_dir) if !Dir.exist?(res.property.app_log_dir)
308
313
  stderr_file = "#{res.property.app_log_dir}/#{res.property.app_id}.err.log"
309
314
  stdout_file = "#{res.property.app_log_dir}/#{res.property.app_id}.out.log"
315
+ pid_file = "#{res.property.app_log_dir}/#{res.property.app_id}.pid.log"
310
316
  File.delete(stderr_file) if File.exist?(stderr_file)
311
317
  File.delete(stdout_file) if File.exist?(stdout_file)
312
- cmd = "#{res.build_command_line} 2>>#{stderr_file} 1>>#{stdout_file} ; echo \"Application '#{res.property.app_id}' exited with code $? \" >>#{stderr_file}"
313
- if res.property.timeout > 0
314
- cmd = "timeout -s #{res.property.timeout_kill_signal} #{res.property.timeout} #{cmd}"
315
- end
318
+ File.delete(pid_file) if File.exist?(pid_file)
319
+ #cmd = "#{res.build_command_line} 2>>#{stderr_file} 1>>#{stdout_file}; echo \"Application exited with code: $? \" >>#{stderr_file}"
320
+ cmd = "ruby -e 'pid = spawn(\"#{res.build_command_line}\", :out=>[\"#{stdout_file}\", \"a\"], :err=>[\"#{stderr_file}\", \"a\"])
321
+ `echo \#{pid} >> #{pid_file}`
322
+ fork {
323
+ sleep #{res.property.timeout}
324
+ Process.kill(\"#{res.property.timeout_kill_signal}\", pid)
325
+ } if #{res.property.timeout} > 0
326
+ Process.waitpid(pid)
327
+ `echo Process \#{pid} exited with code: \#{$?.exitstatus} >> #{stderr_file}`'"
328
+ cmd.gsub!(/[\n]+/, ";");
329
+ # cmd = "#{res.build_command_line} 2>>#{stderr_file} 1>>#{stdout_file};"
330
+ # if res.property.timeout > 0
331
+ # cmd = "timeout -s #{res.property.timeout_kill_signal} #{res.property.timeout} #{cmd}"
332
+ # end
316
333
  info "Adding cron job for '#{res.property.app_id}' with schedule '#{res.property.schedule}' and command '#{cmd}'"
317
334
  CronEdit::Crontab.Add res.property.app_id, "#{res.property.schedule} #{cmd}"
318
335
  # ExecApp.new(res.property.app_id,
@@ -332,7 +349,17 @@ module OmfRc::ResourceProxy::ScheduledApplication
332
349
  data = IO.read(file,nil,res.property.file_read_offset[file])
333
350
  res.property.file_read_offset[file]+=data.length
334
351
  data.split(/\r?\n/).each do |line|
335
- event_type = (file.include? ".err.log") ? "STDERR" : "STDOUT"
352
+ event_type = "STDOUT"
353
+ if file.include? ".err.log"
354
+ event_type = "STDERR"
355
+ if line.include? "exited with code:"
356
+ if line.split(":").last.to_i == 0
357
+ event_type = "DONE.OK"
358
+ else
359
+ event_type = "DONE.ERROR"
360
+ end
361
+ end
362
+ end
336
363
  res.process_event(res, event_type, res.property.app_id, line)
337
364
  end
338
365
  end
@@ -1,3 +1,3 @@
1
1
  module OmfRcShm
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.1"
3
3
  end
data/omf_rc_shm.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency "bundler", "~> 1.3"
21
21
  spec.add_development_dependency "rake"
22
22
  spec.add_runtime_dependency "omf_rc", "~> 6.0.5"
23
+ spec.add_runtime_dependency "json-jwt"
23
24
  spec.add_runtime_dependency "cronedit"
24
25
  spec.add_runtime_dependency "listen"
25
26
  end
@@ -19,10 +19,11 @@ def run_test(app)
19
19
  end
20
20
 
21
21
  # Configure the 'binary_path' and 'parameters' properties of the App Proxy
22
- app.configure(binary_path: "date",
22
+ app.configure(binary_path: "sleep 5",
23
23
  oml_configfile: "/Users/cdw/tempo/omf_rc_shm/README.md",
24
+ timeout: 3,
24
25
  # use_oml: true,
25
- schedule: "* * * * *")
26
+ schedule: "now")
26
27
 
27
28
  # Start the application 2 seconds later
28
29
  OmfCommon.eventloop.after 1 do
@@ -30,7 +31,7 @@ def run_test(app)
30
31
  end
31
32
 
32
33
  # Stop the application another 10 seconds later
33
- OmfCommon.eventloop.after 120 do
34
+ OmfCommon.eventloop.after 200 do
34
35
  app.configure(state: :unscheduled)
35
36
  end
36
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omf_rc_shm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - NICTA
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 6.0.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: json-jwt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: cronedit
57
71
  requirement: !ruby/object:Gem::Requirement