win32-job 0.1.1 → 0.1.2
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 +4 -4
- data/CHANGES +6 -0
- data/lib/win32/job.rb +22 -6
- data/lib/win32/job/constants.rb +1 -0
- data/test/test_win32_job.rb +10 -1
- data/win32-job.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c046b91579b8ce36811d85d9dcf691e2c3ff555
|
4
|
+
data.tar.gz: 4e65f2fe4f2ded16f6a43c0cf672bab7fa5da91c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73df699846e40e26e1bcaebcae9adc5301d2da6a336aafec73f08907a225955751c858098447601aad3f0bbd8967d2cb942bb149ec693da6953f2857c382644f
|
7
|
+
data.tar.gz: fad7d536c6fc5b1a3ca3f9326b5386c7ca54407b1f0d399a37f0f115e276e6b419dbada1f9d1dba71a588cf8c6c40aac6284b83596b576b598f6d8860df466ea
|
data/CHANGES
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
= 0.1.2 - 6-Feb-2014
|
2
|
+
* Altered the constructor. The second argument now controls whether or not
|
3
|
+
to raise an error if the job already exists. By default it will open the job
|
4
|
+
if it already exists.
|
5
|
+
* Fixed a bug in the process_list method where it could return incorrect values.
|
6
|
+
|
1
7
|
= 0.1.1 - 5-Feb-2014
|
2
8
|
* Added a wait method.
|
3
9
|
|
data/lib/win32/job.rb
CHANGED
@@ -14,7 +14,7 @@ module Win32
|
|
14
14
|
extend Windows::Functions
|
15
15
|
|
16
16
|
# The version of the win32-job library
|
17
|
-
VERSION = '0.1.
|
17
|
+
VERSION = '0.1.2'
|
18
18
|
|
19
19
|
private
|
20
20
|
|
@@ -41,6 +41,7 @@ module Win32
|
|
41
41
|
|
42
42
|
public
|
43
43
|
|
44
|
+
# The name of the job, if specified.
|
44
45
|
attr_reader :job_name
|
45
46
|
|
46
47
|
alias :name :job_name
|
@@ -48,11 +49,14 @@ module Win32
|
|
48
49
|
# Create a new Job object identified by +name+. If no name is provided
|
49
50
|
# then an anonymous job is created.
|
50
51
|
#
|
51
|
-
# If the
|
52
|
-
#
|
53
|
-
#
|
52
|
+
# If the job already exists then the existing job is opened instead, unless
|
53
|
+
# the +open_existing+ method is false. In that case an error is
|
54
|
+
# raised.
|
54
55
|
#
|
55
|
-
|
56
|
+
# The +security+ argument accepts a raw SECURITY_ATTRIBUTES struct that is
|
57
|
+
# passed to the CreateJobObject function internally.
|
58
|
+
#
|
59
|
+
def initialize(name = nil, open_existing = true, security = nil)
|
56
60
|
raise TypeError unless name.is_a?(String) if name
|
57
61
|
|
58
62
|
@job_name = name
|
@@ -65,6 +69,10 @@ module Win32
|
|
65
69
|
FFI.raise_windows_error('CreateJobObject', FFI.errno)
|
66
70
|
end
|
67
71
|
|
72
|
+
if FFI.errno == ERROR_ALREADY_EXISTS && !open_existing
|
73
|
+
raise ArgumentError, "job '#{name}' already exists"
|
74
|
+
end
|
75
|
+
|
68
76
|
if block_given?
|
69
77
|
begin
|
70
78
|
yield self
|
@@ -79,6 +87,12 @@ module Win32
|
|
79
87
|
# Add process +pid+ to the job object. Process ID's added to the
|
80
88
|
# job are tracked via the Job#process_list accessor.
|
81
89
|
#
|
90
|
+
# Note that once a process is added to a job, the association cannot be
|
91
|
+
# broken. A process can be associated with more than one job in a
|
92
|
+
# hierarchy of nested jobs, however.
|
93
|
+
#
|
94
|
+
# You may add a maximum of 100 processes per job.
|
95
|
+
#
|
82
96
|
def add_process(pid)
|
83
97
|
if @process_list.size > 99
|
84
98
|
raise ArgumentError, "maximum number of processes reached"
|
@@ -116,6 +130,8 @@ module Win32
|
|
116
130
|
# Kill all processes associated with the job object that are
|
117
131
|
# associated with the current process.
|
118
132
|
#
|
133
|
+
# Note that killing a process does not dissociate it from the job.
|
134
|
+
#
|
119
135
|
def kill
|
120
136
|
unless TerminateJobObject(@job_handle, Process.pid)
|
121
137
|
FFI.raise_windows_error('TerminateJobObject', FFI.errno)
|
@@ -360,7 +376,7 @@ module Win32
|
|
360
376
|
FFI.raise_windows_error('QueryInformationJobObject', FFI.errno)
|
361
377
|
end
|
362
378
|
|
363
|
-
info[:ProcessIdList].to_a
|
379
|
+
info[:ProcessIdList].to_a[0...info[:NumberOfProcessIdsInList]]
|
364
380
|
end
|
365
381
|
|
366
382
|
# Returns an AccountInfoStruct that shows various job accounting
|
data/lib/win32/job/constants.rb
CHANGED
data/test/test_win32_job.rb
CHANGED
@@ -15,7 +15,7 @@ class TC_Win32_Job < Test::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
test "version number is what we expect" do
|
18
|
-
assert_equal('0.1.
|
18
|
+
assert_equal('0.1.2', Win32::Job::VERSION)
|
19
19
|
end
|
20
20
|
|
21
21
|
test "constructor argument may be omitted" do
|
@@ -26,10 +26,19 @@ class TC_Win32_Job < Test::Unit::TestCase
|
|
26
26
|
assert_nothing_raised{ Win32::Job.new(@name) }
|
27
27
|
end
|
28
28
|
|
29
|
+
test "constructor accepts a second argument" do
|
30
|
+
assert_nothing_raised{ Win32::Job.new(@name, true) }
|
31
|
+
end
|
32
|
+
|
29
33
|
test "argument to constructor must be a string" do
|
30
34
|
assert_raise(TypeError){ Win32::Job.new(1) }
|
31
35
|
end
|
32
36
|
|
37
|
+
test "if second argument to constructor is false, an error is raised if the same job is reopened" do
|
38
|
+
@job = Win32::Job.new('test')
|
39
|
+
assert_raise(ArgumentError){ Win32::Job.new('test', false) }
|
40
|
+
end
|
41
|
+
|
33
42
|
test "job_name basic functionality" do
|
34
43
|
assert_respond_to(@job, :job_name)
|
35
44
|
assert_nothing_raised{ @job.job_name }
|
data/win32-job.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
requirements: []
|
99
99
|
rubyforge_project: win32utils
|
100
|
-
rubygems_version: 2.2.
|
100
|
+
rubygems_version: 2.2.2
|
101
101
|
signing_key:
|
102
102
|
specification_version: 4
|
103
103
|
summary: Interface for Windows jobs (process groups)
|