trickle 0.0.1

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: 19cc4105b61efb7c460dd450ec16be6622a72223
4
+ data.tar.gz: 5726cd5e4c4704a35c5c75cbe85aecb635a39c8c
5
+ SHA512:
6
+ metadata.gz: 99f9ce042976023e0e7c302fa6b863b6e4598a666db6de0f08354fc8a91ea25eba6f8ec3aea45cce768588c1e1edd6a54f41d38a106573801f729a769109856e
7
+ data.tar.gz: 30e29bd8f137bc859dde9a0fb8e57e1a9e4cf34480282ec5079d39b075a4d94bd1ad0abaff762caa43073d5f53db558d96dcc339e8aca610a0ddbbc5736dc15d
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ *.swp
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kale Davis
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,29 @@
1
+ # Trickle
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'trickle'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install trickle
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/trickle ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Usage: trickle [--within=<minutes> | --rate=<# per minute> | --now] <file>"
4
+
5
+ require 'trickle'
6
+
7
+ app = Trickle::Trickle.new(*ARGV)
8
+ app.run
@@ -0,0 +1,3 @@
1
+ module Trickle
2
+ VERSION = "0.0.1"
3
+ end
data/lib/trickle.rb ADDED
@@ -0,0 +1,89 @@
1
+ require "trickle/version"
2
+ require "ostruct"
3
+ require "optparse"
4
+
5
+ module Trickle
6
+ class Trickle
7
+ def initialize(*args)
8
+ @args = args
9
+
10
+ @config = OpenStruct.new
11
+ @config.mode = :now
12
+ @config.input = []
13
+ @config.verbose = false
14
+ end
15
+
16
+ def run
17
+ if parsed_options? && arguments_valid?
18
+ case @config.mode
19
+ when :within
20
+ run_schedule(@config.within)
21
+ when :rate
22
+ run_every(@config.rate)
23
+ when :now
24
+ run_all
25
+ end
26
+ else
27
+ abort @opts.to_s
28
+ end
29
+ end
30
+
31
+ def run_all
32
+ @config.input.each do |line|
33
+ display_running_cmd(line)
34
+ puts `#{line}`
35
+ end
36
+ end
37
+
38
+ def run_schedule(within)
39
+ @threads = []
40
+
41
+ @config.input.each do |line|
42
+ @threads << Thread.new do
43
+ sleep(rand(60*within))
44
+ display_running_cmd(line)
45
+ puts `#{line}`
46
+ end
47
+ end
48
+
49
+ # wait for all threads to finish before exiting
50
+ @threads.each(&:join)
51
+ end
52
+
53
+ def run_every(rate)
54
+ @config.input.each do |line|
55
+ display_running_cmd(line)
56
+ puts `#{line}`
57
+ sleep(60.0/rate)
58
+ end
59
+ end
60
+
61
+ protected
62
+
63
+ def display_running_cmd(line)
64
+ puts "Running: #{line}" if @config.verbose
65
+ end
66
+
67
+ def parsed_options?
68
+ @opts = OptionParser.new
69
+ @opts.banner = 'Usage: trickle [options] file ...'
70
+ @opts.on('-t', '--within x', 'Run all commands randomly within x minutes') {|within| @config.mode = :within; @config.within = within.to_i}
71
+ @opts.on('-r', '--rate x', 'Run all commands at the rate of x commands per minute') {|rate| @config.mode = :rate; @config.rate = rate.to_i}
72
+ @opts.on('-n', '--now', 'Run all commands now (default)') {@config.mode = :now}
73
+ @opts.on('-v', '--verbose', 'Output command that is being ran') {@config.verbose = true}
74
+ @opts.parse!(@args) rescue return false
75
+
76
+ if $stdin.tty?
77
+ @args.each {|file| @config.input += IO.readlines(file)}
78
+ else
79
+ $stdin.each_line {|line| @config.input << line}
80
+ end
81
+
82
+ true
83
+ end
84
+
85
+ def arguments_valid?
86
+ true if @config.input.any?
87
+ end
88
+ end
89
+ end
data/trickle.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trickle/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trickle"
8
+ spec.version = Trickle::VERSION
9
+ spec.authors = ["Kale Davis"]
10
+ spec.email = ["kale@kaledavis.com"]
11
+ spec.summary = %q(Run commands specified within files at different rates)
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/kale/trickle"
14
+ spec.license = "MIT"
15
+
16
+ spec.bindir = 'bin'
17
+ spec.executables = %w[trickle]
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trickle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kale Davis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-04 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ description: Run commands specified within files at different rates
28
+ email:
29
+ - kale@kaledavis.com
30
+ executables:
31
+ - trickle
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/trickle
41
+ - lib/trickle.rb
42
+ - lib/trickle/version.rb
43
+ - trickle.gemspec
44
+ homepage: https://github.com/kale/trickle
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.2.2
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Run commands specified within files at different rates
68
+ test_files: []