rasteira 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 16b463d33f2b21c137a649b55da3bd8df4be259e
4
+ data.tar.gz: d9c353cbe174e9ede5a5c927f9671ddf0273c23e
5
+ SHA512:
6
+ metadata.gz: 0a47ffd160905a5da8df674662a1e4721edc6767218bd44b173f3a62e5fdb264b529311230b3929d7f67e606c11f2fadace4fe89e9f6a4bc507e9a33ef0a6f42
7
+ data.tar.gz: f5734c5c5841e68a3909979d5f8ac9332fca7f3e691df3570c935ff45e55a81c68111cf2c605d56ebf1e94553691f3a6ed0a8d39a1b785e0cbc605fd97fc073a
@@ -0,0 +1,150 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ ### https://raw.github.com/github/gitignore/44cbb3686c18f634a488ea123d1148ca9a64fa22/ruby.gitignore
14
+
15
+ *.gem
16
+ *.rbc
17
+ /.config
18
+ /coverage/
19
+ /InstalledFiles
20
+ /pkg/
21
+ /spec/reports/
22
+ /spec/examples.txt
23
+ /test/tmp/
24
+ /test/version_tmp/
25
+ /tmp/
26
+
27
+ # Used by dotenv library to load environment variables.
28
+ # .env
29
+
30
+ ## Specific to RubyMotion:
31
+ .dat*
32
+ .repl_history
33
+ build/
34
+ *.bridgesupport
35
+ build-iPhoneOS/
36
+ build-iPhoneSimulator/
37
+
38
+ ## Specific to RubyMotion (use of CocoaPods):
39
+ #
40
+ # We recommend against adding the Pods directory to your .gitignore. However
41
+ # you should judge for yourself, the pros and cons are mentioned at:
42
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
43
+ #
44
+ # vendor/Pods/
45
+
46
+ ## Documentation cache and generated files:
47
+ /.yardoc/
48
+ /_yardoc/
49
+ /doc/
50
+ /rdoc/
51
+
52
+ ## Environment normalization:
53
+ /.bundle/
54
+ /vendor/bundle
55
+ /lib/bundler/man/
56
+
57
+ # for a library or gem, you might want to ignore these files since the code is
58
+ # intended to run in multiple environments; otherwise, check them in:
59
+ # Gemfile.lock
60
+ # .ruby-version
61
+ # .ruby-gemset
62
+
63
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
64
+ .rvmrc
65
+
66
+
67
+ ### https://raw.github.com/github/gitignore/44cbb3686c18f634a488ea123d1148ca9a64fa22/ruby.gitignore
68
+
69
+ *.gem
70
+ *.rbc
71
+ /.config
72
+ /coverage/
73
+ /InstalledFiles
74
+ /pkg/
75
+ /spec/reports/
76
+ /spec/examples.txt
77
+ /test/tmp/
78
+ /test/version_tmp/
79
+ /tmp/
80
+
81
+ # Used by dotenv library to load environment variables.
82
+ # .env
83
+
84
+ ## Specific to RubyMotion:
85
+ .dat*
86
+ .repl_history
87
+ build/
88
+ *.bridgesupport
89
+ build-iPhoneOS/
90
+ build-iPhoneSimulator/
91
+
92
+ ## Specific to RubyMotion (use of CocoaPods):
93
+ #
94
+ # We recommend against adding the Pods directory to your .gitignore. However
95
+ # you should judge for yourself, the pros and cons are mentioned at:
96
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
97
+ #
98
+ # vendor/Pods/
99
+
100
+ ## Documentation cache and generated files:
101
+ /.yardoc/
102
+ /_yardoc/
103
+ /doc/
104
+ /rdoc/
105
+
106
+ ## Environment normalization:
107
+ /.bundle/
108
+ /vendor/bundle
109
+ /vendor/ruby
110
+ /lib/bundler/man/
111
+
112
+ # for a library or gem, you might want to ignore these files since the code is
113
+ # intended to run in multiple environments; otherwise, check them in:
114
+ # Gemfile.lock
115
+ # .ruby-version
116
+ # .ruby-gemset
117
+
118
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
119
+ .rvmrc
120
+
121
+
122
+ ### https://raw.github.com/github/gitignore/44cbb3686c18f634a488ea123d1148ca9a64fa22/Global/MacOS.gitignore
123
+
124
+ *.DS_Store
125
+ .AppleDouble
126
+ .LSOverride
127
+
128
+ # Icon must end with two \r
129
+ Icon
130
+
131
+
132
+ # Thumbnails
133
+ ._*
134
+
135
+ # Files that might appear in the root of a volume
136
+ .DocumentRevisions-V100
137
+ .fseventsd
138
+ .Spotlight-V100
139
+ .TemporaryItems
140
+ .Trashes
141
+ .VolumeIcon.icns
142
+ .com.apple.timemachine.donotpresent
143
+
144
+ # Directories potentially created on remote AFP share
145
+ .AppleDB
146
+ .AppleDesktop
147
+ Network Trash Folder
148
+ Temporary Items
149
+ .apdisk
150
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ 2.4.1
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - 2.3
8
+ - 2.4
9
+ - ruby-head
10
+ before_install: gem install bundler -v 1.15.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at nserihiro@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rasteira.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Kazuhiro Serizawa
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.
@@ -0,0 +1,63 @@
1
+ [![Build Status](https://travis-ci.org/serihiro/rasteira.svg?branch=master)](https://travis-ci.org/serihiro/rasteira)
2
+
3
+ # Rasteira
4
+
5
+ - Rasteira is
6
+ - a simple on memory thread base job queue worker.
7
+ - embeddable to a ruby product.
8
+ - Rasteira is **not**
9
+ - a dependent daemon process unlike [Sidekiq](https://github.com/mperham/sidekiq), [Resque](https://github.com/resque/resque) and [Delayed::Job](https://github.com/collectiveidea/delayed_job) etc.
10
+ - working as a distributed system: just a single server.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'rasteira'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install rasteira
27
+
28
+ ## Usage
29
+
30
+ Firstly you need to implement a worker like the following.
31
+
32
+ ```ruby:example/hellow_worker.rb
33
+ class HelloWorker
34
+ def perform(name)
35
+ puts "Hello, #{name}"
36
+ end
37
+ end
38
+ ```
39
+
40
+ And start Embed Worker Manager and enqueue a job.
41
+
42
+ ```ruby
43
+ manager = Rasteira::EmbedWorker::Manager.run
44
+ manager.enqueue_job!('HelloWorker', 'example/hello_worker.rb', 'serihiro')
45
+ ```
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/serihiro/rasteira. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
60
+
61
+ ## Code of Conduct
62
+
63
+ Everyone interacting in the Rasteira project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rasteira/blob/master/CODE_OF_CONDUCT.md).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rasteira"
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(__FILE__)
@@ -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,10 @@
1
+ # To test with bin/console, execute like this:
2
+ #
3
+ # 2.4.0 :001 > m = Rasteira::EmbedWorker::Manager.run
4
+ # 2.4.0 :002 > m.enqueue_job!('HelloWorker', 'example/hello_worker.rb', 'serihiro')
5
+ #
6
+ class HelloWorker
7
+ def perform(name)
8
+ puts "Hello, #{name}"
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ require 'rasteira/version'
2
+ require 'rasteira/core/job'
3
+ require 'rasteira/embed_worker/manager'
4
+
5
+ module Rasteira
6
+ end
@@ -0,0 +1,41 @@
1
+ module Rasteira
2
+ module Core
3
+ class Job
4
+ attr_reader :worker_name, :worker_file_path, :args, :status
5
+
6
+ STATUSES = {
7
+ ready: 0,
8
+ in_process: 1,
9
+ finished: 2,
10
+ failed: 3
11
+ }.freeze
12
+
13
+ def initialize(worker_name, worker_file_path, *args)
14
+ @worker_file_path = File.expand_path(worker_file_path, Dir.pwd)
15
+ unless File.exists?(@worker_file_path)
16
+ raise ArgumentError.new("#{@worker_file_path} could not be found")
17
+ end
18
+
19
+ require(@worker_file_path)
20
+ @worker_name = worker_name
21
+ @args = args
22
+ @status = STATUSES[:ready]
23
+ end
24
+
25
+ def start!
26
+ @status = STATUSES[:in_process]
27
+ begin
28
+ worker.perform(*@args)
29
+ @status = STATUSES[:finished]
30
+ rescue => e
31
+ @status = STATUSES[:failed]
32
+ raise e
33
+ end
34
+ end
35
+
36
+ def worker
37
+ @worker ||= Object.const_get("::#{@worker_name}").new
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,80 @@
1
+ module Rasteira
2
+ module EmbedWorker
3
+ class Manager
4
+ attr_reader :job_pool
5
+
6
+ def initialize
7
+ @job_pool = Array.new
8
+ @thread_pool = Array.new
9
+ @mutex = Mutex.new
10
+ end
11
+
12
+ def self.run
13
+ this = new
14
+ this.run
15
+ this
16
+ end
17
+
18
+ # TODO to be specifiable
19
+ MIN_THREAD_SIZE = 5
20
+
21
+ def run
22
+ @thread_pool = MIN_THREAD_SIZE.times.map do
23
+ Thread.start { worker_thread_process }
24
+ end
25
+
26
+ @thread_manager = Thread.start do
27
+ loop do
28
+ @mutex.synchronize do
29
+ @thread_pool.reject! { |thread| !thread.alive? }
30
+
31
+ (@thread_pool.size...MIN_THREAD_SIZE).each do
32
+ @thread_pool << Thread.start { worker_thread_process }
33
+ end
34
+ end
35
+
36
+ sleep(1)
37
+ end
38
+ end
39
+ end
40
+
41
+ def enqueue_job!(worker_name, worker_file_path, *args)
42
+ @mutex.synchronize do
43
+ @job_pool << ::Rasteira::Core::Job.new(worker_name, worker_file_path, *args)
44
+ end
45
+ end
46
+
47
+ def shutdown_workers!
48
+ @thread_pool.each(&:kill)
49
+ @thread_manager.kill
50
+ end
51
+
52
+ def worker_statuses
53
+ @thread_pool.map do |thread|
54
+ { id: thread.object_id, status: thread.status }
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def worker_thread_process
61
+ loop do
62
+ begin
63
+ job = nil
64
+ @mutex.synchronize do
65
+ job = @job_pool.pop
66
+ end
67
+ if !job.nil?
68
+ job.start!
69
+ else
70
+ sleep(3)
71
+ end
72
+ rescue => e
73
+ # TODO logging
74
+ puts e.inspect
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,3 @@
1
+ module Rasteira
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rasteira/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rasteira'
8
+ spec.version = Rasteira::VERSION
9
+ spec.authors = ['Kazuhiro Serizawa']
10
+ spec.email = ['nserihiro@gmail.com']
11
+
12
+ spec.summary = 'simple, on memory, and thread base job queue worker'
13
+ spec.description = 'simple, on memory, and thread base job queue worker'
14
+ spec.homepage = 'https://github.com/serihiro/rasteira'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.15'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rasteira
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kazuhiro Serizawa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-06 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
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
+ description: simple, on memory, and thread base job queue worker
56
+ email:
57
+ - nserihiro@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".ruby-version"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - example/hello_worker.rb
74
+ - lib/rasteira.rb
75
+ - lib/rasteira/core/job.rb
76
+ - lib/rasteira/embed_worker/manager.rb
77
+ - lib/rasteira/version.rb
78
+ - rasteira.gemspec
79
+ homepage: https://github.com/serihiro/rasteira
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.6.13
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: simple, on memory, and thread base job queue worker
103
+ test_files: []