Skip to content

Instantly share code, notes, and snippets.

package main
import (
"context"
"fmt"
"github.com/go-redis/redis/v8"
)
func main() {
class App
attr_reader :queue
def initialize
@queue = []
end
def call
puts "App PID: #{Process.pid}"
publish
class App
attr_reader :queue
def initialize
@queue = []
end
def call
puts "App PID: #{Process.pid}"
publish
class SomeClass
# ...
def execute
api_client.get(id)
rescue StandardError => e
@retries = @retries + 1
retries > RETRY_LIMIT ? raise(e) : retry
end
class WeatherUpdateJob
include Sidekiq::Worker
sidekiq_options retry: 3
def perform
Weather.new(data: BestWeatherAPI.get)
Weather.save!
end
end
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
def get
Retriable.retriable do
# code here...
end
rescue StandardError => e
logger.error 'failed_request', error: e
end
# 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
Retriable.configure do |c|
c.contexts[:aws] = {
tries: 3,
on: [Aws::Errors::ServiceError, Errno::ECONNRESET]
}
c.contexts[:mysql] = {
tries: 10,
on: Mysql::DeadlockException
}
end
require 'retriable'
class Api
# Use it in methods that interact with unreliable services
def get
Retriable.retriable do
# code here...
end
end
end