trickle 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19cc4105b61efb7c460dd450ec16be6622a72223
4
- data.tar.gz: 5726cd5e4c4704a35c5c75cbe85aecb635a39c8c
3
+ metadata.gz: f68db11492eef5ad3120bf8d0e714b7491655ac7
4
+ data.tar.gz: f33df1a76661af8735b69d12e90d84ace548689d
5
5
  SHA512:
6
- metadata.gz: 99f9ce042976023e0e7c302fa6b863b6e4598a666db6de0f08354fc8a91ea25eba6f8ec3aea45cce768588c1e1edd6a54f41d38a106573801f729a769109856e
7
- data.tar.gz: 30e29bd8f137bc859dde9a0fb8e57e1a9e4cf34480282ec5079d39b075a4d94bd1ad0abaff762caa43073d5f53db558d96dcc339e8aca610a0ddbbc5736dc15d
6
+ metadata.gz: fb5906a2c2a252884eb0889065a85954f08f5f40fd817faf2eb5ab89ff58fe9eb421d5e5153e1d38a5e61986a19af2bcc976402727d4f2262a0db7f7f36cb0a0
7
+ data.tar.gz: 36798d71b537277c24feddc829062f9d964d51aff981d6f96561afd548774fe7d8ca39072ece2559b5f98228153294bc21c87399c3e5128edfdaac792effa999
data/README.md CHANGED
@@ -1,24 +1,12 @@
1
1
  # Trickle
2
2
 
3
- TODO: Write a gem description
3
+ A command-line tool to run commands specified in a file or multiple files. You can specify different rates to run the commands. See trickle --help for details. Originally created to run test scripts at random intervals.
4
4
 
5
5
  ## Installation
6
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
7
+ ```
8
+ gem install trickle
9
+ ```
22
10
 
23
11
  ## Contributing
24
12
 
@@ -1,3 +1,3 @@
1
1
  module Trickle
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/trickle.rb CHANGED
@@ -11,10 +11,15 @@ module Trickle
11
11
  @config.mode = :now
12
12
  @config.input = []
13
13
  @config.verbose = false
14
+ @config.no_run = false
15
+ @config.random = false
14
16
  end
15
17
 
16
18
  def run
17
19
  if parsed_options? && arguments_valid?
20
+
21
+ @config.input.shuffle! if @config.random
22
+
18
23
  case @config.mode
19
24
  when :within
20
25
  run_schedule(@config.within)
@@ -30,19 +35,20 @@ module Trickle
30
35
 
31
36
  def run_all
32
37
  @config.input.each do |line|
33
- display_running_cmd(line)
34
- puts `#{line}`
38
+ run_and_or_display(line)
35
39
  end
36
40
  end
37
41
 
38
42
  def run_schedule(within)
39
43
  @threads = []
44
+ mutex = Mutex.new
40
45
 
41
46
  @config.input.each do |line|
42
47
  @threads << Thread.new do
43
- sleep(rand(60*within))
44
- display_running_cmd(line)
45
- puts `#{line}`
48
+ sleep(rand(60*within))
49
+ mutex.synchronize do
50
+ run_and_or_display(line)
51
+ end
46
52
  end
47
53
  end
48
54
 
@@ -52,25 +58,36 @@ module Trickle
52
58
 
53
59
  def run_every(rate)
54
60
  @config.input.each do |line|
55
- display_running_cmd(line)
56
- puts `#{line}`
61
+ run_and_or_display(line)
57
62
  sleep(60.0/rate)
58
63
  end
59
64
  end
60
65
 
61
66
  protected
62
67
 
63
- def display_running_cmd(line)
64
- puts "Running: #{line}" if @config.verbose
68
+ def verbose(line)
69
+ print "#{Time.now} - '#{line.strip}': "
70
+ end
71
+
72
+ def run_and_or_display(line)
73
+ verbose(line) if @config.verbose
74
+
75
+ if @config.no_run
76
+ puts "#{line}"
77
+ else
78
+ puts `#{line}`
79
+ end
65
80
  end
66
81
 
67
82
  def parsed_options?
68
83
  @opts = OptionParser.new
69
84
  @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}
85
+ @opts.on('--within x', 'Run all commands randomly within x minutes') {|within| @config.mode = :within; @config.within = within.to_i}
86
+ @opts.on('--rate x', 'Run all commands at the rate of x commands per minute') {|rate| @config.mode = :rate; @config.rate = rate.to_i}
87
+ @opts.on('--now', 'Run all commands now (default)') {@config.mode = :now}
88
+ @opts.on('--verbose', 'Output command that is being ran') {@config.verbose = true}
89
+ @opts.on('--no-run', 'Only display commands, do not execute them') {@config.no_run = true}
90
+ @opts.on('--random', 'Run through commands in random order') {@config.random = true}
74
91
  @opts.parse!(@args) rescue return false
75
92
 
76
93
  if $stdin.tty?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trickle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kale Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-04 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler