Class: Clusters::Applications::BaseService

Inherits:
Object
  • Object
show all
Defined in:
app/services/clusters/applications/base_service.rb

Direct Known Subclasses

CreateService, DestroyService, UpdateService

Constant Summary collapse

InvalidApplicationError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster, user, params = {}) ⇒ BaseService

Returns a new instance of BaseService.


10
11
12
13
14
# File 'app/services/clusters/applications/base_service.rb', line 10

def initialize(cluster, user, params = {})
  @cluster = cluster
  @current_user = user
  @params = params.dup
end

Instance Attribute Details

#clusterObject (readonly)

Returns the value of attribute cluster.


8
9
10
# File 'app/services/clusters/applications/base_service.rb', line 8

def cluster
  @cluster
end

#current_userObject (readonly)

Returns the value of attribute current_user.


8
9
10
# File 'app/services/clusters/applications/base_service.rb', line 8

def current_user
  @current_user
end

#paramsObject (readonly)

Returns the value of attribute params.


8
9
10
# File 'app/services/clusters/applications/base_service.rb', line 8

def params
  @params
end

Instance Method Details

#execute(request) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/clusters/applications/base_service.rb', line 16

def execute(request)
  instantiate_application.tap do |application|
    if application.has_attribute?(:hostname)
      application.hostname = params[:hostname]
    end

    if application.has_attribute?(:email)
      application.email = params[:email]
    end

    if application.has_attribute?(:stack)
      application.stack = params[:stack]
    end

    if application.respond_to?(:oauth_application)
      application.oauth_application = create_oauth_application(application, request)
    end

    if application.instance_of?(Knative)
      Serverless::AssociateDomainService
        .new(application, pages_domain_id: params[:pages_domain_id], creator: current_user)
        .execute
    end

    worker = worker_class(application)

    application.make_scheduled!

    worker.perform_async(application.name, application.id)
  end
end