notifyme 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,11 +10,11 @@ gem install notifyme
10
10
 
11
11
  # run in the background
12
12
 
13
- $ notifyme_daemon start --(double dash here) /path/to/notifyme_config.rb
13
+ $ notifyme_daemon start --(double dash here) /absolute/path/to/notifyme_config.rb
14
14
 
15
15
  # debug (use Ctrl + C to stop it)
16
16
 
17
- $ notifyme_daemon run --(double dash here) /path/to/notifyme_config.rb
17
+ $ notifyme_daemon run --(double dash here) /absolute/path/to/notifyme_config.rb
18
18
 
19
19
  # stop
20
20
 
@@ -30,7 +30,7 @@ The output from every task's command will be processed (send to endpoint) only i
30
30
 
31
31
  == Version
32
32
 
33
- v 0.2
33
+ v 0.3
34
34
 
35
35
  == Author
36
36
 
@@ -1,9 +1,9 @@
1
- module NotifyMe
1
+ require 'notifyme/task'
2
+ require 'notifyme/log'
2
3
 
3
- VERSION = '0.1'
4
+ module NotifyMe
4
5
 
5
- autoload :Task, 'notifyme/task'
6
- autoload :Log, 'notifyme/log'
6
+ VERSION = '0.3'
7
7
 
8
8
  class Start
9
9
  class << self
@@ -11,6 +11,7 @@ module NotifyMe
11
11
  # log
12
12
  @@log_args = nil
13
13
  @@log_format = nil
14
+ @@log_directory = nil
14
15
 
15
16
  # tasks list
16
17
  @@tasks = []
@@ -28,7 +29,7 @@ module NotifyMe
28
29
 
29
30
  def task(name)
30
31
  raise 'Invalid task calls' unless block_given?
31
- task = Task.new
32
+ task = NotifyMe::Task.new
32
33
  task.name = name
33
34
  task.logger ||= NotifyMe::Log::Base.new(@@log_args).logger
34
35
  task.log_format ||= @@log_format
@@ -43,6 +44,11 @@ module NotifyMe
43
44
  def log_format(format)
44
45
  @@log_format = format
45
46
  end
47
+
48
+ def log_directory(directory)
49
+ FileUtils.mkdir_p directory unless File.directory? directory
50
+ @@log_directory = directory
51
+ end
46
52
  end
47
53
 
48
54
  def run
@@ -69,6 +75,7 @@ module NotifyMe
69
75
  task.result = task.command.call
70
76
  task.end_run_time = Time.now.to_i
71
77
  rescue Exception => e
78
+ log_error task.name, task.command, e.to_s
72
79
  task.result = e.to_s
73
80
  end
74
81
 
@@ -76,7 +83,11 @@ module NotifyMe
76
83
  return if task.result.to_s.empty?
77
84
 
78
85
  # restart the command if need
79
- task.restart_command.call if task.restart_command
86
+ begin
87
+ task.restart_command.call if task.restart_command
88
+ rescue Exception => e
89
+ log_error task.name, task.restart_command, e.to_s
90
+ end
80
91
 
81
92
  @mutex.synchronize do
82
93
  begin
@@ -87,6 +98,14 @@ module NotifyMe
87
98
  end
88
99
  end
89
100
 
101
+ def log_error(task_name, command, msg)
102
+ return if @@log_directory.nil?
103
+ log_file = File.join(@@log_directory, '/', "#{task_name}.log")
104
+ File.open(log_file, 'a') do |f|
105
+ f.write "(#{Time.new.to_s}) #{command} : #{msg}\n"
106
+ end
107
+ end
108
+
90
109
  def initialize(config_file)
91
110
  require config_file
92
111
  end
data/lib/notifyme.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'rubygems'
2
2
  require 'thread'
3
+ require 'fileutils'
3
4
  require 'notifyme/start'
data/notifyme_config.rb CHANGED
@@ -29,16 +29,18 @@ NotifyMe::Start.config do
29
29
  # :csv, :text, :xml, :json
30
30
  log_format :json
31
31
 
32
+ # log_directory '/tmp/notifyme'
33
+
32
34
  # add some tasks
33
35
 
34
36
  task :checking_disk do |t|
35
- t.sleep_time = 1
37
+ t.sleep_time = 3
36
38
  t.command = Proc.new { %x{df -h} }
37
39
  end
38
40
 
39
- task :checking_http do |t|
41
+ task :checking_date do |t|
40
42
  t.sleep_time = 2
41
43
  t.command = MyTask
42
- t.restart_command = lambda { puts "restarted !" }
44
+ t.restart_command = Proc.new { %x{dates} }
43
45
  end
44
46
  end
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- version: "0.2"
7
+ - 3
8
+ version: "0.3"
9
9
  platform: ruby
10
10
  authors:
11
11
  - xianhua.zhou
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2010-11-06 00:00:00 +08:00
16
+ date: 2010-11-17 00:00:00 +08:00
17
17
  default_executable: notifyme_daemon
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
@@ -56,13 +56,13 @@ extensions: []
56
56
  extra_rdoc_files: []
57
57
 
58
58
  files:
59
- - lib/notifyme/task.rb
60
- - lib/notifyme/start.rb
59
+ - lib/vendor/smtp_add_tls_support.rb
60
+ - lib/notifyme/log/stdout.rb
61
61
  - lib/notifyme/log/mail.rb
62
62
  - lib/notifyme/log/file.rb
63
- - lib/notifyme/log/stdout.rb
63
+ - lib/notifyme/task.rb
64
+ - lib/notifyme/start.rb
64
65
  - lib/notifyme/log.rb
65
- - lib/vendor/smtp_add_tls_support.rb
66
66
  - lib/notifyme.rb
67
67
  - README.rdoc
68
68
  - CHANGELOG