win32-taskscheduler 0.2.0 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/win32-taskscheduler.rb +1 -0
- data/lib/win32/taskscheduler.rb +1434 -1677
- data/lib/win32/taskscheduler/constants.rb +266 -0
- data/lib/win32/taskscheduler/helper.rb +51 -0
- data/lib/win32/taskscheduler/sid.rb +132 -0
- data/lib/win32/taskscheduler/time_calc_helper.rb +163 -0
- data/lib/win32/taskscheduler/version.rb +6 -0
- metadata +91 -48
- data/CHANGES +0 -51
- data/MANIFEST +0 -11
- data/README +0 -68
- data/Rakefile +0 -54
- data/doc/taskscheduler.txt +0 -419
- data/examples/taskscheduler_example.rb +0 -56
- data/test/test_taskscheduler.rb +0 -524
- data/win32-taskscheduler.gemspec +0 -36
@@ -0,0 +1,163 @@
|
|
1
|
+
module Win32
|
2
|
+
class TaskScheduler
|
3
|
+
module TimeCalcHelper
|
4
|
+
|
5
|
+
# No of days in given month. Deliberately placed 0 in the
|
6
|
+
# beginning to avoid any miscalculations
|
7
|
+
#
|
8
|
+
DAYS_IN_A_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].freeze
|
9
|
+
|
10
|
+
# No of days in a month for given year
|
11
|
+
#
|
12
|
+
# @param [Integer] month
|
13
|
+
# @param [Integer] year
|
14
|
+
# @return [Integer] No of days
|
15
|
+
#
|
16
|
+
def days_in_month(month, year)
|
17
|
+
month == 2 && is_leap_year?(year) ? 29 : DAYS_IN_A_MONTH[month]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Checks weather the given year is a leap year or not
|
21
|
+
#
|
22
|
+
# @param [Integer] year
|
23
|
+
# @return [Boolean]
|
24
|
+
#
|
25
|
+
def is_leap_year?(year)
|
26
|
+
(((year % 4).zero? && !(year % 100).zero?) || (year % 400).zero?)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Calculates the total minutes within given PTM format time
|
30
|
+
#
|
31
|
+
# @param [Integer] time_str
|
32
|
+
# @return [Integer] Time duration in minutes
|
33
|
+
#
|
34
|
+
def time_in_minutes(time_str)
|
35
|
+
time_in_seconds(time_str) / 60
|
36
|
+
end
|
37
|
+
|
38
|
+
# Calculates the total seconds within given PTM format time
|
39
|
+
#
|
40
|
+
# @param [Integer] time_str the time in PTM format
|
41
|
+
# @return [Integer] Time duration in seconds
|
42
|
+
#
|
43
|
+
def time_in_seconds(time_str)
|
44
|
+
dt_tm_hash = time_details(time_str)
|
45
|
+
curr_time = Time.now
|
46
|
+
|
47
|
+
# Basic time variables
|
48
|
+
future_year = curr_time.year + dt_tm_hash[:year].to_i
|
49
|
+
future_month = curr_time.month + dt_tm_hash[:month].to_i
|
50
|
+
future_day = curr_time.day + dt_tm_hash[:day].to_i
|
51
|
+
future_hr = curr_time.hour + dt_tm_hash[:hour].to_i
|
52
|
+
future_min = curr_time.min + dt_tm_hash[:min].to_i
|
53
|
+
future_sec = curr_time.sec + dt_tm_hash[:sec].to_i
|
54
|
+
|
55
|
+
# 'extra value' calculations for these time variables
|
56
|
+
future_sec, future_min = extra_time(future_sec, future_min, 60)
|
57
|
+
future_min, future_hr = extra_time(future_min, future_hr, 60)
|
58
|
+
future_hr, future_day = extra_time(future_hr, future_day, 24)
|
59
|
+
|
60
|
+
# explicit method to calculate overloaded days;
|
61
|
+
# They may stretch upto years; heance leap year & months are into consideration
|
62
|
+
future_day, future_month, future_year = extra_days(future_day, future_month, future_year, curr_time.month, curr_time.year)
|
63
|
+
|
64
|
+
future_month, future_year = extra_months(future_month, future_year, curr_time.month, curr_time.year)
|
65
|
+
|
66
|
+
future_time = Time.new(future_year, future_month, future_day, future_hr, future_min, future_sec)
|
67
|
+
|
68
|
+
# Difference in time will return seconds
|
69
|
+
future_time.to_i - curr_time.to_i
|
70
|
+
end
|
71
|
+
|
72
|
+
# Adjusts the overlapping seconds and returns actual minutes and seconds
|
73
|
+
#
|
74
|
+
# @example
|
75
|
+
# extra_time(65, 2, 60) #=> => [5, 3]
|
76
|
+
#
|
77
|
+
def extra_time(low_rank, high_rank, div_val)
|
78
|
+
a, b = low_rank.divmod(div_val)
|
79
|
+
high_rank += a; low_rank = b
|
80
|
+
[low_rank, high_rank]
|
81
|
+
end
|
82
|
+
|
83
|
+
# Adjusts the overlapping months and returns actual month and year
|
84
|
+
#
|
85
|
+
def extra_months(month_count, year_count, _init_month, _init_year)
|
86
|
+
year, month_count = month_count.divmod(12)
|
87
|
+
if year.positive? && month_count.zero?
|
88
|
+
month_count = 12
|
89
|
+
year -= 1
|
90
|
+
end
|
91
|
+
year_count += year
|
92
|
+
[month_count, year_count]
|
93
|
+
end
|
94
|
+
|
95
|
+
# Adjusts the overlapping years and months and returns actual days, month and year
|
96
|
+
#
|
97
|
+
def extra_days(days_count, month_count, year_count, init_month, init_year)
|
98
|
+
# Will keep increamenting them with surplus days
|
99
|
+
days = days_count
|
100
|
+
mth = init_month
|
101
|
+
yr = init_year
|
102
|
+
|
103
|
+
loop do
|
104
|
+
days -= days_in_month(mth, yr)
|
105
|
+
break if days <= 0
|
106
|
+
mth += 1
|
107
|
+
if mth > 12
|
108
|
+
mth = 1; yr += 1
|
109
|
+
end
|
110
|
+
days_count = days
|
111
|
+
end
|
112
|
+
|
113
|
+
# Setting actual incremented values
|
114
|
+
month_count += (mth - init_month)
|
115
|
+
year_count += (yr - init_year)
|
116
|
+
|
117
|
+
[days_count, month_count, year_count]
|
118
|
+
end
|
119
|
+
|
120
|
+
# Extracts a hash out of given PTM formatted time
|
121
|
+
#
|
122
|
+
# @param [String] time_str
|
123
|
+
# @return [Hash<:year, :month, :day, :hour, :min, :sec>] With their values in Integer
|
124
|
+
#
|
125
|
+
# @example
|
126
|
+
# time_details("PT3S") #=> {sec: 3}
|
127
|
+
#
|
128
|
+
def time_details(time_str)
|
129
|
+
tm_detail = {}
|
130
|
+
if time_str.to_s != ""
|
131
|
+
# time_str will be like "PxxYxxMxxDTxxHxxMxxS"
|
132
|
+
# Ignoring 'P' and extracting date and time
|
133
|
+
dt, tm = time_str[1..-1].split("T")
|
134
|
+
|
135
|
+
# Replacing strings
|
136
|
+
if dt.to_s != ""
|
137
|
+
dt["Y"] = "year" if dt["Y"]; dt["M"] = "month" if dt["M"]; dt["D"] = "day" if dt["D"]
|
138
|
+
dt_tm_string_to_hash(dt, tm_detail)
|
139
|
+
end
|
140
|
+
|
141
|
+
if tm.to_s != ""
|
142
|
+
tm["H"] = "hour" if tm["H"]; tm["M"] = "min" if tm["M"]; tm["S"] = "sec" if tm["S"]
|
143
|
+
dt_tm_string_to_hash(tm, tm_detail)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
tm_detail
|
147
|
+
end
|
148
|
+
|
149
|
+
# Converts the given date/time string to the hash
|
150
|
+
#
|
151
|
+
# @param [String] str
|
152
|
+
# @param [Hash] tm_detail May be loaded
|
153
|
+
# @return [Hash]
|
154
|
+
#
|
155
|
+
# @example
|
156
|
+
# dt_tm_string_to_hash("10year3month", {}) #=> {:year=>"10", :month=>"3"}
|
157
|
+
#
|
158
|
+
def dt_tm_string_to_hash(str, tm_detail)
|
159
|
+
str.split(/(\d+)/)[1..-1].each_slice(2).each_with_object(tm_detail) { |i, h| h[i.last.to_sym] = i.first; }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
metadata
CHANGED
@@ -1,67 +1,110 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-taskscheduler
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Park Heesob
|
8
8
|
- Daniel J. Berger
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
date: 2019-01-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ffi
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: structured_warnings
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: test-unit
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: win32-security
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: |2
|
71
|
+
The win32-taskscheduler library provides an interface to the MS Windows
|
72
|
+
Task Scheduler. With this interface you can create new scheduled tasks,
|
73
|
+
configure existing tasks, or delete tasks.
|
18
74
|
email: djberg96@gmail.com
|
19
75
|
executables: []
|
20
|
-
|
21
76
|
extensions: []
|
22
|
-
|
23
|
-
|
24
|
-
-
|
25
|
-
- CHANGES
|
26
|
-
- MANIFEST
|
27
|
-
- doc/taskscheduler.txt
|
28
|
-
files:
|
29
|
-
- CHANGES
|
30
|
-
- doc/taskscheduler.txt
|
31
|
-
- examples/taskscheduler_example.rb
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- lib/win32-taskscheduler.rb
|
32
80
|
- lib/win32/taskscheduler.rb
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
- win32
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
81
|
+
- lib/win32/taskscheduler/constants.rb
|
82
|
+
- lib/win32/taskscheduler/helper.rb
|
83
|
+
- lib/win32/taskscheduler/sid.rb
|
84
|
+
- lib/win32/taskscheduler/time_calc_helper.rb
|
85
|
+
- lib/win32/taskscheduler/version.rb
|
86
|
+
homepage: https://github.com/chef/win32-taskscheduler
|
87
|
+
licenses:
|
88
|
+
- Artistic-2.0
|
89
|
+
metadata: {}
|
42
90
|
post_install_message:
|
43
91
|
rdoc_options: []
|
44
|
-
|
45
|
-
require_paths:
|
92
|
+
require_paths:
|
46
93
|
- lib
|
47
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
-
requirements:
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
49
96
|
- - ">="
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
version:
|
52
|
-
|
53
|
-
|
54
|
-
requirements:
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
55
101
|
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
58
|
-
version:
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
59
104
|
requirements: []
|
60
|
-
|
61
|
-
|
62
|
-
rubygems_version: 1.3.4
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.7.6
|
63
107
|
signing_key:
|
64
|
-
specification_version:
|
108
|
+
specification_version: 4
|
65
109
|
summary: A library for the Windows task scheduler
|
66
|
-
test_files:
|
67
|
-
- test/test_taskscheduler.rb
|
110
|
+
test_files: []
|
data/CHANGES
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
== 0.2.0 - 19-Jun-2009
|
2
|
-
* Rewritten in pure Ruby!
|
3
|
-
* The TaskScheduler::ONCE constant is now a valid trigger type. Thanks go to
|
4
|
-
Uri Iurgel for the spot and patch.
|
5
|
-
* Added the TaskScheduler#exists? method.
|
6
|
-
* Added the TaskScheduler#tasks alias for the TaskScheduler#enum method.
|
7
|
-
* The TaskScheduler#new_work_item method now accepts symbols as well as
|
8
|
-
strings for hash keys, and ignores case. Also, the keys are now validated.
|
9
|
-
* Renamed the example file and test file.
|
10
|
-
* Added the 'example' Rake task.
|
11
|
-
* Fixed some code in the README synopsis that was incorrect.
|
12
|
-
|
13
|
-
== 0.1.0 - 11-May-2008
|
14
|
-
* The TaskScheduler#save instance method now accepts an optional file name.
|
15
|
-
* Most of the TaskScheduler setter methods now return the value specified
|
16
|
-
instead of true.
|
17
|
-
* Removed the RUN_ONLY_IF_DOCKED and RUN_IF_CONNECTED_TO_INTERNET constants.
|
18
|
-
The MSDN docs say that they are unused.
|
19
|
-
* Added more documentation. Much more rdoc friendly now.
|
20
|
-
* Added many more tests.
|
21
|
-
* Better type handling for bad arguments.
|
22
|
-
* Added a Rakefile with tasks for building, installation and testing.
|
23
|
-
* Added a gemspec.
|
24
|
-
* Inlined the rdoc documentation.
|
25
|
-
* Internal project reorganization and code cleanup.
|
26
|
-
|
27
|
-
== 0.0.3 - 1-Mar-2005
|
28
|
-
* Bug fix for the bitFieldToHumanDays() internal function.
|
29
|
-
* Moved the 'examples' directory to the toplevel directory.
|
30
|
-
* Made the CHANGES and README files rdoc friendly.
|
31
|
-
* Minor updates to taskscheduler.h.
|
32
|
-
|
33
|
-
== 0.0.2 - 04-Aug-2004
|
34
|
-
* Now uses the newer allocation framework and replaced all instances of the
|
35
|
-
deprecated STR2CSTR() function with StringValuePtr(). This means that, as
|
36
|
-
of this release, Ruby 1.8.0 or later is required.
|
37
|
-
* Modified the constructor to accept arguments. This is just some sugar for
|
38
|
-
creating a new task item in one call instead of two.
|
39
|
-
* The argument to trigger= now must be a hash. The same goes for the 'type'
|
40
|
-
sub-hash.
|
41
|
-
* Added the add_trigger() method. Actually, the C code for this method was
|
42
|
-
already in place, I simply forgot to create a corresponding Ruby method
|
43
|
-
for it.
|
44
|
-
* Removed the create_trigger() method. This was really nothing more than an
|
45
|
-
alias for trigger=(). I got confused somehow.
|
46
|
-
* Test suite modified and many more tests added.
|
47
|
-
* Documentation updates, including docs for a couple of methods that I had
|
48
|
-
accidentally omitted previously.
|
49
|
-
|
50
|
-
== 0.0.1 - 24-Apr-2004
|
51
|
-
* Initial release
|
data/MANIFEST
DELETED
data/README
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
= Description
|
2
|
-
The win32-taskscheduler library is a Ruby interface to the MS Windows Task
|
3
|
-
Scheduler. It is analogous to the Unix cron daemon.
|
4
|
-
|
5
|
-
= Synopsis
|
6
|
-
require 'win32/taskscheduler'
|
7
|
-
include Win32
|
8
|
-
|
9
|
-
ts = TaskScheduler.new
|
10
|
-
|
11
|
-
# Create a trigger that starts on April 25, 2014 at 11:05 pm. The trigger
|
12
|
-
# will run on the first and last week of the month, on Monday and Friday,
|
13
|
-
# in the months of April and May.
|
14
|
-
#
|
15
|
-
trigger = {
|
16
|
-
:start_year => 2014,
|
17
|
-
:start_month => 4,
|
18
|
-
:start_day => 25,
|
19
|
-
:start_hour => 23,
|
20
|
-
:start_minute => 5,
|
21
|
-
:trigger_type => TaskScheduler::MONTHLYDOW,
|
22
|
-
:type => {
|
23
|
-
:weeks => TaskScheduler::FIRST_WEEK | TaskScheduler::LAST_WEEK,
|
24
|
-
:days_of_week => TaskScheduler::MONDAY | TaskScheduler::FRIDAY,
|
25
|
-
:months => TaskScheduler::APRIL | TaskScheduler::MAY
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
ts.new_work_item('foo', trigger)
|
30
|
-
ts.application_name = 'notepad.exe'
|
31
|
-
ts.save
|
32
|
-
|
33
|
-
= Prerequisites
|
34
|
-
Ruby 1.8.2 or later.
|
35
|
-
Building from source requires VC++ 6.0 or later.
|
36
|
-
Windows XP or earlier. Vista and later not currently supported.
|
37
|
-
|
38
|
-
= Installation
|
39
|
-
rake install (non-gem) OR rake install_gem (gem)
|
40
|
-
|
41
|
-
For most of you 'gem install win32-taskscheduler' will work.
|
42
|
-
|
43
|
-
= Documentation
|
44
|
-
If you installed this library as a gem then the documentation was built for
|
45
|
-
you and can be viewed if your gem server is running.
|
46
|
-
|
47
|
-
Otherwise, you can look at the doc/taskscheduler.txt file which should have
|
48
|
-
everything you need.
|
49
|
-
|
50
|
-
= Acknowledgements
|
51
|
-
This library was modeled to some degree on the Win32::TaskScheduler Perl
|
52
|
-
module by Umberto Nicoletti. However, there are some differences. Please see
|
53
|
-
the documentation for details.
|
54
|
-
|
55
|
-
= On using OLE + WMI + Win32_ScheduledJob
|
56
|
-
I will probably include a pure Ruby version of this library at some point,
|
57
|
-
and you can find what I have so far in CVS under lib/win32. Note, however,
|
58
|
-
that there are some significant differences in behavior between the C
|
59
|
-
library and WMI, along with limitations regarding modification to existing
|
60
|
-
tasks.
|
61
|
-
|
62
|
-
You can find a list of differences here: http://tinyurl.com/2l3yau
|
63
|
-
|
64
|
-
= Developer's Notes
|
65
|
-
The CoInitialize() function is used internally instead of CoInitializeEx()
|
66
|
-
function intentionally. The CoInitialize() function merely calls the
|
67
|
-
CoInitializeEx() function with NULL and COINIT_APARTMENTTHREADED arguments,
|
68
|
-
which is what we would do in any case.
|