In Container-based DevOps solutions like Kubernetes, ECS, Heroku an application must be able to stop accepting new client requests before termination, and, most importantly, it must successfully complete already running requests and processes.
By default in most systems Graceful Shutdown implements by sending
SIGTERM signal and 30 seconds delay before terminating the instance.
There are two similar ways:
Both constructions allow handling Linux signals, below I will give some examples with handling
SIGTERM and describe the differences. Also, you can use the full list of POSIX signals.
I will write an app that publishes messages to…
A stub is the only defined result of the method call which doesn’t care about behavior. With RSpec, you can use stub with
If you need to stub the result of the method then it’s possible with
Mock expect methods to be called, otherwise it raises an error. With RSpec, you can use mock with
As well as the stub replacing mock result possible with
Test double is a dummy object that you use to replace a real object during a test…
When designing modern applications on microservices architecture and systems based on cloud solutions such as AWS, Azure, or Google Cloud imply the need to handle expected failures.
We can represent the simplest retry in runtime as a rescue block and variable with a count of executed retries.
Also Ruby has built-in
retry keyword, an example can be changed in the next way:
StandardError, for e.g.
ApiError = Class.new(StandardError)
There are two most popular ways to manage secrets in your application.
In this article, I want to talk about the first approach.
Encrypted secrets were first introduced in Rails 5.1. Rails store secrets in…
In the early stages of development, it may be useful to identify slow queries in time (when you don’t have a paid APM). QueryTrack helps to get notified about slow queries with related data: duration and backtrace.
Add this line to your application’s
Gemfile and then execute
To start receiving information about requests you need to create
config/initializers/query_track.rb where there is a time limit that is specified in seconds and an output channel (for example console logs):
QueryTrack::Settings.configure do |config|
config.duration = 0.5
config.logs = true
You won't get any notifications without setting the max…
One of the tools that are rarely covered in the Ruby/Rails world are the message brokers (probably because they mostly written in Java). Everyone are familiar mostly with background jobs processing, but message brokers offer a more flexible approach to asynchronous execution. For example, you can create a message from one application and process it in another and continue executing without waiting for the response.
Some benefits that you get at the architectural level:
Fault Tolerance, Guaranteed delivery, Asynchronous communication(through Publish/Subscribe pattern), Loosely coupling, etc.
One of the messaging brokers that I used is ActiveMQ. ActiveMQ provides most of these…
To use Redis as a Rails cache store, use a dedicated cache instance that’s set up as an LRU (Last Recently Used) cache instead of pointing the store at your existing Redis server, to make sure entries are dropped from the store when it reaches its maximum size.
To get started, add the redis gem to…
Sucker Punch — a single-process Ruby asynchronous processing library that runs with your existing app’s process.
Gem is built on top of concurrent-ruby and have no dependencies with any data storage, what is both an advantage and a disadvantage.
Running in the application process really simplifies the deployment process, but If the web processes are restarted with jobs remaining in the queue, they will be lost. Also, since all state persistence is in memory, Sucker Punch can operate extremely fast on small tasks. …
export statements have been standardized in ES2015. They are not supported in browsers yet, but webpack does support them out of the box. But actually it’s more powerful tool which can help us build whole our front-end.
Let’s start with initializing
package.json by using
npm init command.
Installing globally locks you down to a specific version of webpack and could fail in projects that use a different version. Therefore, we will install it locally.
npm install --save-dev webpack
Webpack will be added to
Because we are…
Linter is a static analysis tool such as RuboCop. It checks the written code and makes suggestions based on pre-defined rules by community-driven coding style guides and common idioms.
Most definitions of linter default behavior can be changed for the needs of your team and project via various configuration options.
There are many reasons to lint the code:
Git hooks are scripts that execute before or after actions such…
Software Engineer. Interested in Full-Stack Development and DevOps.