Skip to content

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
bdewater committed Oct 20, 2024
1 parent b183606 commit e3c4f84
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion guides/throttling.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,31 @@ def build_enumerator(_params, cursor:)
end
```

If you want to apply throttling on all jobs, you can subclass your own EnumeratorBuilder and override the default
enumerator builder. The builder always wraps the returned enumerators from `build_enumerator`

```ruby
class MyOwnBuilder < JobIteration::EnumeratorBuilder
class Wrapper < Enumerator
class << self
def wrap(_builder, enum)
ThrottleEnumerator.new(
enum,
nil,
throttle_on: -> { DatabaseStatus.unhealthy? },
backoff: 30.seconds
)
end
end
end
end

JobIteration.enumerator_builder = MyOwnBuilder
```

Note that it's up to you to implement `DatabaseStatus.unhealthy?` that works for your database choice. At Shopify, a helper like `DatabaseStatus` checks the following MySQL metrics:

* Replication lag across all regions
* DB threads
* DB is available for writes (otherwise indicates a failover happening)
* [Semian](https://github.com/shopify/semian) open circuits
* [Semian](https://github.com/shopify/semian) open circuits

0 comments on commit e3c4f84

Please sign in to comment.