README.md in global-registry-bindings-0.1.9 vs README.md in global-registry-bindings-0.2.0
- old
+ new
@@ -19,22 +19,33 @@
config.base_url = ENV['GLOBAL_REGISTRY_URL'] || 'https://backend.global-registry.org'
end
```
Make sure sidekiq is configured. See [Using Redis](https://github.com/mperham/sidekiq/wiki/Using-Redis) for information.
-### Aditional Sidekiq Configuration
+### Additional Configuration
+#### Sidekiq options
The `global-registry-bindings` gem allows for configuring default sidekiq options for all workers. You can configure
this by creating a custom initializer, or adding to the global_registry initializer the following.
```ruby
GlobalRegistry::Bindings.configure do |config|
-# Run global-registry-bindings workers in a :custom queue
+ # Run global-registry-bindings workers in a :custom queue
config.sidekiq_options = { queue: :custom }
end
```
Custom sidekiq options will apply to all Global Registry Bindings sidekiq Workers.
+#### Redis Error Action
+This option defines what `global-registry-bindings` does when a Redis error is encountered while adding a sidekiq
+worker to the queue. Valid actions are `:ignore`, `:log` and `:raise`.
+```ruby
+GlobalRegistry::Bindings.configure do |config|
+ config.redis_error_action = :ignore # Silently ignore redis issues
+end
+```
+The default behaviour is to `:log` the error to `Rollbar` if present.
+
## Usage
To make use of `global-registry-bindings` your model will need a few additional columns.
To push models to Global Registry, you will need a `global_registry_id` column. You additionally need a
`global_registry_mdm_id` to pull a Global Registry MDM (master data model) id. Additionally, relationships will also
@@ -147,10 +158,14 @@
option is nil or empty. (default: `nil`) **[`:entity`]**
* `:mdm_timeout`: Only pull mdm information at most once every `:mdm_timeout`. (default: `1.minute`)
**[`:entity`]**
+* `:if`, `:unless`: Proc or Symbol, called to determine if the change should be sent (enqueue a worker) to Global
+Registry. Proc and Symbol will both receive the model for an entity, and the type and model for a relationship. See
+[Conditional Push](#conditional-push) for examples. **[`:entity`, `:relationship`]**
+
## Entities
`global-registry-bindings` default bindings is to push an Active Record class as an Entity to Global Registry.
This can be used to push root level entities, entities with a parent and entities with a hierarchy. You can also
enable fetching of a Master Data Model from Global Registry.
@@ -371,9 +386,32 @@
end
```
As an example, this would alias `field1` to `name` and use the method `field2` to determine the value for `field2`. It
subsequently changes the value of `:description` and adds an `:authentication` field using the
`entity_attributes_to_push` override.
+
+## Conditional Push
+
+Entities and relationships can be conditionally pushed to Global Registry using the `:if` and `:unless` options. These
+options take either a Proc or a Symbol and should return true/false depending on if the Model should be pushed.
+
+Using a proc:
+```ruby
+class Product < ActiveRecord::Base
+ attr_accessor :should_push
+ global_registry_bindings if: proc { |model| model.should_push }
+end
+```
+Using a Symbol:
+```ruby
+class Product < ActiveRecord::Base
+ global_registry_bindings unless: :should_push
+
+ def should_push(_model)
+ return ::GlobalConfig.gr_enabled?
+ end
+end
+```
## Example Models
Example models can be found in the [specs](https://github.com/CruGlobal/global-registry-bindings/tree/master/spec/internal/app/models).