bow 0.0.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bow
4
+ class ThreadPool
5
+ attr_accessor :max_threads, :queue
6
+
7
+ def initialize(max_threads = 4)
8
+ @queue = []
9
+ @threads = []
10
+ @history = []
11
+ @max_threads = max_threads
12
+ return unless block_given?
13
+ yield(self)
14
+ run
15
+ end
16
+
17
+ def add(&task)
18
+ add_task(task)
19
+ end
20
+
21
+ def run
22
+ @queue.each do |task|
23
+ wait
24
+ run_task(task)
25
+ end
26
+ wait_for_all
27
+ end
28
+
29
+ def from_enumerable(enumerable, &block)
30
+ enumerable.each do |params|
31
+ task = build_task(block, params)
32
+ add_task(task)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def run_task(task)
39
+ thr = Thread.new(&task)
40
+ @threads << thr
41
+ end
42
+
43
+ def build_task(handler, params)
44
+ -> { handler.call(params) }
45
+ end
46
+
47
+ def add_task(task)
48
+ @queue << task
49
+ end
50
+
51
+ def wait
52
+ return if @threads.count < @max_threads
53
+ until @threads.count < @max_threads
54
+ active_threads = @threads.select(&:alive?)
55
+ @history += (@threads - active_threads)
56
+ @threads = active_threads
57
+ sleep 0.001
58
+ end
59
+ end
60
+
61
+ def wait_for_all
62
+ return if @threads.empty?
63
+ # @threads.map!(&:run)
64
+ @threads.each(&:join)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bow
4
+ VERSION = '0.5.0'
5
+ end
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ################################################
4
+ # INSTALLS RVM & RUBY & RAKE #
5
+ # TO REMOVE RUN: rvm implode #
6
+ ################################################
7
+
8
+ RUBY_VERSION="2.4"
9
+
10
+ # Install rvm
11
+ which rvm &>/dev/null
12
+ if [[ 0 != $? ]]; then
13
+ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
14
+ echo ">> Installing RVM..."
15
+ \curl -sSL https://get.rvm.io | sudo bash -s stable
16
+ source /usr/local/rvm/scripts/rvm
17
+ if [[ $? == 0 ]]; then echo "RVM installed!"; fi
18
+ else
19
+ echo ">> RVM already installed!"
20
+ fi
21
+
22
+ # Install ruby
23
+ which ruby &>/dev/null
24
+ if [[ 0 != $? ]]; then
25
+ echo ">> Installing Ruby $RUBY_VERSION..."
26
+ source /usr/local/rvm/scripts/rvm
27
+ rvm install $RUBY_VERSION
28
+ rvm --default use $RUBY_VERSION
29
+ if [[ $? == 0 ]]; then echo "Ruby $RUBY_VERSION installed!"; fi
30
+ else
31
+ echo ">> Ruby already installed!"
32
+ fi
33
+
34
+ # Install bow
35
+ which bow &>/dev/null
36
+ if [[ 0 != $? ]]; then
37
+ echo ">> Installing Bow..."
38
+ gem install bow
39
+ if [[ $? == 0 ]]; then echo "Bow installed!"; fi
40
+ else
41
+ echo ">> Bow already installed!"
42
+ fi
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zinovyev Ivan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-09 00:00:00.000000000 Z
11
+ date: 2017-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
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'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rubocop
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,14 +80,43 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
- description: Simple provisioning with rake tasks
83
+ description: Simple provisioning via rake tasks
70
84
  email: zinovyev.id@gmail.com
71
- executables: []
85
+ executables:
86
+ - bow
72
87
  extensions: []
73
88
  extra_rdoc_files: []
74
89
  files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - bin/bow
75
96
  - bow.gemspec
76
97
  - lib/bow.rb
98
+ - lib/bow/application.rb
99
+ - lib/bow/command.rb
100
+ - lib/bow/commands/apply.rb
101
+ - lib/bow/commands/exec.rb
102
+ - lib/bow/commands/init.rb
103
+ - lib/bow/commands/ping.rb
104
+ - lib/bow/commands/prepare.rb
105
+ - lib/bow/config.rb
106
+ - lib/bow/inventory.rb
107
+ - lib/bow/inventory_example.rb
108
+ - lib/bow/locker.rb
109
+ - lib/bow/memorable.rb
110
+ - lib/bow/options.rb
111
+ - lib/bow/rake.rb
112
+ - lib/bow/response_formatter.rb
113
+ - lib/bow/ssh/rsync.rb
114
+ - lib/bow/ssh/scp.rb
115
+ - lib/bow/ssh_helper.rb
116
+ - lib/bow/targets.rb
117
+ - lib/bow/thread_pool.rb
118
+ - lib/bow/version.rb
119
+ - src/preprovision.sh
77
120
  homepage: https://github.com/zinovyev/bow
78
121
  licenses:
79
122
  - MIT
@@ -97,5 +140,5 @@ rubyforge_project:
97
140
  rubygems_version: 2.6.11
98
141
  signing_key:
99
142
  specification_version: 4
100
- summary: Simple provisioning with rake tasks
143
+ summary: Simple provisioning via rake tasks
101
144
  test_files: []