100 Days of Flatiron School Bootcamp

I’ve reached the 100-day mark. I have to say, I honestly thought I’d be done by now. I’m 82% of the way there. It’s going to be a mad dash to the end. I really, really, really don’t want to pay another full month’s tuition when I finish a few days into that billing cycle. So it’s pretty simple. I have to finish by June 27th. We’ll see what happens. I have a backup plan if I’m literally working on my final project and I’m sure I’m not going to make it. We’ll see if it comes to that or not…

Tonight had me learning about workers in Rails apps and specifically the Sidekiq gem. It’s pretty sweet how easily it can abstract out letting a task run in the background so a user can keep on with their work. The example in the lesson is loading a large CSV of leads into your web app. First, you create a worker file in app/workers, make sure that file has include Sidekiq::Worker, then take the long-running process and input that into #perform.

# app/workers/leads_worker.rb

class LeadsWorker
  require 'csv'
  include Sidekiq::Worker

  def perform(leads_file)
    CSV.foreach(leads_file, headers: true) do |lead|
      Customer.create(email: lead[0], first_name: lead[1], last_name: lead[2])
    end
  end
end

After that replace the long-running process code in your controller by running the worker.

# app/controllers/customers_controller.rb
class CustomersController < ApplicationController

  def index
    @customers = Customer.all
  end

  def upload
    LeadsWorker.perform_async(params[:leads].path)
    redirect_to customers_path
  end
end

Now if you upload a large CSV file via the form at /customers, when you submit it everything will move along. Then as you refresh the index page /customers it will have a growing list until the CSV file is done being imported into the DB.

I also did a few lessons on Consuming APIs. Luckily for me, this is not completely new to me so I have a good base to work off of. Actually, this shouldn’t be completely new to anyone in the program as earlier labs deal with pulling API data and rendering it to the DOM. My main note on APIs is the querystring which trips me up sometimes.

  • ? after the URL
  • param=value&param2=value
  • ie. https://api.example.com/places?name=tonys&city=nashville

Although, I also learned how Postman has a params section with key/value pairs which helps with building out the query string.

Time spent today: 1:53
Time spent total: 369:58
Lessons completed today: 7
Lessons completed total: 621