cloudblocks 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/cloud-quartz.rb +1 -1
  2. data/lib/plugins/rotater.rb +60 -0
  3. metadata +13 -12
data/lib/cloud-quartz.rb CHANGED
@@ -21,7 +21,7 @@ class CloudQuartz
21
21
  end
22
22
 
23
23
  def unregister(agent)
24
- process(self.class.delete("/agent/#{agent}", :headers => http_headers))
24
+ process(self.class.delete("/agent/#{@agent_id}.json", :headers => http_headers))
25
25
  end
26
26
 
27
27
  def check_version
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), 'quartz_plugin')
2
+ require 'fileutils'
3
+
4
+ class Rotater < QuartzPlugin
5
+
6
+ def info
7
+ { :uid => "02f7d8237bcc438e8f0659babfef2911", :name => "File Rotater", :version => "0.0.0" }
8
+ end
9
+
10
+ def run(message)
11
+ pl = payload(message)
12
+
13
+ source_pattern = pl['source pattern']
14
+ dest_folder = pl['location']
15
+ keep = pl['keep'].nil? ? 5 : pl['keep'].to_i
16
+ post_rotate = pl['post rotate']
17
+
18
+ archive = File.join(dest_folder, '/archive')
19
+
20
+ ext = Time.now.utc.strftime('%Y%m%d%H%M%S')
21
+
22
+ FileUtils.mkdir_p(archive)
23
+ rotated = false
24
+ Dir.glob(source_pattern).each do |f|
25
+ rotated = true
26
+ fname = File.basename(f)
27
+ dest_filename = "#{fname}.#{ext}"
28
+ dest_path = File.join(archive, dest_filename)
29
+ @log.debug "Moving #{f} to #{dest_path}"
30
+
31
+ move_shell = run_shell("mv #{f} #{dest_path}")
32
+ return run_result(false, move_shell[:message]) unless move_shell[:ok]
33
+
34
+ # find all the files from this one's rotations
35
+ rotated_pattern = "#{File.join(archive, fname)}.*"
36
+ @log.debug "Looking for rotated files #{rotated_pattern}"
37
+ all_rotated = Dir.glob(rotated_pattern)
38
+ if all_rotated.count > keep
39
+ remove_count = all_rotated.count - keep
40
+ to_remote = all_rotated.sort! { |a,b| File.mtime(a) <=> File.mtime(b) }[0...remove_count]
41
+ @log.debug "Removing extra files"
42
+ to_remote.each do |tr|
43
+ @log.debug "Removing #{tr}"
44
+ remove_shell = run_shell("rm #{tr}")
45
+ return run_result(false, remove_shell[:message]) unless remove_shell[:ok]
46
+ end
47
+ end
48
+ end
49
+
50
+ if post_rotate && rotated
51
+ @log.debug "Running post rotate step #{post_rotate}"
52
+ post_shell = run_shell(post_rotate)
53
+ return run_result(false, post_shell[:message]) unless post_shell[:ok]
54
+ end
55
+
56
+ result = rotated ? "Files rotated successfully" : "No files to rotate"
57
+
58
+ run_result(true, result)
59
+ end
60
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudblocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-16 00:00:00.000000000Z
12
+ date: 2012-03-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70331935927900 !ruby/object:Gem::Requirement
16
+ requirement: &70232128687800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.8.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70331935927900
24
+ version_requirements: *70232128687800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70331935924160 !ruby/object:Gem::Requirement
27
+ requirement: &70232128687140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.6.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70331935924160
35
+ version_requirements: *70232128687140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: eventmachine
38
- requirement: &70331935922320 !ruby/object:Gem::Requirement
38
+ requirement: &70232128667840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.12.10
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70331935922320
46
+ version_requirements: *70232128667840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faye
49
- requirement: &70331935911040 !ruby/object:Gem::Requirement
49
+ requirement: &70232128667180 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.8.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70331935911040
57
+ version_requirements: *70232128667180
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: open4
60
- requirement: &70331935910460 !ruby/object:Gem::Requirement
60
+ requirement: &70232128666420 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 1.3.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70331935910460
68
+ version_requirements: *70232128666420
69
69
  description: See http://www.thecloudblocks.com for more info
70
70
  email: khash@thecloudblocks.com
71
71
  executables:
@@ -80,6 +80,7 @@ files:
80
80
  - lib/plugins/mysql.rb
81
81
  - lib/plugins/quartz_plugin.rb
82
82
  - lib/plugins/rake.rb
83
+ - lib/plugins/rotater.rb
83
84
  - lib/plugins/shell.rb
84
85
  - lib/plugins/tester.rb
85
86
  - lib/plugins/webget.rb