Class: WebHooks::DestroyService

Inherits:
Object
  • Object
show all
Includes:
BaseServiceUtility
Defined in:
app/services/web_hooks/destroy_service.rb

Constant Summary collapse

BATCH_SIZE =
1000
LOG_COUNT_THRESHOLD =
10000
DestroyError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(current_user) ⇒ DestroyService

Returns a new instance of DestroyService.


14
15
16
# File 'app/services/web_hooks/destroy_service.rb', line 14

def initialize(current_user)
  @current_user = current_user
end

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.


12
13
14
# File 'app/services/web_hooks/destroy_service.rb', line 12

def current_user
  @current_user
end

#web_hookObject

Returns the value of attribute web_hook.


12
13
14
# File 'app/services/web_hooks/destroy_service.rb', line 12

def web_hook
  @web_hook
end

Instance Method Details

#execute(web_hook) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/web_hooks/destroy_service.rb', line 18

def execute(web_hook)
  @web_hook = web_hook

  async = false
  # For a better user experience, it's better if the Web hook is
  # destroyed right away without waiting for Sidekiq. However, if
  # there are a lot of Web hook logs, we will need more time to
  # clean them up, so schedule a Sidekiq job to do this.
  if needs_async_destroy?
    Gitlab::AppLogger.info("User #{current_user&.id} scheduled a deletion of hook ID #{web_hook.id}")
    async_destroy(web_hook)
    async = true
  else
    sync_destroy(web_hook)
  end

  success({ async: async })
end

#sync_destroy(web_hook) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/web_hooks/destroy_service.rb', line 37

def sync_destroy(web_hook)
  @web_hook = web_hook

  delete_web_hook_logs
  result = web_hook.destroy

  if result
    success({ async: false })
  else
    error("Unable to destroy #{web_hook.model_name.human}")
  end
end