class PoiseApplicationPython::Resources::CeleryWorker::Resource

Private Instance Methods

default_app_module() click to toggle source

Compute the default application module to pass to gunicorn. This checks the app state and then looks for commonly used filenames. Raises an exception if no default can be found.

@return [String]

# File lib/poise_application_python/resources/celery_worker.rb, line 41
def default_app_module
  # If set in app_state, use that.
  return app_state[:python_celery_module] if app_state[:python_celery_module]
  # If a Django settings module is set, use everything by the last
  # dotted component of it. to_s handles nil since that won't match.
  return $1 if app_state_environment[:DJANGO_SETTINGS_MODULE].to_s =~ /^(.+?)\.[^.]+$/
  files = Dir.exist?(path) ? Dir.entries(path) : []
  # Try to find a known filename.
  candidate_file = %w{tasks.py task.py celery.py main.py app.py application.py}.find {|file| files.include?(file) }
  # Try the first Python file. Do I really want this?
  candidate_file ||= files.find {|file| file.end_with?('.py') }
  if candidate_file
    ::File.basename(candidate_file, '.py')
  else
    nil
  end
end