Below you will find pages that utilize the taxonomy term “Phoenix”
Running Quantum in an Elixir Cluster
In one of the projects that I work on, for the sake of availability and reliability, we are running our Phoenix app in a cluster of 3 servers using libcluster. Initially, it was just running on a single server and I had configured Quantum to run our recurring tasks on a cron like schedule. This worked well, and I had no issues with the setup. When we decided to move to a clustered setup, there was a consideration concerning Quantum. I didn’t want the jobs to run on multiple servers, I wanted to have a single server responsible for handling all the scheduled jobs so as to keep duplicate jobs from running. I looked around and found someone who had written about using Highlander to make sure there was only a single instance of Quantum running on the cluster at a time. I decided to try this out.
Ecto Preload Nested Associations with joins
Recently I had an issue where I was loading some “models” in ecto, and I needed to preload some of the associations along with the parent record. I had it working with a very simple bit of code.
def get_franchises do
Franchise
|> preload(merchants: [stores: :shopify])
|> Repo.all()
end
As you can see from this bit of code, some of the associations were nested, Franchise has many Merchants, Merchants have many stores, and a store can have a Shopify record. What I noticed when I started using the returned data was that some of the stores didn’t have a Shopify record. For my purposes, I wasn’t interested in the stores without a Shopify record, so I wanted to exclude them from my query results. In its original form, there were several queries being made to satisfy the ecto results. I struggled with how to include a where clause in the preload statement, until I came across something that led me to my desired result. Here’s the end game, a single SQL query resulting from an ecto statement with a preload that limits the stores to those with a Shopify record. You could further fine tune your query to return a subset of these results if you desired.
Heroku Git Transport Feature Retirement
We recently received an email from Heroku telling us that we would need to transition our deployments away from the ssh transport that we’ve been using on Semaphore CI to deploy our Elixir Phoenix app. The Semaphore deployment documentation only covers the ssh transport route. We needed to figure out how to move to the https deployments from our CI server. The instructions in the email were’t too helpful as those steps had already been taken in our project, the Semaphore solution replaces https with ssh for deployments. The real issue was how to authenticate to Heroku now that SSH was off the table.
Add Sass to Phoenix 1.6 with Esbuild
If you are starting a new project with The Phoenix Framework version 1.6, you’ll notice there has been a change with regard to asset handling. Chris McCord and The Phoenix Team have made the choice to move away from WebPack and start using Esbuild to deal with the Javascript files. One side effect of this is you lose the ability to use Sass files by default. Have no fear, there’s a way to add Sass back into your project.