<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Phoenix on Justin B Kay's Blog</title><link>https://blog.jbkconsultingllc.com/tags/phoenix/</link><description>Recent content in Phoenix on Justin B Kay's Blog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Thu, 17 Feb 2022 14:42:55 -0700</lastBuildDate><atom:link href="https://blog.jbkconsultingllc.com/tags/phoenix/index.xml" rel="self" type="application/rss+xml"/><item><title>Running Quantum in an Elixir Cluster</title><link>https://blog.jbkconsultingllc.com/posts/running-quantum-in-elixir-cluster/</link><pubDate>Thu, 17 Feb 2022 14:42:55 -0700</pubDate><guid>https://blog.jbkconsultingllc.com/posts/running-quantum-in-elixir-cluster/</guid><description>&lt;p&gt;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 &lt;a href="https://github.com/quantum-elixir/quantum-core"&gt;Quantum&lt;/a&gt; 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&amp;rsquo;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 &lt;a href="https://github.com/derekkraan/highlander"&gt;Highlander&lt;/a&gt; to make sure there was only a single instance of Quantum running on the cluster at a time. I decided to try this out.&lt;/p&gt;</description></item><item><title>Ecto Preload Nested Associations with joins</title><link>https://blog.jbkconsultingllc.com/posts/ecto-preload-nested-associations/</link><pubDate>Fri, 15 Oct 2021 10:06:51 -0600</pubDate><guid>https://blog.jbkconsultingllc.com/posts/ecto-preload-nested-associations/</guid><description>&lt;p&gt;Recently I had an issue where I was loading some &amp;ldquo;models&amp;rdquo; 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.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-elixir" data-lang="elixir"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;def&lt;/span&gt; get_franchises &lt;span style="color:#66d9ef"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;Franchise&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;|&amp;gt;&lt;/span&gt; preload(&lt;span style="color:#e6db74"&gt;merchants&lt;/span&gt;: [&lt;span style="color:#e6db74"&gt;stores&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;:shopify&lt;/span&gt;])
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;|&amp;gt;&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;Repo&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;all()
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;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&amp;rsquo;t have a Shopify record. For my purposes, I wasn&amp;rsquo;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&amp;rsquo;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.&lt;/p&gt;</description></item><item><title>Heroku Git Transport Feature Retirement</title><link>https://blog.jbkconsultingllc.com/posts/heroku-git-transport-feature-retirement/</link><pubDate>Wed, 29 Sep 2021 08:16:17 -0600</pubDate><guid>https://blog.jbkconsultingllc.com/posts/heroku-git-transport-feature-retirement/</guid><description>&lt;p&gt;We recently received an email from Heroku telling us that we would need to transition our deployments away from the ssh transport that we&amp;rsquo;ve been using on &lt;a href="https://semaphoreci.com/"&gt;Semaphore CI&lt;/a&gt; to deploy our Elixir Phoenix app. The &lt;a href="https://docs.semaphoreci.com/examples/heroku-deployment/"&gt;Semaphore deployment documentation&lt;/a&gt; only covers the ssh transport route. We needed to figure out how to move to the https deployments from our CI server. The &lt;a href="https://help.heroku.com/6JAIBWLM/how-do-i-deploy-my-app-with-heroku-s-http-git-transport-instead-of-ssh-git-transport"&gt;instructions&lt;/a&gt; in the email were&amp;rsquo;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.&lt;/p&gt;</description></item><item><title>Add Sass to Phoenix 1.6 with Esbuild</title><link>https://blog.jbkconsultingllc.com/posts/add-sass-to-phoenix-with-esbuild/</link><pubDate>Sun, 12 Sep 2021 20:49:30 -0600</pubDate><guid>https://blog.jbkconsultingllc.com/posts/add-sass-to-phoenix-with-esbuild/</guid><description>&lt;p&gt;If you are starting a new project with The &lt;a href="https://www.phoenixframework.org/"&gt;Phoenix Framework&lt;/a&gt; version 1.6, you&amp;rsquo;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 &lt;a href="https://esbuild.github.io/"&gt;Esbuild&lt;/a&gt; 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&amp;rsquo;s a way to add Sass back into your project.&lt;/p&gt;</description></item></channel></rss>