Run rails new --help
to see all of the options you can use to create a new Rails application:
Output for Rails 8+
Usage:
rails COMMAND [options]
You must specify a command:
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 |
class SomeClass | |
attr_reader :id, :retries | |
ApiError = Class.new(StandardError) | |
RETRY_LIMIT = 3 | |
def initialize(id) | |
@id = id | |
@retries = 0 |
Run rails new --help
to see all of the options you can use to create a new Rails application:
Output for Rails 8+
Usage:
rails COMMAND [options]
You must specify a command:
class Integer | |
def times_method | |
(0...self).each do |i| | |
yield(i) | |
end | |
return self | |
end | |
end |