rufus-scheduler-win32-service 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,21 +18,31 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- You want to run your rufus-scheduler tasks as a Windows service. This gem provides the boilerplate:
21
+ You want to run your rufus-scheduler tasks as a Windows service. This gem provides the boilerplate.
22
+
23
+ Use the `Daemon` class as the base for the class you're going to run as a service:
22
24
 
23
25
  ```
24
- require 'rufus/scheduler/win32/service'
26
+ require 'rufus/scheduler/win32/daemon'
25
27
 
26
- class MyService < Rufus::Scheduler::Win32::Service
28
+ class MyService < RufusSchedulerWin32::Daemon
27
29
  def service_init
28
30
  # Set up everything and create your scheduled tasks here
29
31
  scheduler.every '5m' do |_job|
30
32
  logger.info 'Reports of my death have been greatly exaggerated'
31
33
  end
34
+
35
+ scheduler.join
32
36
  end
33
37
  end
38
+
39
+ # Start the service
40
+ MyService.mainloop
34
41
  ```
35
42
 
43
+ You get access to the `scheduler` property to schedule your tasks and the `logger`
44
+ property for logging.
45
+
36
46
  ## Contributing
37
47
 
38
48
  1. Fork it
@@ -0,0 +1,52 @@
1
+ require 'rufus/scheduler/win32/service/version'
2
+ require 'logger'
3
+ require 'win32/daemon'
4
+ require 'rufus-scheduler'
5
+
6
+ module RufusSchedulerWin32
7
+ # Service wrapper around rufus-scheduler
8
+ class Daemon < Win32::Daemon
9
+ attr_writer :logger
10
+
11
+ def service_main
12
+ logger.info 'Running Main Loop'
13
+ while scheduler.up?
14
+ logger.debug 'Still Running'
15
+ sleep 10
16
+ end
17
+ logger.info 'Scheduler down. Exiting main loop'
18
+ end
19
+
20
+ def service_stop
21
+ logger.info 'Stopping scheduler service'
22
+
23
+ scheduler.shutdown(:wait)
24
+
25
+ logger.info 'Service stopped'
26
+ end
27
+
28
+ def service_pause
29
+ logger.info 'Pausing scheduler service'
30
+
31
+ scheduler.pause unless scheduler.paused?
32
+
33
+ logger.info 'Paused scheduler service'
34
+ end
35
+
36
+ def service_resume
37
+ logger.info 'Resuming scheduler service'
38
+
39
+ scheduler.resume if scheduler.paused?
40
+
41
+ logger.info 'Resumed scheduler service'
42
+ end
43
+
44
+ def scheduler
45
+ @scheduler ||= Rufus::Scheduler.new
46
+ end
47
+
48
+ def logger
49
+ @logger ||= Logger.new(STDOUT)
50
+ end
51
+ end
52
+ end
@@ -1,10 +1,5 @@
1
- module Rufus
2
- module Scheduler
3
- module Win32
4
- # Service wrapper around rufus-scheduler
5
- class Service
6
- VERSION = '0.0.1'
7
- end
8
- end
1
+ module RufusSchedulerWin32
2
+ class Service
3
+ VERSION = '0.0.2'
9
4
  end
10
5
  end
@@ -5,16 +5,16 @@ require 'rufus/scheduler/win32/service/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'rufus-scheduler-win32-service'
8
- spec.version = Rufus::Scheduler::Win32::Service::VERSION
8
+ spec.version = RufusSchedulerWin32::Service::VERSION
9
9
  spec.authors = ['Jurgens du Toit']
10
10
  spec.email = ['jrgns@jrgns.net']
11
11
  spec.description = %(
12
- A simple wrapper around the rufus-cheduler to run it as a Windows Service'
12
+ A simple wrapper around the rufus-scheduler to run it as a Windows Service
13
13
  ).strip
14
14
  spec.summary = %(
15
- A simple wrapper around the rufus-cheduler to run it as a Windows Service
15
+ A simple wrapper around the rufus-scheduler to run it as a Windows Service
16
16
  ).strip
17
- spec.homepage = ''
17
+ spec.homepage = 'https://github.com/jrgns/rufus-scheduler-win32-service'
18
18
  spec.license = 'MIT'
19
19
 
20
20
  spec.files = `git ls-files`.split($RS)
@@ -1,7 +1,7 @@
1
- require 'rufus/scheduler/win32/service'
1
+ require 'rufus/scheduler/win32/daemon'
2
2
 
3
- describe Rufus::Scheduler::Win32::Service do
4
- subject { Rufus::Scheduler::Win32::Service.new }
3
+ describe RufusSchedulerWin32::Daemon do
4
+ subject { RufusSchedulerWin32::Daemon.new }
5
5
 
6
6
  it 'provides a scheduler' do
7
7
  expect(subject).to respond_to :scheduler
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-scheduler-win32-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-10 00:00:00.000000000 Z
12
+ date: 2014-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rufus-scheduler
@@ -107,7 +107,7 @@ dependencies:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
109
  version: '2.6'
110
- description: A simple wrapper around the rufus-cheduler to run it as a Windows Service'
110
+ description: A simple wrapper around the rufus-scheduler to run it as a Windows Service
111
111
  email:
112
112
  - jrgns@jrgns.net
113
113
  executables: []
@@ -119,11 +119,11 @@ files:
119
119
  - LICENSE.txt
120
120
  - README.md
121
121
  - Rakefile
122
- - lib/rufus/scheduler/win32/service.rb
122
+ - lib/rufus/scheduler/win32/daemon.rb
123
123
  - lib/rufus/scheduler/win32/service/version.rb
124
124
  - rufus-scheduler-win32-service.gemspec
125
125
  - spec/rufus_scheduler_win32_service_spec.rb
126
- homepage: ''
126
+ homepage: https://github.com/jrgns/rufus-scheduler-win32-service
127
127
  licenses:
128
128
  - MIT
129
129
  post_install_message:
@@ -144,9 +144,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  requirements: []
146
146
  rubyforge_project:
147
- rubygems_version: 1.8.23
147
+ rubygems_version: 1.8.28
148
148
  signing_key:
149
149
  specification_version: 3
150
- summary: A simple wrapper around the rufus-cheduler to run it as a Windows Service
150
+ summary: A simple wrapper around the rufus-scheduler to run it as a Windows Service
151
151
  test_files:
152
152
  - spec/rufus_scheduler_win32_service_spec.rb
@@ -1,59 +0,0 @@
1
- require 'rufus/scheduler/win32/service/version'
2
- require 'logger'
3
- require 'win32/daemon'
4
- require 'rufus-scheduler'
5
-
6
- module Rufus
7
- module Scheduler
8
- # Containing module for the Service class
9
- module Win32
10
- include ::Win32
11
-
12
- # Service wrapper around rufus-scheduler
13
- class Service
14
- attr_writer :logger
15
-
16
- def service_main
17
- logger.info 'Running Main Loop'
18
- while scheduler.up?
19
- logger.debug 'Still Running'
20
- sleep 10
21
- end
22
- logger.info 'Scheduler down. Exiting main loop'
23
- end
24
-
25
- def service_stop
26
- logger.info 'Stopping scheduler service'
27
-
28
- scheduler.shutdown(:wait)
29
-
30
- logger.info 'Service stopped'
31
- end
32
-
33
- def service_pause
34
- logger.info 'Pausing scheduler service'
35
-
36
- scheduler.pause unless scheduler.paused?
37
-
38
- logger.info 'Paused scheduler service'
39
- end
40
-
41
- def service_resume
42
- logger.info 'Resuming scheduler service'
43
-
44
- scheduler.resume if scheduler.paused?
45
-
46
- logger.info 'Resumed scheduler service'
47
- end
48
-
49
- def scheduler
50
- @scheduler ||= Rufus::Scheduler.new
51
- end
52
-
53
- def logger
54
- @logger ||= Logger.new(STDOUT)
55
- end
56
- end
57
- end
58
- end
59
- end