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



121
122
123
124
125
126
127
128
129
# File 'lib/webhookdb/async.rb', line 121

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



131
132
133
134
135
136
137
138
# File 'lib/webhookdb/async.rb', line 131

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



75
76
77
78
79
80
81
# File 'lib/webhookdb/async.rb', line 75

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.



114
115
116
117
118
119
# File 'lib/webhookdb/async.rb', line 114

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.



90
91
92
93
94
95
# File 'lib/webhookdb/async.rb', line 90

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.



102
103
104
105
106
107
108
# File 'lib/webhookdb/async.rb', line 102

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