Commit f6aa5f9b authored by Luke Duncalfe's avatar Luke Duncalfe
parent d0871fac
# frozen_string_literal: true
module Integrations
module ReactivelyCached
extend ActiveSupport::Concern
included do
include ::ReactiveCaching
# Default cache key: class name + project_id
self.reactive_cache_key = ->(integration) { [integration.class.model_name.singular, integration.project_id] }
self.reactive_cache_work_type = :external_dependency
end
end
end
# frozen_string_literal: true
module ReactiveService
extend ActiveSupport::Concern
included do
include ReactiveCaching
# Default cache key: class name + project_id
self.reactive_cache_key = ->(service) { [service.class.model_name.singular, service.project_id] }
self.reactive_cache_work_type = :external_dependency
end
end
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Integrations module Integrations
class Bamboo < BaseCi class Bamboo < BaseCi
include ActionView::Helpers::UrlHelper include ActionView::Helpers::UrlHelper
include ReactiveService include ReactivelyCached
prop_accessor :bamboo_url, :build_key, :username, :password prop_accessor :bamboo_url, :build_key, :username, :password
......
...@@ -5,7 +5,7 @@ require "addressable/uri" ...@@ -5,7 +5,7 @@ require "addressable/uri"
module Integrations module Integrations
class Buildkite < BaseCi class Buildkite < BaseCi
include HasWebHook include HasWebHook
include ReactiveService include ReactivelyCached
extend Gitlab::Utils::Override extend Gitlab::Utils::Override
ENDPOINT = "https://buildkite.com" ENDPOINT = "https://buildkite.com"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Integrations module Integrations
class DroneCi < BaseCi class DroneCi < BaseCi
include HasWebHook include HasWebHook
include ReactiveService include ReactivelyCached
include ServicePushDataValidations include ServicePushDataValidations
extend Gitlab::Utils::Override extend Gitlab::Utils::Override
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module Integrations module Integrations
class Teamcity < BaseCi class Teamcity < BaseCi
include ReactiveService include ReactivelyCached
include ServicePushDataValidations include ServicePushDataValidations
prop_accessor :teamcity_url, :build_type, :username, :password prop_accessor :teamcity_url, :build_type, :username, :password
......
...@@ -74,7 +74,7 @@ For more information, read the internal issue ...@@ -74,7 +74,7 @@ For more information, read the internal issue
### In models and integrations ### In models and integrations
The ReactiveCaching concern can be used in models as well as `integrations` The ReactiveCaching concern can be used in models as well as integrations
(`app/models/integrations`). (`app/models/integrations`).
1. Include the concern in your model or integration. 1. Include the concern in your model or integration.
...@@ -88,7 +88,7 @@ The ReactiveCaching concern can be used in models as well as `integrations` ...@@ -88,7 +88,7 @@ The ReactiveCaching concern can be used in models as well as `integrations`
To include the concern in an integration: To include the concern in an integration:
```ruby ```ruby
include ReactiveService include Integrations::ReactivelyCached
``` ```
1. Implement the `calculate_reactive_cache` method in your model or integration. 1. Implement the `calculate_reactive_cache` method in your model or integration.
...@@ -201,15 +201,15 @@ There are some `class_attribute` options which can be tweaked. ...@@ -201,15 +201,15 @@ There are some `class_attribute` options which can be tweaked.
and `"ExampleModel:1:arg1:arg2:alive"` respectively, where `ExampleModel` is the and `"ExampleModel:1:arg1:arg2:alive"` respectively, where `ExampleModel` is the
name of the model, `1` is the ID of the record, `arg1` and `arg2` are parameters name of the model, `1` is the ID of the record, `arg1` and `arg2` are parameters
passed to `with_reactive_cache`. passed to `with_reactive_cache`.
- If you're including this concern in a service instead, you must override - If you're including this concern in an integration (`app/models/integrations/`) instead, you must override
the default by adding the following to your service: the default by adding the following to your integration:
```ruby ```ruby
self.reactive_cache_key = ->(service) { [service.class.model_name.singular, service.project_id] } self.reactive_cache_key = ->(integration) { [integration.class.model_name.singular, integration.project_id] }
``` ```
If your reactive_cache_key is exactly like the above, you can use the existing If your reactive_cache_key is exactly like the above, you can use the existing
`ReactiveService` concern instead. `Integrations::ReactivelyCached` concern instead.
#### `self.reactive_cache_lease_timeout` #### `self.reactive_cache_lease_timeout`
......
...@@ -4,7 +4,7 @@ module Projects ...@@ -4,7 +4,7 @@ module Projects
module Integrations module Integrations
module Jira module Jira
class ByIdsFinder class ByIdsFinder
include ReactiveService include ::Integrations::ReactivelyCached
self.reactive_cache_key = ->(finder) { [finder.model_name] } self.reactive_cache_key = ->(finder) { [finder.model_name] }
self.reactive_cache_work_type = :external_dependency self.reactive_cache_work_type = :external_dependency
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment