This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "context" | |
| "fmt" | |
| "github.com/go-redis/redis/v8" | |
| ) | |
| func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class App | |
| attr_reader :queue | |
| def initialize | |
| @queue = [] | |
| end | |
| def call | |
| puts "App PID: #{Process.pid}" | |
| publish |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class App | |
| attr_reader :queue | |
| def initialize | |
| @queue = [] | |
| end | |
| def call | |
| puts "App PID: #{Process.pid}" | |
| publish |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SomeClass | |
| # ... | |
| def execute | |
| api_client.get(id) | |
| rescue StandardError => e | |
| @retries = @retries + 1 | |
| retries > RETRY_LIMIT ? raise(e) : retry | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WeatherUpdateJob | |
| include Sidekiq::Worker | |
| sidekiq_options retry: 3 | |
| def perform | |
| Weather.new(data: BestWeatherAPI.get) | |
| Weather.save! | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Aws::S3 | |
| module Errors | |
| extend Aws::Errors::DynamicErrors | |
| class BucketAlreadyExists < ServiceError | |
| def initialize(context, message, data = Aws::EmptyStructure.new) | |
| super(context, message, data) | |
| end | |
| end | |
| class BucketAlreadyOwnedByYou < ServiceError |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get | |
| Retriable.retriable do | |
| # code here... | |
| end | |
| rescue StandardError => e | |
| logger.error 'failed_request', error: e | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Will retry all exceptions | |
| Retriable.with_context(:aws) do | |
| # aws_call | |
| end | |
| # Will retry Mysql::DeadlockException | |
| Retriable.with_context(:mysql) do | |
| # write_to_table | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Retriable.configure do |c| | |
| c.contexts[:aws] = { | |
| tries: 3, | |
| on: [Aws::Errors::ServiceError, Errno::ECONNRESET] | |
| } | |
| c.contexts[:mysql] = { | |
| tries: 10, | |
| on: Mysql::DeadlockException | |
| } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'retriable' | |
| class Api | |
| # Use it in methods that interact with unreliable services | |
| def get | |
| Retriable.retriable do | |
| # code here... | |
| end | |
| end | |
| end |