Contributing to Open Source Phase at Encora Apprenticeship — Week 3
This post is part of a weekly assignment at Encora Apprentice and in this series, I’ll share my journey as a Software Engineer Apprentice. I hope these stories help and motivate others on their tech journey.
This week at Encora
This week at Encora I continued on my quest through the Open-Source community as I worked on a new issue and kept looking for a new one to contribute. I also got to write tests in Ruby and Javascript projects, so make sure to keep reading to find more about it!
Debugging with Ruby
As I mentioned last week, I took on an issue for the RubyGems project. To contribute to it, I needed to check how the install
command worked, and how to implement that behavior in the fetch
command. I decided to try the same approach I used to solve the Netlify-CLI issue, which was to set up a debugging tool to help me look at the values of the variables and see which methods were being invoked.
To do this, I used an extension called vscode-ruby or just Ruby for VSCode. To use this extension, it is necessary to install some gems like ruby-debug-ide
and debase
. After this, we can generate a launch.json, where we define what file we want to run to debug, in my case, I wrote a main.rb
to call the method I needed.
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Local File",
"type": "Ruby",
"program": "${workspaceRoot}/main.rb"
}
]
}
With this, we can now use the debug
tool integrated with VSCode when pressing the “play” button in the debug
menu. Thanks to this approach, I could find the file fetch_command.rb
which contained the method execute
which needed to separate the gem names from the versions.
Exponential Backoff
While on my quest to find new issues, I came across a new issue where was pointed out that it could be implemented an exponential backoff, which is an algorithm to prevent devices from generating excessive calls and loads to servers.
This algorithm consists of the client (who makes the calls) retrying a failed request in certain periods of time, these periods are increasing in an exponential fashion until a maximum_backoff
. The truncated exponential backoff stops increasing the time after this limit.
Anatomy of a Jenkinsfiles
This week I’ve been working a little bit with Jenkins and while following this tutorial, I came across a Jenkinsfile
, where we can define the steps of our CI/CD pipeline and Jenkins will execute them. We can start with a simple file:
pipeline {
agent {
docker {
image: 'node:lts-buster-slim'
args: '-p 3000:3000'
}
}
stages {
stage('Build') {
steps {
sh 'npm install'
}
}
}
}
In this example, we are defining an agent
, which will be a container using and image
with node
. And for the stages, we just define one, which is the Build
stage, and will run the command npm install
. We can add more stages that can run the tests or perform other actions in the future.
Before I go
Working on open-source projects is a very interesting experience since we need to become familiar with big codebases while following conventions, which at the same time help on keeping the code readable.