command_timer 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ["cctiger36@gmail.com"]
7
7
  gem.description = %q{Simple tool to execute commands on schedule}
8
8
  gem.summary = %q{Execute commands on schedule}
9
- gem.homepage = ""
9
+ gem.homepage = "https://github.com/cctiger36/command_timer"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
data/lib/command_timer.rb CHANGED
@@ -12,7 +12,7 @@ module CommandTimer
12
12
  return parse_time(%x[ntpdate -q #{server}].scan(/[0-9]{2}:[0-9]{2}:[0-9]{2}/).first)
13
13
  end
14
14
  end
15
- puts "Warning: ntpdate not installed and use the local clock."
15
+ puts "Warning: ntpdate not found and then use the local clock."
16
16
  Time.now
17
17
  end
18
18
 
@@ -5,7 +5,11 @@ module CommandTimer
5
5
  attr_writer :burn_time
6
6
 
7
7
  def burn_time
8
- CommandTimer.parse_time(@burn_time)
8
+ if @burn_time =~ /[0-9]{2}:[0-9]{2}:[0-9]{2}/
9
+ CommandTimer.parse_time(@burn_time)
10
+ else
11
+ nil
12
+ end
9
13
  end
10
14
 
11
15
  def exec
@@ -8,15 +8,22 @@ module CommandTimer
8
8
  end
9
9
 
10
10
  def start
11
- @commands.each_with_index do |command|
12
- count_down_and_burn_command(command)
11
+ @commands.each_with_index do |command, index|
12
+ puts "####################"
13
+ puts "# Next: Command#{index + 1}"
14
+ puts "####################"
15
+ if command.burn_time
16
+ count_down_and_burn_command(command)
17
+ else
18
+ wait_input_to_continue(command)
19
+ end
13
20
  end
14
21
  end
15
22
 
16
23
  private
17
24
 
18
25
  def count_down_and_burn_command(command)
19
- puts "Get ready to execute next command at #{command.burn_time}."
26
+ puts "Get ready to execute the next command at [#{command.burn_time}]."
20
27
  current_time = CommandTimer.ntp_time(@ntp_server)
21
28
  left_sec = command.burn_time.to_i - current_time.to_i
22
29
  if left_sec <= 0
@@ -32,7 +39,7 @@ module CommandTimer
32
39
  current_time += 1
33
40
  left_sec -= 1
34
41
  end
35
- puts "[#{current_time}] Command will be executed in #{left_sec} second."
42
+ puts "[#{current_time}] Next command will be executed at [#{command.burn_time}] (#{left_sec} seconds left)."
36
43
  if left_sec < 1
37
44
  break
38
45
  else
@@ -46,6 +53,15 @@ module CommandTimer
46
53
  command.exec
47
54
  end
48
55
 
56
+ def wait_input_to_continue(command)
57
+ input = ""
58
+ until ["c", "C", "continue"].include?(input) do
59
+ print "Input C to execute the next command: "
60
+ input = STDIN.gets.chomp
61
+ end
62
+ command.exec
63
+ end
64
+
49
65
  def echo_commands
50
66
  @commands.each_with_index do |command, index|
51
67
  puts "--------------------"
@@ -1,3 +1,3 @@
1
1
  module CommandTimer
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_timer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -31,8 +31,7 @@ files:
31
31
  - lib/command_timer/parser.rb
32
32
  - lib/command_timer/runner.rb
33
33
  - lib/command_timer/version.rb
34
- - sample_commands.yml
35
- homepage: ''
34
+ homepage: https://github.com/cctiger36/command_timer
36
35
  licenses: []
37
36
  post_install_message:
38
37
  rdoc_options: []
data/sample_commands.yml DELETED
@@ -1,17 +0,0 @@
1
- command1:
2
- description: メンテナンス開始
3
- burn_time: "11:33:00"
4
- content: |
5
- cd ~/Documents/workspace/bm_gree/tower7
6
- ls
7
- command2:
8
- description: デプロイ
9
- burn_time: "14:10:00"
10
- content: |
11
- cap deploy ROLES=deploy
12
- cap deploy\:admin ROLES=admin
13
- command3:
14
- description: メンテナンス終了
15
- burn_time: "15:00:00"
16
- content: |
17
- cap maintenance\:nginx_end