Top Level Namespace
Defined Under Namespace
Modules: SimpleWorker, Uber
Classes: SimpleWorkerGenerator
Instance Method Summary
collapse
Instance Method Details
#constantize(camel_cased_word) ⇒ Object
File activesupport/lib/active_support/inflector/methods.rb, line 107 Shoutout to the MIT License
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/simple_worker/server/runner.rb', line 33
def constantize(camel_cased_word)
names = camel_cased_word.split('::')
names.shift if names.empty? || names.first.empty?
constant = Object
names.each do |name|
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
end
constant
end
|
#get_class_to_run(class_name) ⇒ Object
26
27
28
29
|
# File 'lib/simple_worker/server/runner.rb', line 26
def get_class_to_run(class_name)
runner_class = constantize(class_name)
return runner_class
end
|
#init_database_connection(sw_config) ⇒ Object
This is the file that gets executed on the server.
3
4
5
6
7
8
9
10
11
12
|
# File 'lib/simple_worker/server/runner.rb', line 3
def init_database_connection(sw_config)
if sw_config
db_config = sw_config['database']
if db_config
require 'active_record'
ActiveRecord::Base.establish_connection(db_config)
end
end
end
|
#init_mailer(sw_config) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/simple_worker/server/runner.rb', line 14
def init_mailer(sw_config)
if sw_config
mailer_config = sw_config['mailer']
if mailer_config
require 'action_mailer'
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = mailer_config
ActionMailer::Base.delivery_method = :smtp
end
end
end
|
#init_runner(runner_class, job_data, user_dir, task_id) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/simple_worker/server/runner.rb', line 44
def init_runner(runner_class, job_data, user_dir, task_id)
init_arity = runner_class.instance_method(:initialize).arity
if init_arity == 0 || init_arity == -1
else
raise SimpleWorker::InvalidWorkerError, "Worker initialize method must accept zero arguments."
end
runner = runner_class.new
runner.instance_variable_set(:@task_id, task_id)
runner.instance_variable_set(:@job_data, job_data)
runner.instance_variable_set(:@sw_config, job_data['sw_config'])
runner.instance_variable_set(:@user_dir, user_dir)
runner.sw_set_data(job_data)
runner
end
|
#init_worker_service_for_runner(job_data) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/simple_worker/server/runner.rb', line 61
def init_worker_service_for_runner(job_data)
SimpleWorker.configure do |config|
sw_config = job_data['sw_config']
config.token = sw_config['token']
config.project_id = sw_config['project_id']
config.scheme = sw_config['scheme'] if sw_config['scheme']
config.host = sw_config['host'] if sw_config['host']
config.port = sw_config['port'] if sw_config['port']
db_config = sw_config['database']
if db_config
config.database = db_config
end
mailer_config = sw_config['mailer']
if mailer_config && config.respond_to?(:mailer)
config.mailer = mailer_config
end
config.global_attributes = sw_config['global_attributes'] if sw_config['global_attributes']
end
end
|