dronejob 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -7
- data/README.md +20 -1
- data/bin/dronejob +0 -10
- data/dronejob.gemspec +0 -3
- data/lib/active_job/queue_adapters/dronejob_queue_adapter.rb +19 -0
- data/lib/dronejob/base.rb +3 -0
- data/lib/dronejob/command.rb +40 -17
- data/lib/dronejob/loader.rb +8 -6
- data/lib/dronejob/modules/attr_store.rb +1 -1
- data/lib/dronejob/modules/core.rb +3 -7
- data/lib/dronejob/modules/git.rb +2 -2
- data/lib/dronejob/modules/log.rb +48 -11
- data/lib/dronejob/modules/params.rb +2 -1
- data/lib/dronejob/modules/phases.rb +10 -8
- data/lib/dronejob/modules/pub_sub.rb +60 -0
- data/lib/dronejob/modules/workspace.rb +4 -2
- data/lib/dronejob/railtie.rb +26 -0
- data/lib/dronejob/railties/dronejob.rake +6 -0
- data/lib/dronejob/version.rb +1 -1
- data/lib/dronejob.rb +4 -1
- metadata +6 -46
- data/lib/active_job/queue_adapters/pub_sub_queue_adapter.rb +0 -76
- data/lib/dronejob/logger.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cae818f5050ff58791380e627c546e63efdddca
|
4
|
+
data.tar.gz: 1131b202e4e2edf76fecfd6367003bc93d85baac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0c6d490e93388f63e4bf6a19e3ff87d5f711408b12902554f8a5deecb3e4bbdaeb9cf28b8e874e9ffab8c8355e71bd3886612b7c5e1dbca21a95b5d158d1b9d
|
7
|
+
data.tar.gz: 24e8e35a177f6130e02f5acefde34bfb96e530246cb25880e7d679c4ae65ce25462ceebe78862747ce877e1253603fdcb4cd7f5d596b2f752c300846cd84e1bf
|
data/.gitignore
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
/*.gem
|
2
|
-
|
3
|
-
|
2
|
+
app/*
|
3
|
+
tmp/*
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -13,14 +13,11 @@ GIT
|
|
13
13
|
PATH
|
14
14
|
remote: .
|
15
15
|
specs:
|
16
|
-
dronejob (1.0.
|
16
|
+
dronejob (1.0.2)
|
17
17
|
activejob (~> 4.2)
|
18
18
|
bundler (~> 1.11)
|
19
19
|
gcloud (~> 0.6)
|
20
20
|
git (~> 1.2)
|
21
|
-
google-api-client (~> 0.8)
|
22
|
-
logging (~> 2.0)
|
23
|
-
logging-google-cloud (~> 1.0)
|
24
21
|
rake (~> 10.5)
|
25
22
|
thor (~> 0.19)
|
26
23
|
|
@@ -79,9 +76,6 @@ GEM
|
|
79
76
|
logging (2.0.0)
|
80
77
|
little-plugger (~> 1.1)
|
81
78
|
multi_json (~> 1.10)
|
82
|
-
logging-google-cloud (1.0.2)
|
83
|
-
gcloud (~> 0.6)
|
84
|
-
logging (~> 2.0)
|
85
79
|
memoist (0.14.0)
|
86
80
|
method_source (0.8.2)
|
87
81
|
mime-types (2.99)
|
data/README.md
CHANGED
@@ -6,4 +6,23 @@ Scalable worker factory for ruby
|
|
6
6
|
|
7
7
|
Install gems:
|
8
8
|
|
9
|
-
|
9
|
+
$ gem install dronejob
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
|
14
|
+
### Logging
|
15
|
+
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
# Create stdout logger
|
19
|
+
require "logging"
|
20
|
+
Logging.color_scheme("bright", levels: { debug: :blue, info: :green, warn: :yellow, error: :red, fatal: [:white, :on_red] }, date: :blue, ndc: :blue, logger: :cyan, message: :black)
|
21
|
+
Dronejob::Base.logger = Logging::Logger.new("Dronejob").add_appenders(Logging::Appenders::Stdout.new("stdout", {layout: Logging.layouts.pattern({pattern: '[%d] %-5l %c{1} %x %m\n', color_scheme: 'bright'})}))
|
22
|
+
|
23
|
+
# Create gcl logger
|
24
|
+
require "logging"
|
25
|
+
require "logging/appenders/gcl"
|
26
|
+
Logging.init(Logging::Appenders::GoogleCloudLogging::SEVERITY_NAMES)
|
27
|
+
Dronejob::Base.logger = Logging::Logger.new("Dronejob").add_appenders(Logging::Appenders::GoogleCloudLogging.new("gcl", {project_id: "project-id", log_name: "dronejob", resource_type: "gce_instance", resource_labels: {instance_id: "instance-id", zone: "us-central1-b"}, buffer_size: '3', immediate_at: 'error, fatal'}))
|
28
|
+
```
|
data/bin/dronejob
CHANGED
@@ -1,17 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$:.push("lib/")
|
3
|
-
# require "pry"
|
4
3
|
require "thor"
|
5
4
|
|
6
|
-
# initialize activejob
|
7
|
-
require "dronejob"
|
8
|
-
require "active_job"
|
9
|
-
require "active_job/queue_adapters/pub_sub_queue_adapter"
|
10
|
-
ActiveJob::Base.queue_adapter = :pub_sub_queue
|
11
|
-
ActiveJob::Base.logger = Dronejob::Logger.logger
|
12
|
-
|
13
5
|
# initialize dronejob
|
14
|
-
Dronejob::Loader.init
|
15
|
-
|
16
6
|
require "dronejob/command"
|
17
7
|
Dronejob::Command.start
|
data/dronejob.gemspec
CHANGED
@@ -17,12 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_runtime_dependency "bundler", "~> 1.11"
|
18
18
|
s.add_runtime_dependency "rake", "~> 10.5"
|
19
19
|
s.add_runtime_dependency "git", "~> 1.2"
|
20
|
-
s.add_runtime_dependency "logging", "~> 2.0"
|
21
20
|
s.add_runtime_dependency "thor", "~> 0.19"
|
22
21
|
s.add_runtime_dependency "activejob", "~> 4.2"
|
23
|
-
s.add_runtime_dependency "logging-google-cloud", "~> 1.0"
|
24
22
|
s.add_runtime_dependency "gcloud", "~> 0.6"
|
25
|
-
s.add_runtime_dependency "google-api-client", "~> 0.8"
|
26
23
|
s.add_development_dependency "rspec", "~> 3.3"
|
27
24
|
s.add_development_dependency "pry", "~> 0.10"
|
28
25
|
s.files = `git ls-files`.split("\n")
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "gcloud"
|
2
|
+
module ActiveJob
|
3
|
+
module QueueAdapters
|
4
|
+
class DronejobQueueAdapter
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def enqueue(job)
|
8
|
+
Dronejob::Base.log("info", "Enqueuing worker #{job.class.name} with job id #{job.job_id}")
|
9
|
+
Dronejob::Base.publish_job(job)
|
10
|
+
end
|
11
|
+
|
12
|
+
def enqueue_at(*)
|
13
|
+
raise NotImplementedError.new("Delayed execution is not supported on Google Cloud Pub Sub.")
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/dronejob/base.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
require "active_job"
|
1
2
|
require 'dronejob/modules/attr_store'
|
2
3
|
require 'dronejob/modules/core'
|
3
4
|
require 'dronejob/modules/git'
|
4
5
|
require 'dronejob/modules/log'
|
5
6
|
require 'dronejob/modules/params'
|
6
7
|
require 'dronejob/modules/phases'
|
8
|
+
require 'dronejob/modules/pub_sub'
|
7
9
|
require 'dronejob/modules/workspace'
|
8
10
|
|
9
11
|
module Dronejob
|
@@ -14,6 +16,7 @@ module Dronejob
|
|
14
16
|
include Modules::Log
|
15
17
|
include Modules::Params
|
16
18
|
include Modules::Phases
|
19
|
+
include Modules::PubSub
|
17
20
|
include Modules::Workspace
|
18
21
|
|
19
22
|
ActiveSupport.run_load_hooks(:dronejob, self)
|
data/lib/dronejob/command.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "dronejob"
|
2
|
+
require "active_job"
|
1
3
|
module Dronejob
|
2
4
|
class Command < Thor
|
3
5
|
|
@@ -6,8 +8,9 @@ module Dronejob
|
|
6
8
|
|
7
9
|
# Pub/Sub options
|
8
10
|
method_option(:project_id, type: :string, required: true)
|
9
|
-
method_option(:queue_topic, type: :string, required:
|
10
|
-
method_option(:status_topic, type: :string, required:
|
11
|
+
method_option(:queue_topic, type: :string, required: false)
|
12
|
+
method_option(:status_topic, type: :string, required: false)
|
13
|
+
method_option(:queue_adapter, type: :string, default: "dronejob_queue")
|
11
14
|
|
12
15
|
# Worker options
|
13
16
|
method_option(:run, aliases: "-r", type: :boolean, default: false)
|
@@ -15,6 +18,9 @@ module Dronejob
|
|
15
18
|
method_option(:skip, aliases: "-s", type: :array, default: [])
|
16
19
|
method_option(:from, aliases: "-f", type: :string)
|
17
20
|
method_option(:listen, aliases: "-l", type: :boolean, default: false)
|
21
|
+
method_option(:notify, aliases: "-n", type: :boolean, default: true)
|
22
|
+
method_option(:jobs_path, type: :string)
|
23
|
+
method_option(:output_path, type: :string)
|
18
24
|
|
19
25
|
# Worker options
|
20
26
|
worker.params.each do |key, config|
|
@@ -22,22 +28,33 @@ module Dronejob
|
|
22
28
|
end
|
23
29
|
|
24
30
|
define_method(identifier) do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
ActiveJob::Base.queue_adapter = options.queue_adapter
|
32
|
+
Dronejob::Base.project_id = options.project_id
|
33
|
+
Dronejob::Base.queue_topic = options.queue_topic if options.queue_topic
|
34
|
+
Dronejob::Base.status_topic = options.status_topic if options.status_topic
|
35
|
+
Dronejob::Base.jobs_path = options.jobs_path if options.jobs_path
|
36
|
+
Dronejob::Base.output_path = options.output_path if options.output_path
|
29
37
|
|
30
38
|
# Execute / queue job
|
31
39
|
if options.run
|
32
|
-
worker.perform_now(options
|
40
|
+
worker.perform_now(options)
|
33
41
|
else
|
34
42
|
job = worker.perform_later(options.to_hash)
|
35
43
|
|
36
44
|
# Listen for notifications
|
37
45
|
if options.listen
|
38
|
-
|
39
|
-
Dronejob::
|
40
|
-
|
46
|
+
if options.run or !options.notify
|
47
|
+
Dronejob::Base.log("error", "Unable to listen to a jobs that '--run' instantly, or with '--no-notify' set")
|
48
|
+
else
|
49
|
+
Dronejob::Base.subscribe(Dronejob::Base.status_topic, true) do |data|
|
50
|
+
if data["job_id"] == job.job_id
|
51
|
+
Dronejob::Base.log("info", "status: #{data["detail"].to_json}")
|
52
|
+
if data["detail"]["phase"] == "complete"
|
53
|
+
Dronejob::Base.log("info", "job completed")
|
54
|
+
Kernel.exit
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
41
58
|
end
|
42
59
|
end
|
43
60
|
|
@@ -46,17 +63,23 @@ module Dronejob
|
|
46
63
|
end
|
47
64
|
|
48
65
|
desc :server, "Start Dronejob Server"
|
66
|
+
method_option(:queue_adapter, type: :string, default: "dronejob_queue", enum: ["dronejob_queue"])
|
49
67
|
method_option(:project_id, type: :string, required: true)
|
50
|
-
method_option(:queue_topic, type: :string, required:
|
51
|
-
method_option(:status_topic, type: :string, required:
|
68
|
+
method_option(:queue_topic, type: :string, required: false)
|
69
|
+
method_option(:status_topic, type: :string, required: false)
|
70
|
+
method_option(:jobs_path, type: :string)
|
71
|
+
method_option(:output_path, type: :string)
|
52
72
|
def server
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
73
|
+
ActiveJob::Base.queue_adapter = options.queue_adapter
|
74
|
+
Dronejob::Base.project_id = options.project_id
|
75
|
+
Dronejob::Base.queue_topic = options.queue_topic if options.queue_topic
|
76
|
+
Dronejob::Base.status_topic = options.status_topic if options.status_topic
|
77
|
+
Dronejob::Base.jobs_path = options.jobs_path if options.jobs_path
|
78
|
+
Dronejob::Base.output_path = options.output_path if options.output_path
|
57
79
|
|
58
80
|
# Run worker
|
59
|
-
|
81
|
+
Dronejob::Base.log("info", "Subscribing to topic #{Dronejob::Base.queue_topic} in project #{Dronejob::Base.project_id}")
|
82
|
+
Dronejob::Base.run_worker!
|
60
83
|
end
|
61
84
|
|
62
85
|
end
|
data/lib/dronejob/loader.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
module Dronejob
|
2
2
|
module Loader
|
3
|
-
@@workers =
|
3
|
+
@@workers = nil
|
4
4
|
|
5
|
-
def self.
|
5
|
+
def self.load
|
6
6
|
require "active_support/all"
|
7
|
-
|
7
|
+
workers = {}
|
8
|
+
Dir["#{Dronejob::Base.jobs_path}/*.rb"].each do |file|
|
8
9
|
require "./#{file}"
|
9
10
|
identifier = File.basename(file).gsub(/\.rb$/, "")
|
10
|
-
klassname =
|
11
|
+
klassname = identifier.camelcase
|
11
12
|
klass = klassname.constantize
|
12
|
-
|
13
|
+
workers[identifier] = klass
|
13
14
|
end
|
15
|
+
workers
|
14
16
|
end
|
15
17
|
|
16
18
|
def self.identifier_for(worker)
|
@@ -18,7 +20,7 @@ module Dronejob
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def self.workers
|
21
|
-
@@workers
|
23
|
+
@@workers ||= load
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -19,23 +19,19 @@ module Dronejob
|
|
19
19
|
begin
|
20
20
|
phase_result = public_send(phase)
|
21
21
|
rescue Exception => e
|
22
|
-
error
|
22
|
+
error(e)
|
23
23
|
end
|
24
|
-
|
24
|
+
publish_status(phase_result) if config[:notify]
|
25
25
|
git_commit(phase)
|
26
26
|
end
|
27
27
|
@phase = "complete"
|
28
|
-
|
28
|
+
publish_status(true) if param(:notify) and !param(:run)
|
29
29
|
end
|
30
30
|
|
31
31
|
def uuid
|
32
32
|
@uuid ||= "#{self.class.name.split('::').last.underscore}_#{SecureRandom.uuid}"
|
33
33
|
end
|
34
34
|
|
35
|
-
def notify(result=nil)
|
36
|
-
ActiveJob::QueueAdapters::PubSubQueueAdapter.notify(self, {phase: @phase, result: result})
|
37
|
-
end
|
38
|
-
|
39
35
|
def shell
|
40
36
|
@shell ||= Thor::Shell::Color.new
|
41
37
|
end
|
data/lib/dronejob/modules/git.rb
CHANGED
@@ -46,9 +46,9 @@ module Dronejob
|
|
46
46
|
|
47
47
|
def git_reset(commit=nil)
|
48
48
|
if commit
|
49
|
-
|
49
|
+
info("resetting to phase '#{commit}'")
|
50
50
|
from_index = @commits.keys.index(commit)
|
51
|
-
error
|
51
|
+
error("phase '#{commit}' not found!") if from_index.nil? or !@commits.keys[from_index]
|
52
52
|
previous = @commits.keys[from_index]
|
53
53
|
@git.reset_hard(@commits[previous])
|
54
54
|
else
|
data/lib/dronejob/modules/log.rb
CHANGED
@@ -1,22 +1,59 @@
|
|
1
|
+
require 'active_support/tagged_logging'
|
2
|
+
require 'active_support/logger'
|
1
3
|
module Dronejob
|
2
4
|
module Modules
|
3
5
|
module Log
|
4
6
|
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
|
8
|
+
included do
|
9
|
+
cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
|
14
|
+
def log(level, message, phase=:global)
|
15
|
+
if !logger.nil?
|
16
|
+
logger.send(level, message)
|
17
|
+
else
|
18
|
+
puts "#{level}: [#{phase}] #{message}"
|
13
19
|
end
|
14
|
-
abort "EXIT"
|
15
20
|
end
|
16
21
|
end
|
17
22
|
|
18
|
-
def
|
19
|
-
log(message,
|
23
|
+
def log(level, message)
|
24
|
+
self.class.log(level, message, @phase)
|
25
|
+
end
|
26
|
+
|
27
|
+
def debug(message)
|
28
|
+
log(:debug, message)
|
29
|
+
end
|
30
|
+
|
31
|
+
def info(message)
|
32
|
+
log(:info, message)
|
33
|
+
end
|
34
|
+
|
35
|
+
def notice(message)
|
36
|
+
log(:notice, message)
|
37
|
+
end
|
38
|
+
|
39
|
+
def warning(message)
|
40
|
+
log(:warning, message)
|
41
|
+
end
|
42
|
+
|
43
|
+
def error(message)
|
44
|
+
log(:error, message)
|
45
|
+
end
|
46
|
+
|
47
|
+
def critical(message)
|
48
|
+
log(:critical, message)
|
49
|
+
end
|
50
|
+
|
51
|
+
def alert(message)
|
52
|
+
log(:alert, message)
|
53
|
+
end
|
54
|
+
|
55
|
+
def emergency(message)
|
56
|
+
log(:emergency, message)
|
20
57
|
end
|
21
58
|
|
22
59
|
end
|
@@ -23,15 +23,17 @@ module Dronejob
|
|
23
23
|
fail "Phase not found: '#{phase}'" unless self.respond_to?(phase)
|
24
24
|
@phase = phase
|
25
25
|
before_phase(phase, config) if self.respond_to?(:before_phase)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
|
27
|
+
logger.tagged(phase) do
|
28
|
+
if completed_phase?(phase) and !config[:always_run]
|
29
|
+
info("already completed")
|
30
|
+
elsif skip_phase?(phase)
|
31
|
+
info("skipping...")
|
32
|
+
else
|
33
|
+
block.call(phase, config)
|
34
|
+
end
|
33
35
|
end
|
34
|
-
|
36
|
+
|
35
37
|
after_phase(phase, config) if self.respond_to?(:after_phase)
|
36
38
|
end
|
37
39
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "gcloud"
|
2
|
+
|
3
|
+
module Dronejob
|
4
|
+
module Modules
|
5
|
+
module PubSub
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
cattr_accessor(:project_id) { "default" }
|
10
|
+
cattr_accessor(:queue_topic) { "dronejob_queue" }
|
11
|
+
cattr_accessor(:status_topic) { "dronejob_status" }
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
|
16
|
+
def pubsub
|
17
|
+
@pubsub ||= Gcloud.new(project_id).pubsub
|
18
|
+
end
|
19
|
+
|
20
|
+
def publish_job(job)
|
21
|
+
publish(queue_topic, job.serialize)
|
22
|
+
end
|
23
|
+
|
24
|
+
def publish_status(job, detail)
|
25
|
+
publish(status_topic, {job_id: job.job_id, detail: detail})
|
26
|
+
end
|
27
|
+
|
28
|
+
def publish(topic_name, data)
|
29
|
+
topic = pubsub.topic(topic_name)
|
30
|
+
topic.publish(data.to_json)
|
31
|
+
end
|
32
|
+
|
33
|
+
def run_worker!
|
34
|
+
subscribe(queue_topic, true) do |data|
|
35
|
+
begin
|
36
|
+
ActiveJob::Base.deserialize(data).perform_now()
|
37
|
+
rescue Exception => e
|
38
|
+
log("error", e)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def subscribe(topic_name, autoack=true, &block)
|
44
|
+
topic = pubsub.topic(topic_name)
|
45
|
+
subscription = topic.subscription(topic_name)
|
46
|
+
topic.subscribe(topic_name) if subscription.nil? or !subscription.exists?
|
47
|
+
subscription.listen autoack: autoack do |message|
|
48
|
+
block.call(JSON.parse(message.data))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def publish_status(result=nil)
|
55
|
+
self.class.publish_status(self, {phase: @phase, result: result})
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -5,10 +5,12 @@ module Dronejob
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
attr_accessor :working_dir
|
8
|
+
cattr_accessor(:jobs_path) { "app/jobs" }
|
9
|
+
cattr_accessor(:output_path) { "tmp/jobs" }
|
8
10
|
end
|
9
11
|
|
10
|
-
def create_working_dir
|
11
|
-
@working_dir = File.join(
|
12
|
+
def create_working_dir
|
13
|
+
@working_dir = File.join(self.class.output_path, uuid)
|
12
14
|
FileUtils.mkdir_p(@working_dir)
|
13
15
|
end
|
14
16
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'global_id/railtie'
|
2
|
+
require 'dronejob'
|
3
|
+
|
4
|
+
module Dronejob
|
5
|
+
# = Dronejob Railtie
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
config.dronejob = ActiveSupport::OrderedOptions.new
|
8
|
+
|
9
|
+
initializer 'dronejob.logger' do
|
10
|
+
ActiveSupport.on_load(:dronejob) { self.logger = ::Rails.logger }
|
11
|
+
end
|
12
|
+
|
13
|
+
initializer "dronejob.set_configs" do |app|
|
14
|
+
options = app.config.dronejob
|
15
|
+
|
16
|
+
ActiveSupport.on_load(:dronejob) do
|
17
|
+
options.each { |k,v| send("#{k}=", v) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
rake_tasks do
|
22
|
+
load "dronejob/railties/dronejob.rake"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/dronejob/version.rb
CHANGED
data/lib/dronejob.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require "active_support"
|
2
|
+
require 'active_support/rails'
|
3
|
+
require "active_job/queue_adapters/dronejob_queue_adapter"
|
2
4
|
require "dronejob/version"
|
3
5
|
|
6
|
+
require 'dronejob/railtie' if defined?(Rails)
|
7
|
+
|
4
8
|
module Dronejob
|
5
9
|
extend ActiveSupport::Autoload
|
6
10
|
autoload :Base
|
7
11
|
autoload :Loader
|
8
|
-
autoload :Logger
|
9
12
|
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
|
+
version: 1.0.2
|
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-02-
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.2'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: logging
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ~>
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '2.0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: thor
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,20 +80,6 @@ dependencies:
|
|
94
80
|
- - ~>
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '4.2'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: logging-google-cloud
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ~>
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '1.0'
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ~>
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '1.0'
|
111
83
|
- !ruby/object:Gem::Dependency
|
112
84
|
name: gcloud
|
113
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,20 +94,6 @@ dependencies:
|
|
122
94
|
- - ~>
|
123
95
|
- !ruby/object:Gem::Version
|
124
96
|
version: '0.6'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: google-api-client
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ~>
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0.8'
|
132
|
-
type: :runtime
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ~>
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0.8'
|
139
97
|
- !ruby/object:Gem::Dependency
|
140
98
|
name: rspec
|
141
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,19 +136,21 @@ files:
|
|
178
136
|
- README.md
|
179
137
|
- bin/dronejob
|
180
138
|
- dronejob.gemspec
|
181
|
-
- lib/active_job/queue_adapters/
|
139
|
+
- lib/active_job/queue_adapters/dronejob_queue_adapter.rb
|
182
140
|
- lib/dronejob.rb
|
183
141
|
- lib/dronejob/base.rb
|
184
142
|
- lib/dronejob/command.rb
|
185
143
|
- lib/dronejob/loader.rb
|
186
|
-
- lib/dronejob/logger.rb
|
187
144
|
- lib/dronejob/modules/attr_store.rb
|
188
145
|
- lib/dronejob/modules/core.rb
|
189
146
|
- lib/dronejob/modules/git.rb
|
190
147
|
- lib/dronejob/modules/log.rb
|
191
148
|
- lib/dronejob/modules/params.rb
|
192
149
|
- lib/dronejob/modules/phases.rb
|
150
|
+
- lib/dronejob/modules/pub_sub.rb
|
193
151
|
- lib/dronejob/modules/workspace.rb
|
152
|
+
- lib/dronejob/railtie.rb
|
153
|
+
- lib/dronejob/railties/dronejob.rake
|
194
154
|
- lib/dronejob/version.rb
|
195
155
|
homepage: https://github.com/MagLoft/dronejob
|
196
156
|
licenses:
|
@@ -1,76 +0,0 @@
|
|
1
|
-
module ActiveJob
|
2
|
-
module QueueAdapters
|
3
|
-
class PubSubQueueAdapter
|
4
|
-
|
5
|
-
def self.project_id
|
6
|
-
@@project_id
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.project_id=(project_id)
|
10
|
-
@@project_id = project_id
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.queue_topic
|
14
|
-
@@queue_topic ||= "dronejob_queue"
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.queue_topic=(queue_topic)
|
18
|
-
@@queue_topic = queue_topic
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.status_topic
|
22
|
-
@@status_topic ||= "dronejob_status"
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.status_topic=(status_topic)
|
26
|
-
@@status_topic = status_topic
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.pubsub
|
30
|
-
gcloud = Gcloud.new(self.project_id)
|
31
|
-
gcloud.pubsub
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.enqueue(job)
|
35
|
-
Dronejob::Logger.log("info", "Enqueuing worker #{job.class.name} with job id #{job.job_id}")
|
36
|
-
topic = pubsub.topic(self.queue_topic)
|
37
|
-
topic.publish(job.serialize.to_json)
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.listen(job, &block)
|
41
|
-
subscribe(self.status_topic, true) do |data|
|
42
|
-
block.call(data["detail"]) if data["job_id"] == job.job_id
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.run_worker!
|
47
|
-
subscribe(self.queue_topic, true) do |data|
|
48
|
-
job = ActiveJob::Base.deserialize(data)
|
49
|
-
Dronejob::Logger.log("info", "Processing worker #{job.class.name} with job id #{job.job_id}")
|
50
|
-
job.perform_now()
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.notify(job, detail)
|
55
|
-
topic = pubsub.topic(self.status_topic)
|
56
|
-
data = {job_id: job.job_id, detail: detail}
|
57
|
-
topic.publish(data.to_json)
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
def self.subscribe(topic_name, autoack=true, &block)
|
63
|
-
Dronejob::Logger.log("info", "Preparing subscription to #{topic_name}")
|
64
|
-
topic = pubsub.topic(topic_name)
|
65
|
-
subscription = topic.subscription(topic_name)
|
66
|
-
topic.subscribe(topic_name) if subscription.nil? or !subscription.exists?
|
67
|
-
Dronejob::Logger.log("info", "Subscribing to #{topic}")
|
68
|
-
subscription.listen autoack: autoack do |message|
|
69
|
-
data = JSON.parse(message.data)
|
70
|
-
block.call(data)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/lib/dronejob/logger.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require "logging"
|
2
|
-
require "logging/appenders/gcl"
|
3
|
-
|
4
|
-
module Dronejob
|
5
|
-
module Logger
|
6
|
-
@@logger = nil
|
7
|
-
|
8
|
-
def self.logger
|
9
|
-
if @@logger.nil?
|
10
|
-
Logging.init(Logging::Appenders::GoogleCloudLogging::SEVERITY_NAMES)
|
11
|
-
Logging.color_scheme("bright", levels: { debug: :blue, info: :green, warn: :yellow, error: :red, fatal: [:white, :on_red] }, date: :blue, ndc: :blue, logger: :cyan, message: :black)
|
12
|
-
Logging.appenders.stdout("stdout", layout: Logging.layouts.pattern( pattern: '[%d] %-5l %c{1} %x %m\n', color_scheme: 'bright'))
|
13
|
-
Logging.appenders.gcl("gcl", project_id: "typeshot-01", log_name: "dronejob", resource_type: "gce_instance", resource_labels: {instance_id: "drone-05", zone: "us-central1-b"}, buffer_size: '3', immediate_at: 'error, fatal')
|
14
|
-
@@logger = Logging::Logger.new("Dronejob")
|
15
|
-
@@logger.add_appenders("stdout") # gcl
|
16
|
-
end
|
17
|
-
@@logger
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.log(level, message)
|
21
|
-
logger.send(level, message)
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|