dronejob 1.0.5 → 1.0.6

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: 06339a1fef10bf3f164d9eff6565c05a4208c315
4
- data.tar.gz: 67b287c477a60ca2962c264d38050cbf71dc51b9
3
+ metadata.gz: 5f5df12fd8e611f67180596502d7779bfdf2256c
4
+ data.tar.gz: e6c626d975c8f4041628715085e6c7bef1ae72c4
5
5
  SHA512:
6
- metadata.gz: 4fd156af7248545a3a2cc140bc14a44ae628cd5c063c4aaa110d09ef99b6f9130e2dffe7f0d36c88f5ca458970893f621762717dbe285229545ebb2dda6f6242
7
- data.tar.gz: 4a44ffac4db1a1cef18221ad6d8b44d5bf1d9c452799b0d15e887ca519f86d06cc1dffdd05aa983bea6811dbc5c2267b028828359aa84d91094e193a521a7278
6
+ metadata.gz: c1772f75b8d08eb2b3689a344fe188f6385b9249661291453979aed9eb2ff22d3e2e65069e9c0a3efca6e0d51c80369548d00f05c750256e5041049944f2f730
7
+ data.tar.gz: f02a43b2ce9a4b512175ef085191d18e093be5540a0bbc92f2b09a721748be3a61fea62ad202372403f0ce18cb9144dadb39762fee3b5c109bae94d46e5f2553
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dronejob (1.0.5)
4
+ dronejob (1.0.6)
5
5
  activejob (~> 4.2)
6
6
  bundler (~> 1.11)
7
7
  git (~> 1.2)
data/lib/dronejob/base.rb CHANGED
@@ -11,6 +11,7 @@ require 'dronejob/modules/workspace'
11
11
 
12
12
  module Dronejob
13
13
  class Base < ActiveJob::Base
14
+ DRONEJOB_TYPE = "base"
14
15
  queue_as :dronejob
15
16
  include Modules::AttrStore
16
17
  include Modules::Core
@@ -3,7 +3,7 @@ require "active_job"
3
3
  module Dronejob
4
4
  class Command < Thor
5
5
 
6
- Dronejob::Loader.workers.each do |identifier, worker|
6
+ Dronejob::Loader.workers(:base).each do |identifier, worker|
7
7
  desc identifier, "Queue #{identifier} worker"
8
8
 
9
9
  # Pub/Sub options
@@ -56,6 +56,18 @@ module Dronejob
56
56
  end
57
57
  end
58
58
 
59
+ Dronejob::Loader.workers(:one_off).each do |identifier, worker|
60
+ desc identifier, "Run #{identifier} one-off worker"
61
+ method_option(:break, aliases: "-b", type: :boolean, default: false)
62
+ method_option(:skip, aliases: "-s", type: :array, default: [])
63
+ worker.params.each do |key, config|
64
+ method_option(key, required: config[:required], type: config[:type], default: config[:default])
65
+ end
66
+ define_method(identifier) do
67
+ worker.new.perform(options)
68
+ end
69
+ end
70
+
59
71
  desc :server, "Start Dronejob Server"
60
72
  method_option(:queue_adapter, type: :string, default: "sidekiq", enum: ["sidekiq"])
61
73
  method_option(:jobs_path, type: :string)
@@ -91,7 +103,8 @@ module Dronejob
91
103
  end
92
104
 
93
105
  desc :unarchive, "Unarchive Completed Job"
94
- archives = WorkspaceDir.new("archive").children.map{|file| file.name.gsub(/\.zip$/, "")}
106
+ archives_dir = WorkspaceDir.new("archive")
107
+ archives = archives_dir.exists? ? archives_dir.children.map{|file| file.name.gsub(/\.zip$/, "")} : []
95
108
  method_option(:archive, type: :string, required: true, enum: archives)
96
109
  method_option(:force, aliases: "-f", type: :boolean, default: false)
97
110
  def unarchive
@@ -19,8 +19,10 @@ module Dronejob
19
19
  self.workers.key(worker.class)
20
20
  end
21
21
 
22
- def self.workers
22
+ def self.workers(type="base")
23
+ type = type.to_s
23
24
  @@workers ||= load
25
+ result = @@workers.select{|key, worker| worker::DRONEJOB_TYPE == type}
24
26
  end
25
27
  end
26
28
  end
@@ -33,44 +33,6 @@ module Dronejob
33
33
  def asset_file(path)
34
34
  WorkspaceDir.new("app/assets").file(path)
35
35
  end
36
-
37
- # def file_replace_contents(target_path, &block)
38
- # binding.pry
39
- # contents = File.open(target_path).read
40
- # contents = block.call(contents)
41
- # file_write(target_path, contents)
42
- # end
43
- #
44
- # def file_delete_path(*args)
45
- # binding.pry
46
- # path = File.join(*args)
47
- # FileUtils.rm_rf(path)
48
- # path
49
- # end
50
- #
51
- # def file_parse_haml(haml_path, output_path, options={})
52
- # binding.pry
53
- # engine = Haml::Engine.new(haml_path)
54
- # open(output_path, 'wb') do |file|
55
- # file << engine.render(Object.new, options)
56
- # end
57
- # end
58
- #
59
- # def file_root_dir
60
- # binding.pry
61
- # File.expand_path("../../../", __FILE__)
62
- # end
63
- #
64
- # def file_data_path(target_path)
65
- # binding.pry
66
- # File.join(Gem.datadir("app-drone"), target_path)
67
- # end
68
- #
69
- # def file_data_contents(target_path)
70
- # binding.pry
71
- # path = file_data_path(target_path)
72
- # File.open(path).read
73
- # end
74
36
  end
75
37
  end
76
38
  end
@@ -0,0 +1,77 @@
1
+ require "active_job"
2
+ require 'dronejob/modules/core'
3
+ require 'dronejob/modules/log'
4
+ require 'dronejob/modules/options'
5
+ require 'dronejob/modules/params'
6
+ require 'dronejob/modules/phases'
7
+
8
+ module Dronejob
9
+ class OneOff
10
+ DRONEJOB_TYPE = "one_off"
11
+ include Modules::Core
12
+ include Modules::Log
13
+ include Modules::Options
14
+ include Modules::Params
15
+ include Modules::Phases
16
+
17
+ def perform(params)
18
+ @params = params
19
+ validate_parameters!
20
+
21
+ # Run through phases
22
+ each_phase do |phase, config|
23
+ begin
24
+ phase_result = public_send(phase)
25
+ rescue Exception => e
26
+ error(e.message)
27
+ error(e.backtrace.join("\n"))
28
+ return false
29
+ end
30
+ end
31
+ end
32
+
33
+ def each_phase(&block)
34
+ self.class.phases.each do |phase, config|
35
+ fail "Phase not found: '#{phase}'" unless self.respond_to?(phase)
36
+ @phase = phase
37
+ before_phase(phase, config) if self.respond_to?(:before_phase)
38
+
39
+ logger.tagged(phase) do
40
+ if completed_phase?(phase) and !config[:always_run]
41
+ info("already completed")
42
+ elsif skip_phase?(phase)
43
+ info("skipping...")
44
+ else
45
+ # Require libraries
46
+ if !config[:require].nil?
47
+ config[:require].each do |library|
48
+ require library
49
+ end
50
+ end
51
+
52
+ # Include helpers
53
+ if !config[:helpers].nil?
54
+ config[:helpers].each do |helper|
55
+ helper_path = "helpers/#{helper}"
56
+ require "./app/#{helper_path}"
57
+ self.class.include helper_path.camelcase.constantize
58
+ end
59
+ end
60
+
61
+ block.call(phase, config)
62
+ end
63
+ end
64
+
65
+ after_phase(phase, config) if self.respond_to?(:after_phase)
66
+ end
67
+
68
+ info("JOB COMPLETED")
69
+ end
70
+
71
+ def completed_phase?(phase)
72
+ false
73
+ end
74
+
75
+ ActiveSupport.run_load_hooks(:dronejob, self)
76
+ end
77
+ end
@@ -1,3 +1,3 @@
1
1
  module Dronejob
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
@@ -92,7 +92,6 @@ module Dronejob
92
92
  end
93
93
  return self
94
94
  rescue StandardError => e
95
- binding.pry
96
95
  return false
97
96
  end
98
97
 
data/lib/dronejob.rb CHANGED
@@ -7,5 +7,6 @@ require 'dronejob/railtie' if defined?(Rails)
7
7
  module Dronejob
8
8
  extend ActiveSupport::Autoload
9
9
  autoload :Base
10
+ autoload :OneOff
10
11
  autoload :Loader
11
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dronejob
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Strebitzer
@@ -205,6 +205,7 @@ files:
205
205
  - lib/dronejob/modules/phases.rb
206
206
  - lib/dronejob/modules/queue.rb
207
207
  - lib/dronejob/modules/workspace.rb
208
+ - lib/dronejob/one_off.rb
208
209
  - lib/dronejob/railtie.rb
209
210
  - lib/dronejob/railties/dronejob.rake
210
211
  - lib/dronejob/server/sidekiq.rb
@@ -231,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
232
  version: '2.4'
232
233
  requirements: []
233
234
  rubyforge_project:
234
- rubygems_version: 2.4.5.1
235
+ rubygems_version: 2.6.3
235
236
  signing_key:
236
237
  specification_version: 4
237
238
  summary: DroneJob Drone Factory