dronejob 1.0.4 → 1.0.5

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: 228486e1f34d82c4c9383f275f2747fec2bb87a3
4
- data.tar.gz: 7f54c109f367a215126f247e28ed3b771871fd34
3
+ metadata.gz: 06339a1fef10bf3f164d9eff6565c05a4208c315
4
+ data.tar.gz: 67b287c477a60ca2962c264d38050cbf71dc51b9
5
5
  SHA512:
6
- metadata.gz: e91a7bc50704804be80cb4eb41ce79a89945a40eb103788c55ee4ab566d8a8e19c6314998699b78ca855cb10ddfa695f3fbcfdff6e53acde6c4f5cc4f2d9e152
7
- data.tar.gz: bea2eb4c05e8fbef73f98c60c2af2b2ca14aee6c0ad6ccf3c7f15e78dd45e3857fceb44078d9a759fd58a87f296e9e6aae496be6dfd735bcb2795e98d38e2b85
6
+ metadata.gz: 4fd156af7248545a3a2cc140bc14a44ae628cd5c063c4aaa110d09ef99b6f9130e2dffe7f0d36c88f5ca458970893f621762717dbe285229545ebb2dda6f6242
7
+ data.tar.gz: 4a44ffac4db1a1cef18221ad6d8b44d5bf1d9c452799b0d15e887ca519f86d06cc1dffdd05aa983bea6811dbc5c2267b028828359aa84d91094e193a521a7278
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  app/*
3
3
  tmp/*
4
4
  plugins/*
5
+ /archive/*
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dronejob (1.0.4)
4
+ dronejob (1.0.5)
5
5
  activejob (~> 4.2)
6
6
  bundler (~> 1.11)
7
7
  git (~> 1.2)
@@ -69,5 +69,43 @@ module Dronejob
69
69
  Dronejob::Base.run_worker!
70
70
  end
71
71
 
72
+ desc :archive, "Archive Completed Jobs"
73
+ method_option(:force, aliases: "-f", type: :boolean, default: false)
74
+ def archive
75
+ archive_dir = WorkspaceDir.new("archive")
76
+ archive_dir.create
77
+ WorkspaceDir.new("tmp/jobs").each_dir do |dir|
78
+ dronejob_variables = dir.file("dronejob.yml").read_yaml
79
+ if dronejob_variables[:dronejob_completed] == true
80
+ Dronejob::Base.log("info", "Archiving #{dir.name}")
81
+ archive_file = archive_dir.file("#{dir.name}.zip")
82
+ if archive_file.exists? and !options.force
83
+ Dronejob::Base.log("error", "Error: Archive '#{archive_file.full_path}' already exists. Use --force to replace.")
84
+ else
85
+ archive_file.delete! if archive_file.exists?
86
+ dir.compress(archive_file)
87
+ dir.delete!
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ desc :unarchive, "Unarchive Completed Job"
94
+ archives = WorkspaceDir.new("archive").children.map{|file| file.name.gsub(/\.zip$/, "")}
95
+ method_option(:archive, type: :string, required: true, enum: archives)
96
+ method_option(:force, aliases: "-f", type: :boolean, default: false)
97
+ def unarchive
98
+ archives_dir = WorkspaceDir.new("archive")
99
+ archive_file = archives_dir.file("#{options.archive}.zip")
100
+ Dronejob::Base.log("info", "Unarchiving '#{archive_file.full_path}'")
101
+ target_dir = WorkspaceDir.new("tmp/jobs").dir(options.archive)
102
+ if !options.force and target_dir.exists?
103
+ Dronejob::Base.log("error", "Error: Job directory already exists")
104
+ else
105
+ target_dir.delete! if target_dir.exists?
106
+ archive_file.extract(target_dir)
107
+ end
108
+ end
109
+
72
110
  end
73
111
  end
@@ -9,12 +9,12 @@ module Dronejob
9
9
 
10
10
  module ClassMethods
11
11
  def attr_store(*args)
12
- @attr_stores ||= []
12
+ @attr_stores ||= [:dronejob_completed]
13
13
  @attr_stores.push(*args)
14
14
  end
15
15
 
16
16
  def attr_stores
17
- @attr_stores ||= []
17
+ @attr_stores ||= [:dronejob_completed]
18
18
  end
19
19
  end
20
20
 
@@ -52,6 +52,10 @@ module Dronejob
52
52
 
53
53
  after_phase(phase, config) if self.respond_to?(:after_phase)
54
54
  end
55
+
56
+ @dronejob_completed = true
57
+ git_commit("dronejob_completed")
58
+ info("JOB COMPLETED")
55
59
  end
56
60
 
57
61
  def completed_phase?(phase)
@@ -1,3 +1,3 @@
1
1
  module Dronejob
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -7,6 +7,10 @@ module Dronejob
7
7
  @path = path
8
8
  end
9
9
 
10
+ def name
11
+ File.basename(full_path)
12
+ end
13
+
10
14
  def full_path
11
15
  File.join(@workspace, @path)
12
16
  end
@@ -31,5 +35,31 @@ module Dronejob
31
35
  def dir(dir_path)
32
36
  WorkspaceDir.new(@workspace, File.join(@path, dir_path))
33
37
  end
38
+
39
+ def compress(target_file)
40
+ target_file.delete!
41
+ Zip::File.open(target_file.full_path, 'w') do |zipfile|
42
+ Dir["#{full_path}/**/**"].each do |file|
43
+ zipfile.add(file.sub("#{full_path}/",''), file)
44
+ end
45
+ end
46
+ self
47
+ end
48
+
49
+ def children
50
+ entries = []
51
+ Dir.chdir(full_path) do
52
+ Dir["*"].each do |path|
53
+ entries.push(dir(path))
54
+ end
55
+ end
56
+ entries
57
+ end
58
+
59
+ def each_dir(&block)
60
+ children.each do |subdir|
61
+ block.call(subdir)
62
+ end
63
+ end
34
64
  end
35
65
  end
@@ -120,5 +120,8 @@ module Dronejob
120
120
  WorkspaceDir.new(@workspace, File.dirname(@path))
121
121
  end
122
122
 
123
+ def delete!
124
+ FileUtils.rm_f(full_path)
125
+ end
123
126
  end
124
127
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dronejob
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Strebitzer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-24 00:00:00.000000000 Z
11
+ date: 2016-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler