hq-tools 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ module HQ
2
+ module Tools
3
+ module Cron
4
+
5
+ def self.wrap log = nil
6
+
7
+ is_tty = $stderr.tty?
8
+
9
+ if log
10
+ log = String.new log
11
+ log.gsub! /@ts(@|\b)/, Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
12
+ log.gsub! /@pid(@|\b)/, $$.to_s
13
+ else
14
+ require "tempfile"
15
+ temp = Tempfile.new "hq-cron-"
16
+ log = temp.path
17
+ end
18
+
19
+ begin
20
+
21
+ caught_exception = nil
22
+
23
+ unless is_tty
24
+ stdout_saved = $stdout.dup unless is_tty
25
+ stderr_saved = $stderr.dup unless is_tty
26
+ $stdout.reopen log, "a" unless is_tty
27
+ $stderr.reopen log, "a" unless is_tty
28
+ end
29
+
30
+ begin
31
+ yield log
32
+ rescue => e
33
+ caught_exception = e
34
+ end
35
+ $stdout.flush unless is_tty
36
+ $stderr.flush unless is_tty
37
+
38
+ $stdout.reopen stdout_saved unless is_tty
39
+ $stderr.reopen stderr_saved unless is_tty
40
+ stdout_saved.close unless is_tty
41
+ stderr_saved.close unless is_tty
42
+
43
+ if caught_exception
44
+ system "cat #{log} >&2" unless is_tty
45
+ $stderr.puts "Caught #{caught_exception.class}: #{caught_exception.message}"
46
+ $stderr.puts caught_exception.backtrace.join "\n"
47
+ end
48
+
49
+ ensure
50
+ temp.unlink if temp
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,23 @@
1
+ require "hq/tools/cron"
2
+
3
+ module HQ
4
+ module Tools
5
+
6
+ describe Cron do
7
+
8
+ context "#wrap" do
9
+
10
+ it "calls the provided block" do
11
+ called = false
12
+ subject.wrap do
13
+ called = true
14
+ end
15
+ called.should == true
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hq-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-15 00:00:00.000000000 Z
12
+ date: 2013-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
@@ -99,9 +99,11 @@ extensions: []
99
99
  extra_rdoc_files: []
100
100
  files:
101
101
  - lib/hq/tools/getopt.rb
102
+ - lib/hq/tools/cron.rb
102
103
  - lib/hq/tools/escape.rb
103
104
  - lib/hq/tools/check-script.rb
104
105
  - spec/hq/tools/getopt-spec.rb
106
+ - spec/hq/tools/cron-spec.rb
105
107
  - spec/hq/tools/check-script-spec.rb
106
108
  homepage: https://github.com/jamespharaoh/hq-tools
107
109
  licenses: []
@@ -129,4 +131,5 @@ specification_version: 3
129
131
  summary: HQ tools
130
132
  test_files:
131
133
  - spec/hq/tools/getopt-spec.rb
134
+ - spec/hq/tools/cron-spec.rb
132
135
  - spec/hq/tools/check-script-spec.rb