Module: Webhookdb::Async

Extended by:
MethodUtilities
Includes:
Appydays::Configurable, Appydays::Loggable
Defined in:
lib/webhookdb/async.rb

Defined Under Namespace

Modules: Autoscaler, Job, ScheduledJob Classes: AuditLogger, JobLogger

Class Method Summary collapse

Methods included from MethodUtilities

attr_predicate, attr_predicate_accessor, singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer, singleton_method_alias, singleton_predicate_accessor, singleton_predicate_reader

Class Method Details

._require_jobsObject



126
127
128
129
130
131
132
133
134
# File 'lib/webhookdb/async.rb', line 126

def self._require_jobs
  Amigo::DurableJob.replace_database_settings(
    loggers: [Webhookdb.logger],
    **Webhookdb::Dbutil.configured_connection_options,
  )
  Gem.find_files(File.join("webhookdb/jobs/*.rb")).each do |path|
    require path
  end
end

._setup_commonObject



136
137
138
139
140
141
142
143
# File 'lib/webhookdb/async.rb', line 136

def self._setup_common
  raise "Async already setup, only call this once" if Amigo.structured_logging
  Amigo.structured_logging = true
  Amigo.log_callback = lambda { |j, lvl, msg, o|
    lg = j ? Appydays::Loggable[j] : Webhookdb::Async::JobLogger.logger
    lg.send(lvl, msg, o)
  }
end

.open_webObject



80
81
82
83
84
85
86
# File 'lib/webhookdb/async.rb', line 80

def self.open_web
  u = URI(Webhookdb.api_url)
  u.user = self.web_username
  u.password = self.web_password
  u.path = "/sidekiq"
  `open #{u}`
end

.setup_testsObject

Set up for tests. This performs common config and requires the jobs. It does not install the routing/auditing jobs, since those should only be installed at specific times.



119
120
121
122
123
124
# File 'lib/webhookdb/async.rb', line 119

def self.setup_tests
  return if Amigo.structured_logging # assume we are set up
  self._setup_common
  self._require_jobs
  return true
end

.setup_webObject

Set up async for the web/client side of things. This performs common Amigo config, and sets up the routing/auditing jobs.

Note that we must also require all async jobs, since in some cases we may have sidekiq middleware that needs access to the actual job class, so it must be available.



95
96
97
98
99
100
# File 'lib/webhookdb/async.rb', line 95

def self.setup_web
  self._setup_common
  Amigo.install_amigo_jobs
  self._require_jobs
  return true
end

.setup_workersObject

Set up the worker process. This peforms common Amigo config, sets up the routing/audit jobs (since jobs may publish to other jobs), requires the actual jobs, and starts the cron.



107
108
109
110
111
112
113
# File 'lib/webhookdb/async.rb', line 107

def self.setup_workers
  self._setup_common
  Amigo.install_amigo_jobs
  self._require_jobs
  Amigo.start_scheduler
  return true
end