soar_thread_worker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 725c49f29b9c2a8361fffa2419a7dc4f206d1f9f
4
+ data.tar.gz: 970ae6b9365da10c7a45a1d153dfd6da332deb75
5
+ SHA512:
6
+ metadata.gz: 7c886cb4ca5f7f6babd46dca4d4fe9d17e64ee01c75907e532075a4cfe32e35819fce21798ece7b9d7e0f8d25953112d4a528c138d051519ee52e66499a3bc79
7
+ data.tar.gz: cf1ed9d06c9388a5e17209f352295817a4bce163a4dab30eee343c3ad16de90e4fd0795b500e31f1714a34b296140cc3fc1162680eb0e9ed476a6ed4b8c69c9c
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .byebug_history
11
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ soar_thread_worker
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in soar_auditing_provider.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Barney de Villiers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # SoarThreadWorker
2
+
3
+ [![Build Status](http://soar-ci.dev.auto-h.net:8080/job/soar_thread_worker/badge/icon)](http://soar-ci.dev.auto-h.net:8080/job/soar_thread_worker)
4
+
5
+ This gem provides the thread worker that workers in the SOAR architecture can extend from for threading purposes.
6
+
7
+ ```ruby
8
+ class MyWorker < SoarThreadWorker::ThreadWorker
9
+ end
10
+ @worker = MyWorker.new
11
+ @worker.start
12
+ ```
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'soar_thread_worker'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install soar_thread_worker
29
+
30
+ ## Testing
31
+
32
+ Run the rspec test tests:
33
+
34
+ $ bundle exec rspec -cfd spec
35
+
36
+ ## Usage
37
+
38
+
39
+ ## Detailed example
40
+
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and feature requests are welcome by email to barney dot de dot villiers at hetzner dot co dot za. This gem is sponsored by Hetzner (Pty) Ltd (http://hetzner.co.za)
45
+
46
+ ## Notes
47
+
48
+
49
+ ## License
50
+
51
+ 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,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "soar_auditing_provider_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,68 @@
1
+ module SoarThreadWorker
2
+ class ThreadWorker
3
+ attr_accessor :event_handler
4
+ attr_accessor :thread
5
+
6
+ def self.create_worker(event_handler)
7
+ ThreadWorker.new(event_handler)
8
+ end
9
+
10
+ def self.error(message)
11
+ $stderr.puts "ERROR [ThreadWorker] #{message}"
12
+ end
13
+
14
+ def initialize(event_handler)
15
+ @running = false
16
+ @stopping = false
17
+ @event_handler = event_handler
18
+ end
19
+
20
+ def running?
21
+ @running and not @thread.nil?
22
+ end
23
+
24
+ def start
25
+ begin
26
+ return if (running?)
27
+ create_thread()
28
+ @running = true
29
+ rescue Exception => e
30
+ ThreadWorker::error("Exception #{e} in start")
31
+ end
32
+ end
33
+
34
+ def stop
35
+ @stopping = true
36
+ @thread = nil
37
+ end
38
+
39
+ def execute
40
+ #Inversion of control: override this method to do the work you need.
41
+ #Return true if after execution the thread should stop, false if it
42
+ #should continue running
43
+ false
44
+ end
45
+
46
+ private
47
+
48
+ def run
49
+ while not @stopping
50
+ stop if execute
51
+ be_nice
52
+ end
53
+ @running = false
54
+ end
55
+
56
+ def create_thread
57
+ @thread = Thread.new do
58
+ Thread.abort_on_exception=true
59
+ run
60
+ end
61
+ end
62
+
63
+ def be_nice
64
+ sleep(0.1)
65
+ Thread.pass
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module SoarThreadWorker
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "soar_thread_worker/version"
2
+ require 'soar_thread_worker/thread_worker'
3
+
4
+ module SoarThreadWorker
5
+ end
@@ -0,0 +1 @@
1
+ sanity
@@ -0,0 +1 @@
1
+ ruby-2.2
data/sanity/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'soar_thread_worker', :path => "../"
data/sanity/sanity.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'soar_thread_worker'
2
+
3
+ class Main
4
+
5
+ def test_sanity
6
+ end
7
+ end
8
+
9
+ main = Main.new
10
+ main.test_sanity
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soar_thread_worker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "soar_thread_worker"
8
+ spec.version = SoarThreadWorker::VERSION
9
+ spec.authors = ["Barney de Villiers"]
10
+ spec.email = ["barney.de.villiers@hetzner.co.za"]
11
+
12
+ spec.summary = %q{Thread Worker for SOAR architecture}
13
+ spec.description = %q{Thread Worker for SOAR architecture providing basic thread operations}
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "byebug"
25
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soar_thread_worker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Barney de Villiers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Thread Worker for SOAR architecture providing basic thread operations
70
+ email:
71
+ - barney.de.villiers@hetzner.co.za
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".ruby-gemset"
79
+ - ".ruby-version"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/soar_thread_worker.rb
87
+ - lib/soar_thread_worker/thread_worker.rb
88
+ - lib/soar_thread_worker/version.rb
89
+ - sanity/.ruby-gemset
90
+ - sanity/.ruby-version
91
+ - sanity/Gemfile
92
+ - sanity/sanity.rb
93
+ - soar_thread_worker.gemspec
94
+ homepage:
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.8
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Thread Worker for SOAR architecture
118
+ test_files: []