Class: TaskScheduler::WindowsScheduler
- Inherits:
-
Object
- Object
- TaskScheduler::WindowsScheduler
- Defined in:
- lib/task_scheduler/windows_scheduler.rb
Instance Attribute Summary collapse
-
#import_at ⇒ Object
readonly
Returns the value of attribute import_at.
-
#rake_task ⇒ Object
readonly
Returns the value of attribute rake_task.
-
#repeat_time ⇒ Object
readonly
Returns the value of attribute repeat_time.
-
#repeat_type ⇒ Object
readonly
Returns the value of attribute repeat_type.
-
#task_name ⇒ Object
readonly
Returns the value of attribute task_name.
Instance Method Summary collapse
-
#create_task(import_at, import_time, repeat_type, repeat_time, username, password, bat_params = nil) ⇒ Object
creates a windows scheduled task via command line.
- #delete_task ⇒ Object
-
#initialize(task_name, rake_task) ⇒ WindowsScheduler
constructor
A new instance of WindowsScheduler.
- #run_task(system_ip = nil) ⇒ Object
-
#update_task(import_at, import_time, repeat_type, repeat_time, username, password, bat_params = nil) ⇒ Object
updates a windows scheuled task via the command line.
Constructor Details
#initialize(task_name, rake_task) ⇒ WindowsScheduler
Returns a new instance of WindowsScheduler.
5 6 7 8 |
# File 'lib/task_scheduler/windows_scheduler.rb', line 5 def initialize(task_name, rake_task) @task_name = task_name @rake_task = rake_task end |
Instance Attribute Details
#import_at ⇒ Object (readonly)
Returns the value of attribute import_at.
3 4 5 |
# File 'lib/task_scheduler/windows_scheduler.rb', line 3 def import_at @import_at end |
#rake_task ⇒ Object (readonly)
Returns the value of attribute rake_task.
3 4 5 |
# File 'lib/task_scheduler/windows_scheduler.rb', line 3 def rake_task @rake_task end |
#repeat_time ⇒ Object (readonly)
Returns the value of attribute repeat_time.
3 4 5 |
# File 'lib/task_scheduler/windows_scheduler.rb', line 3 def repeat_time @repeat_time end |
#repeat_type ⇒ Object (readonly)
Returns the value of attribute repeat_type.
3 4 5 |
# File 'lib/task_scheduler/windows_scheduler.rb', line 3 def repeat_type @repeat_type end |
#task_name ⇒ Object (readonly)
Returns the value of attribute task_name.
3 4 5 |
# File 'lib/task_scheduler/windows_scheduler.rb', line 3 def task_name @task_name end |
Instance Method Details
#create_task(import_at, import_time, repeat_type, repeat_time, username, password, bat_params = nil) ⇒ Object
creates a windows scheduled task via command line
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/task_scheduler/windows_scheduler.rb', line 20 def create_task(import_at, import_time, repeat_type, repeat_time, username, password, bat_params = nil) io = StringIO.new io << 'SchTasks /Create ' io << "/RU #{username} /RP #{password} " if repeat_type && repeat_time io << "/SC #{get_schedule_type(repeat_type)} " # schedule frequency io << "/MO #{repeat_time} " # time between runs end io << "/TN '#{task_name}' " # name of the task io << "/TR '#{build_bat_params(bat_params)}' " # what to execute when task runs io << "/ST '#{import_time.strftime('%H:%M')}' " if import_time # start time io << "/SD '#{import_at.strftime('%m/%d/%Y')}'" if import_at # start date io end |
#delete_task ⇒ Object
42 43 44 45 |
# File 'lib/task_scheduler/windows_scheduler.rb', line 42 def delete_task io = StringIO.new io << "SchTasks /Delete /TN '#{task_name}' /F" end |
#run_task(system_ip = nil) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/task_scheduler/windows_scheduler.rb', line 10 def run_task(system_ip = nil) io = StringIO.new io << 'SchTasks /Run ' io << "/S #{system_ip} " if system_ip # run a task on a different system io << "/TN '#{task_name}' " io end |
#update_task(import_at, import_time, repeat_type, repeat_time, username, password, bat_params = nil) ⇒ Object
updates a windows scheuled task via the command line
37 38 39 40 |
# File 'lib/task_scheduler/windows_scheduler.rb', line 37 def update_task(import_at, import_time, repeat_type, repeat_time, username, password, bat_params = nil) delete_task&.run create_task(import_at, import_time, repeat_type, repeat_time, username, password, bat_params) end |