Class: Virtuaservices::Utils::Seeder

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/virtuaservices/utils/seeder.rb

Overview

This class loads the necessary data in the database if they don’t exist yet.

Author:

Instance Method Summary collapse

Instance Method Details

#create_service(key) ⇒ Virtuaservices::Monitoring::Service

Creates the service if it does not exist, and the instance if it does not exist.

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/virtuaservices/utils/seeder.rb', line 10

def create_service(key)
  service = Virtuaservices::Monitoring::Service.where(key: key).first

  if service.nil?
    service = Virtuaservices::Monitoring::Service.create!(key: key, path: "/#{key}", premium: true, active: true)
  end

  if service.instances.where(url: ENV['SERVICE_URL']).first.nil?
    Virtuaservices::Monitoring::Instance.create!(url: ENV['SERVICE_URL'], running: true, service: service, active: true)
  end

  return service
end