task_scheduler 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +27 -0
- data/lib/task_runner.bat +21 -0
- data/lib/task_scheduler.rb +5 -0
- data/lib/task_scheduler/scheduler.rb +33 -0
- data/lib/task_scheduler/version.rb +3 -0
- data/lib/task_scheduler/windows_scheduler.rb +67 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5667540718eb766101b3c4e9bfc1257fb7247585
|
4
|
+
data.tar.gz: efe74860457dfdc5892855bb280be7a15f30ea2e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97c228d282e5ea77e29c897004c03245522022812868bbec7a51252cbf84284d5726ad4c7463482382c5795c4465b99265d7d75f1f71d3f469760330109e5a9e
|
7
|
+
data.tar.gz: 808d9688f615c4a6baba02304cdd38cb13182c4ef1079d5114f59b409bb92d0dbaff2e91378426de2fbcef94a852763ce8263c89d5544d2f4b86f4ccb65dba85
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 SecZetta
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# TaskScheduler
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'task_scheduler'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install task_scheduler
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'TaskScheduler'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task default: :test
|
data/lib/task_runner.bat
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
@echo off
|
2
|
+
|
3
|
+
set RESTVAR=
|
4
|
+
shift
|
5
|
+
:loop1
|
6
|
+
if "%1"=="" goto after_loop
|
7
|
+
set RESTVAR=%RESTVAR% %1=%2
|
8
|
+
shift
|
9
|
+
shift
|
10
|
+
goto loop1
|
11
|
+
|
12
|
+
:after_loop
|
13
|
+
echo %RESTVAR%
|
14
|
+
|
15
|
+
|
16
|
+
REM params have to be separated by a single space
|
17
|
+
set "param1=%~1"
|
18
|
+
set "param2=%~2"
|
19
|
+
|
20
|
+
cd %param1%
|
21
|
+
jruby -S bundle exec rake scheduled_task:start_ldap_auto_sync %RESTVAR%
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module TaskScheduler
|
2
|
+
module Scheduler
|
3
|
+
TIMEFRAMES = %w[hours days months].freeze
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
after_save :update_scheduled_task, if: 'OS.windows?'
|
8
|
+
after_create :create_scheduled_task, if: 'OS.windows?'
|
9
|
+
|
10
|
+
validates_presence_of :scheduler, :task_name, :rake_task_name, :import_at,
|
11
|
+
:import_time, :repeat_time, :repeat_type
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def create_scheduled_task
|
18
|
+
process_name = 'directory_auto_sync_scheduler.bat'
|
19
|
+
|
20
|
+
scheduler = WindowsScheduler.new(task_name, process_name)
|
21
|
+
task = scheduler.create_task(import_at, repeat_type, repeat_time, bat_params)
|
22
|
+
task.run
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_scheduled_task
|
26
|
+
process_name = 'directory_auto_sync_scheduler.bat'
|
27
|
+
|
28
|
+
scheduler = WindowsScheduler.new(task_name, process_name)
|
29
|
+
task = scheduler.update_task(import_at, repeat_type, repeat_time, bat_params)
|
30
|
+
task.run
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module TaskScheduler
|
2
|
+
class WindowsScheduler
|
3
|
+
attr_reader :task_name, :rake_task, :import_at, :repeat_type, :repeat_time
|
4
|
+
|
5
|
+
def initialize(task_name, rake_task)
|
6
|
+
@task_name = task_name
|
7
|
+
@rake_task = rake_task
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_task(system_ip = nil)
|
11
|
+
io = StringIO.new
|
12
|
+
io << 'SchTasks /Run '
|
13
|
+
io << "/S #{system_ip} " if system_ip # run a task on a different system
|
14
|
+
io << "/TN '#{task_name}' "
|
15
|
+
io
|
16
|
+
end
|
17
|
+
|
18
|
+
# creates a windows scheduled task via command line
|
19
|
+
#
|
20
|
+
def create_task(import_at, repeat_type, repeat_time, bat_params = nil)
|
21
|
+
io = StringIO.new
|
22
|
+
io << 'SchTasks /Create '
|
23
|
+
if repeat_type && repeat_time
|
24
|
+
io << "/SC #{repeat_type} " # schedule frequency
|
25
|
+
io << "/MO #{repeat_time} " # time between runs
|
26
|
+
end
|
27
|
+
io << "/TN '#{task_name}' " # name of the task
|
28
|
+
io << "/TR '#{build_bat_params(bat_params)}' " # what to execute when task runs
|
29
|
+
io << "/ST '#{import_at}'" if import_at # start time
|
30
|
+
io
|
31
|
+
end
|
32
|
+
|
33
|
+
# updates a windows scheuled task via the command line
|
34
|
+
#
|
35
|
+
def update_task(import_at, repeat_type, repeat_time, bat_params = nil)
|
36
|
+
delete_task&.run
|
37
|
+
create_task(import_at, repeat_type, repeat_time, bat_params)
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_task
|
41
|
+
io = StringIO.new
|
42
|
+
io << "SchTasks /Delete /TN '#{task_name}' /F"
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def build_bat_params(bat_params)
|
48
|
+
io = StringIO.new
|
49
|
+
io << "#{File.join(File.dirname(__FILE__), 'task_runner.bat')} "
|
50
|
+
|
51
|
+
return io.string unless bat_params
|
52
|
+
|
53
|
+
io << "#{Rails.root} " # first param so the bat file knows where to cd into
|
54
|
+
bat_params.each do |_param_name, value|
|
55
|
+
io << "#{value} "
|
56
|
+
end
|
57
|
+
io.string
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class StringIO
|
63
|
+
# I built this method because I couldn't test with the system method in the create_task method
|
64
|
+
def run
|
65
|
+
system(string)
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: task_scheduler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Corey Votta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '4.2'
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.2.0
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.2.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - "~>"
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
name: os
|
40
|
+
prerelease: false
|
41
|
+
type: :runtime
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: Uses system commands to create scheduled tasks in a windows envoirment.
|
48
|
+
email:
|
49
|
+
- cvotta@seczetta.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- MIT-LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/task_runner.bat
|
58
|
+
- lib/task_scheduler.rb
|
59
|
+
- lib/task_scheduler/scheduler.rb
|
60
|
+
- lib/task_scheduler/version.rb
|
61
|
+
- lib/task_scheduler/windows_scheduler.rb
|
62
|
+
homepage:
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.6.8
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Creates scheduled tasks via the windows task scheduler
|
86
|
+
test_files: []
|