rufus-scheduler-win32-service 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rufus-scheduler-win32-service.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jurgens du Toit
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Rufus::Scheduler::Win32::Service
2
+
3
+ A simple wrapper around the rufus-cheduler (https://github.com/jmettraux/rufus-scheduler) to run it as a Windows Service (https://github.com/djberg96/win32-service).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rufus-scheduler-win32-service'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rufus-scheduler-win32-service
18
+
19
+ ## Usage
20
+
21
+ You want to run your rufus-scheduler tasks as a Windows service. This gem provides the boilerplate:
22
+
23
+ ```
24
+ require 'rufus/scheduler/win32/service'
25
+
26
+ class MyService < Rufus::Scheduler::Win32::Service
27
+ def service_init
28
+ # Set up everything and create your scheduled tasks here
29
+ scheduler.every '5m' do |_job|
30
+ logger.info 'Reports of my death have been greatly exaggerated'
31
+ end
32
+ end
33
+ end
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,59 @@
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
@@ -0,0 +1,10 @@
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
9
+ end
10
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rufus/scheduler/win32/service/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rufus-scheduler-win32-service'
8
+ spec.version = Rufus::Scheduler::Win32::Service::VERSION
9
+ spec.authors = ['Jurgens du Toit']
10
+ spec.email = ['jrgns@jrgns.net']
11
+ spec.description = %(
12
+ A simple wrapper around the rufus-cheduler to run it as a Windows Service'
13
+ ).strip
14
+ spec.summary = %(
15
+ A simple wrapper around the rufus-cheduler to run it as a Windows Service
16
+ ).strip
17
+ spec.homepage = ''
18
+ spec.license = 'MIT'
19
+
20
+ spec.files = `git ls-files`.split($RS)
21
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_runtime_dependency 'rufus-scheduler'
26
+ spec.add_runtime_dependency 'win32-service'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.3'
29
+ spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'rubocop'
31
+ spec.add_development_dependency 'rspec', '~> 2.6'
32
+
33
+ end
@@ -0,0 +1,68 @@
1
+ require 'rufus/scheduler/win32/service'
2
+
3
+ describe Rufus::Scheduler::Win32::Service do
4
+ subject { Rufus::Scheduler::Win32::Service.new }
5
+
6
+ it 'provides a scheduler' do
7
+ expect(subject).to respond_to :scheduler
8
+ end
9
+
10
+ it 'shuts down the scheduler when the service stops' do
11
+ scheduler = double.as_null_object
12
+ subject.stub(:scheduler) { scheduler }
13
+
14
+ subject.service_stop
15
+
16
+ expect(scheduler).to have_received(:shutdown).with(:wait)
17
+ end
18
+
19
+ it 'pauses the scheduler when the service pauses' do
20
+ scheduler = double.as_null_object
21
+ allow(scheduler).to receive('paused?').and_return(false)
22
+ subject.stub(:scheduler) { scheduler }
23
+
24
+ subject.service_pause
25
+
26
+ expect(scheduler).to have_received(:pause)
27
+ end
28
+
29
+ it 'does not pause an already paused scheduler when the service pauses' do
30
+ scheduler = double.as_null_object
31
+ allow(scheduler).to receive('paused?').and_return(true)
32
+ subject.stub(:scheduler) { scheduler }
33
+
34
+ subject.service_pause
35
+
36
+ expect(scheduler).to have_not_received(:pause)
37
+ end
38
+
39
+ it 'resumes the scheduler when the service resumes' do
40
+ scheduler = double.as_null_object
41
+ allow(scheduler).to receive('paused?').and_return(true)
42
+ subject.stub(:scheduler) { scheduler }
43
+
44
+ subject.service_resume
45
+
46
+ expect(scheduler).to have_received(:resume)
47
+ end
48
+
49
+ it 'does not resume an already running scheduler when the service resumes' do
50
+ scheduler = double.as_null_object
51
+ allow(scheduler).to receive('paused?').and_return(false)
52
+ subject.stub(:scheduler) { scheduler }
53
+
54
+ subject.service_resume
55
+
56
+ expect(scheduler).to have_not_received(:resume)
57
+ end
58
+
59
+ it 'has a basic logger' do
60
+ expect(subject).to respond_to :logger
61
+ end
62
+
63
+ it 'can have another logger' do
64
+ logger = Logger.new(STDOUT)
65
+ subject.logger = logger
66
+ expect(subject.logger).to be logger
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rufus-scheduler-win32-service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jurgens du Toit
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rufus-scheduler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: win32-service
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rubocop
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '2.6'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '2.6'
110
+ description: A simple wrapper around the rufus-cheduler to run it as a Windows Service'
111
+ email:
112
+ - jrgns@jrgns.net
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - LICENSE.txt
120
+ - README.md
121
+ - Rakefile
122
+ - lib/rufus/scheduler/win32/service.rb
123
+ - lib/rufus/scheduler/win32/service/version.rb
124
+ - rufus-scheduler-win32-service.gemspec
125
+ - spec/rufus_scheduler_win32_service_spec.rb
126
+ homepage: ''
127
+ licenses:
128
+ - MIT
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 1.8.23
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: A simple wrapper around the rufus-cheduler to run it as a Windows Service
151
+ test_files:
152
+ - spec/rufus_scheduler_win32_service_spec.rb