Module: Executo
- Defined in:
- lib/executo/scheduler_worker.rb,
lib/executo.rb,
lib/executo/cli.rb,
lib/executo/worker.rb,
lib/executo/command.rb,
lib/executo/version.rb,
lib/executo/command_dsl.rb,
lib/executo/configuration.rb,
lib/executo/tagged_logger.rb,
lib/executo/encrypted_worker.rb,
lib/executo/feedback_process_job.rb,
lib/executo/feedback_process_service.rb
Overview
Defined Under Namespace
Modules: CommandDsl, TaggedLogger
Classes: CLI, Command, Configuration, EncryptedWorker, Error, FeedbackProcessJob, FeedbackProcessService, SchedulerWorker, Worker
Constant Summary
collapse
- VERSION =
'0.3.12'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
28
29
30
|
# File 'lib/executo.rb', line 28
def config
@config
end
|
Class Method Details
.active_job_connection_pool ⇒ Object
102
103
104
|
# File 'lib/executo.rb', line 102
def active_job_connection_pool
@active_job_connection_pool ||= ConnectionPool.new(size: 5, timeout: 5) { Redis.new(config.active_job_redis) }
end
|
.connection_pool ⇒ Object
98
99
100
|
# File 'lib/executo.rb', line 98
def connection_pool
@connection_pool ||= ConnectionPool.new(size: 5, timeout: 5) { Redis.new(config.redis) }
end
|
.cryptor ⇒ Object
37
38
39
|
# File 'lib/executo.rb', line 37
def cryptor
@cryptor ||= ActiveSupport::MessageEncryptor.new(ENV['EXECUTO_KEY'])
end
|
.decrypt(string) ⇒ Object
45
46
47
|
# File 'lib/executo.rb', line 45
def decrypt(string)
cryptor.decrypt_and_verify(string)
end
|
.encrypt(obj) ⇒ Object
41
42
43
|
# File 'lib/executo.rb', line 41
def encrypt(obj)
cryptor.encrypt_and_sign(obj)
end
|
.publish(target:, command:, parameters: [], encrypt: false, options: {}, job_options: {}, feedback: {}) ⇒ Object
Publishes a command to be executed on a target
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/executo.rb', line 64
def publish(target:, command:, parameters: [], encrypt: false, options: {}, job_options: {}, feedback: {})
options['feedback'] = feedback&.stringify_keys
options['feedback']['id'] ||= SecureRandom.uuid
args = [command, parameters, options.deep_stringify_keys]
args = args.map { |a| encrypt(a) } if encrypt
sidekiq_options = { 'retry' => 0 }.merge(job_options).merge(
'queue' => target,
'class' => encrypt ? 'Executo::EncryptedWorker' : 'Executo::Worker',
'args' => args
)
if defined?(Rails) && Rails.env.test?
$executo_jobs ||= {}
$executo_jobs[options.dig('feedback', 'id')] = sidekiq_options
else
Sidekiq::Client.new(connection_pool).push(sidekiq_options)
end
logger.info("Published #{command} to #{target} with id #{options['feedback']['id']}")
options.dig('feedback', 'id')
end
|
.schedule(target, list) ⇒ Object
88
89
90
91
92
93
94
95
96
|
# File 'lib/executo.rb', line 88
def schedule(target, list)
options = {
'retry' => 0,
'queue' => target,
'class' => 'Executo::SetScheduleWorker',
'args' => list
}
Sidekiq::Client.new(connection_pool).push(options)
end
|
.setup {|config| ... } ⇒ Object
32
33
34
35
|
# File 'lib/executo.rb', line 32
def setup
@config = Configuration.new
yield config
end
|