pid-watcher 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9b3dc9e29d83b17a681f70f903068a8f675addf
4
- data.tar.gz: ceb1e38781387cc972a39c0bd7b6ec2725d9f269
3
+ metadata.gz: 587fbb3588f3b811ebd155c86883dba3f9acfd2b
4
+ data.tar.gz: 5a0fa11317f7a1ad94fd90a0b6a45197efd08e1a
5
5
  SHA512:
6
- metadata.gz: a82cfd62efe94f8d81104cdf6fd71214e998bb515aec062a9096ab7ea85c81e33e5e767aed7f77b6b3f697fb36e5abdbd2944907399c8a35c0ea73e06a80bf2f
7
- data.tar.gz: 9ca6a0e60cfc09ca16af788e2912e73dfff4f33001600f0b40da9172f18e5feb930d480bf2038ffa76347fc0eb3c077672f20215c5138bf6336d2e24d290f668
6
+ metadata.gz: db8cd63fb4420751531688eb3dda3baf3ad3e1833f7580fa95ab7dc6a9068d9fdb21351a65051e5690dba8c1e69716d005bc3418d76cfa39b53d2c3fd6e42048
7
+ data.tar.gz: 5c9259be5b41437bb7d5a4c7d0217411b4455cf3ded07550eba024adc99acc7d70eba1053aa7e564606b0214b4fc040447f965ac8b4409e56fd502eae3618d74
data/README.md CHANGED
@@ -1,13 +1,25 @@
1
- # Pid::Watcher
1
+ # Pid Watcher
2
2
 
3
3
  This program will allow you to observe the process, and when the process is complete, you will be notified.
4
4
 
5
5
  ## Installation
6
6
  gem install pid-watcher
7
7
 
8
+ ## Supported platform
9
+ Only Mac OS version >= 10.8
10
+
8
11
  ## Usage
12
+ $ pid-watcher -h
13
+ Usage: pid-watcher PID [options]
14
+ -m, --message MESSAGE Message for Notification Center (default: Process %{pid} finished)
15
+ -t, --timeout TIMEOUT Timeout in seconds for process (default: 600)
16
+ -v Show version
17
+
18
+ ## Example
19
+ $ cd /rails/app/ && bundle
20
+ $ ps ax | grep bundle
21
+ 58537 s002 R+ 0:01.31 /Users/10525/.rbenv/versions/2.0.0-p353/bin/ruby /Users/10525/.rbenv/versions/2.0.0-p353/bin/bundle
22
+ $ pid-watcher 58537
23
+ On completion
9
24
 
10
- Usage: pid-watcher PID [options]
11
- -m, --message MESSAGE Message for Notification Center (default: Process %{pid} finished)
12
- -t, --timeout TIMEOUT Timeout in seconds for process (default: 600)
13
- -v Show version
25
+ ![Image](screenshot.png?raw=true)
@@ -19,6 +19,10 @@ option_parser = OptionParser.new do |opts|
19
19
  options[:timeout] = v
20
20
  end
21
21
 
22
+ opts.on("-c", "--command COMMAND", String, "Run something command after the completion ") do |v|
23
+ options[:command] = v
24
+ end
25
+
22
26
  opts.on_tail("-v", "Show version") do
23
27
  puts PidWatcher::VERSION
24
28
  exit
@@ -33,5 +37,5 @@ unless ARGV.first.to_s.match(/^\d+$/)
33
37
  end
34
38
 
35
39
  pid = ARGV.first.to_i
36
- pid_watcher = PidWatcher.new(pid, options[:message], options[:timeout])
40
+ pid_watcher = PidWatcher.new(pid, options)
37
41
  pid_watcher.watch
@@ -2,25 +2,27 @@ require 'terminal-notifier'
2
2
  require 'timeout'
3
3
 
4
4
  class PidWatcher
5
- VERSION = "0.0.1"
5
+ VERSION = "0.0.2"
6
6
  DEFAULT_TIMEOUT = 10 * 60
7
7
  DEFAULT_MESSAGE = "Process %{pid} finished"
8
8
  TIMEOUT_MESSAGE = "Timeout for process %{pid}"
9
9
  TITLE = 'Pid Watcher'
10
10
 
11
- def initialize(pid, message = nil, timeout = nil)
11
+ def initialize(pid, options)
12
12
  @pid = pid
13
- @message = message || DEFAULT_MESSAGE
14
- @timeout = timeout || DEFAULT_TIMEOUT
13
+ @message = options[:message] || DEFAULT_MESSAGE
14
+ @timeout = options[:timeout] || DEFAULT_TIMEOUT
15
+ @command = options[:command]
15
16
  end
16
17
 
17
18
  def watch
18
- Process.daemon(nil, true)
19
+ Process.daemon
19
20
 
20
21
  Timeout::timeout(timeout) do
21
22
  while pid_exists?
22
23
  sleep(1)
23
24
  end
25
+ run_command unless command.nil?
24
26
  finish_notify
25
27
  end
26
28
  rescue Timeout::Error
@@ -29,14 +31,23 @@ class PidWatcher
29
31
 
30
32
  private
31
33
 
34
+ def run_command
35
+ Process.spawn(command)
36
+ rescue
37
+ true
38
+ end
39
+
32
40
  def pid_exists?
33
41
  status = Process.kill(0, pid) rescue false
34
42
  !!status
35
43
  end
36
44
 
37
45
  def finish_notify
46
+ prepared_msg = message % { :pid => pid }
47
+ prepared_msg += " and '#{command}' was running in background" unless command.nil?
48
+
38
49
  TerminalNotifier.notify(
39
- message % { :pid => pid },
50
+ prepared_msg,
40
51
  :title => TITLE,
41
52
  :subtitle => 'Finished'
42
53
  )
@@ -50,5 +61,5 @@ class PidWatcher
50
61
  )
51
62
  end
52
63
 
53
- attr_reader :pid, :message, :timeout
64
+ attr_reader :pid, :message, :timeout, :command
54
65
  end
Binary file
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pid-watcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - vad4msiu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-10 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: terminal-notifier
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Watcher for process
@@ -60,15 +60,15 @@ executables:
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
63
+ - ".gitignore"
64
64
  - Gemfile
65
65
  - LICENSE.txt
66
66
  - README.md
67
67
  - Rakefile
68
68
  - bin/pid-watcher
69
69
  - lib/pid_watcher.rb
70
- - lib/pid_watcher/version.rb
71
70
  - pid-watcher.gemspec
71
+ - screenshot.png
72
72
  homepage: ''
73
73
  licenses:
74
74
  - MIT
@@ -79,19 +79,18 @@ require_paths:
79
79
  - lib
80
80
  required_ruby_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - '>='
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
91
  rubyforge_project:
92
- rubygems_version: 2.0.14
92
+ rubygems_version: 2.2.2
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: Watcher for process
96
96
  test_files: []
97
- has_rdoc:
@@ -1,3 +0,0 @@
1
- class PidWatcher
2
- VERSION = "0.0.1"
3
- end