pid-watcher 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +13 -0
- data/Rakefile +1 -0
- data/bin/pid-watcher +37 -0
- data/lib/pid_watcher/version.rb +3 -0
- data/lib/pid_watcher.rb +54 -0
- data/pid-watcher.gemspec +26 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f9b3dc9e29d83b17a681f70f903068a8f675addf
|
4
|
+
data.tar.gz: ceb1e38781387cc972a39c0bd7b6ec2725d9f269
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a82cfd62efe94f8d81104cdf6fd71214e998bb515aec062a9096ab7ea85c81e33e5e767aed7f77b6b3f697fb36e5abdbd2944907399c8a35c0ea73e06a80bf2f
|
7
|
+
data.tar.gz: 9ca6a0e60cfc09ca16af788e2912e73dfff4f33001600f0b40da9172f18e5feb930d480bf2038ffa76347fc0eb3c077672f20215c5138bf6336d2e24d290f668
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 vad4msiu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Pid::Watcher
|
2
|
+
|
3
|
+
This program will allow you to observe the process, and when the process is complete, you will be notified.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
gem install pid-watcher
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
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
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/pid-watcher
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path('../../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'optparse'
|
7
|
+
require 'pid_watcher'
|
8
|
+
|
9
|
+
options = {}
|
10
|
+
|
11
|
+
option_parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: pid-watcher PID [options]"
|
13
|
+
|
14
|
+
opts.on("-m", "--message MESSAGE", String, "Message for Notification Center (default: #{PidWatcher::DEFAULT_MESSAGE})") do |v|
|
15
|
+
options[:message] = v
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on("-t", "--timeout TIMEOUT", Integer, "Timeout in seconds for process (default: #{PidWatcher::DEFAULT_TIMEOUT})") do |v|
|
19
|
+
options[:timeout] = v
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on_tail("-v", "Show version") do
|
23
|
+
puts PidWatcher::VERSION
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
option_parser.parse!
|
29
|
+
|
30
|
+
unless ARGV.first.to_s.match(/^\d+$/)
|
31
|
+
puts option_parser.help
|
32
|
+
exit(1)
|
33
|
+
end
|
34
|
+
|
35
|
+
pid = ARGV.first.to_i
|
36
|
+
pid_watcher = PidWatcher.new(pid, options[:message], options[:timeout])
|
37
|
+
pid_watcher.watch
|
data/lib/pid_watcher.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'terminal-notifier'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
class PidWatcher
|
5
|
+
VERSION = "0.0.1"
|
6
|
+
DEFAULT_TIMEOUT = 10 * 60
|
7
|
+
DEFAULT_MESSAGE = "Process %{pid} finished"
|
8
|
+
TIMEOUT_MESSAGE = "Timeout for process %{pid}"
|
9
|
+
TITLE = 'Pid Watcher'
|
10
|
+
|
11
|
+
def initialize(pid, message = nil, timeout = nil)
|
12
|
+
@pid = pid
|
13
|
+
@message = message || DEFAULT_MESSAGE
|
14
|
+
@timeout = timeout || DEFAULT_TIMEOUT
|
15
|
+
end
|
16
|
+
|
17
|
+
def watch
|
18
|
+
Process.daemon(nil, true)
|
19
|
+
|
20
|
+
Timeout::timeout(timeout) do
|
21
|
+
while pid_exists?
|
22
|
+
sleep(1)
|
23
|
+
end
|
24
|
+
finish_notify
|
25
|
+
end
|
26
|
+
rescue Timeout::Error
|
27
|
+
timeout_notify
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def pid_exists?
|
33
|
+
status = Process.kill(0, pid) rescue false
|
34
|
+
!!status
|
35
|
+
end
|
36
|
+
|
37
|
+
def finish_notify
|
38
|
+
TerminalNotifier.notify(
|
39
|
+
message % { :pid => pid },
|
40
|
+
:title => TITLE,
|
41
|
+
:subtitle => 'Finished'
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def timeout_notify
|
46
|
+
TerminalNotifier.notify(
|
47
|
+
TIMEOUT_MESSAGE % { :pid => pid },
|
48
|
+
:title => TITLE,
|
49
|
+
:subtitle => 'Timeout'
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
attr_reader :pid, :message, :timeout
|
54
|
+
end
|
data/pid-watcher.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pid_watcher'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pid-watcher"
|
8
|
+
spec.version = PidWatcher::VERSION
|
9
|
+
spec.authors = ["vad4msiu"]
|
10
|
+
spec.email = ["vad4msiu@gmail.com"]
|
11
|
+
spec.description = %q{Watcher for process}
|
12
|
+
spec.summary = %q{Watcher for process}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.executables << 'pid-watcher'
|
21
|
+
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_dependency 'terminal-notifier'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pid-watcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- vad4msiu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: terminal-notifier
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Watcher for process
|
56
|
+
email:
|
57
|
+
- vad4msiu@gmail.com
|
58
|
+
executables:
|
59
|
+
- pid-watcher
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/pid-watcher
|
69
|
+
- lib/pid_watcher.rb
|
70
|
+
- lib/pid_watcher/version.rb
|
71
|
+
- pid-watcher.gemspec
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.14
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Watcher for process
|
96
|
+
test_files: []
|
97
|
+
has_rdoc:
|