‹ Dan Peterson

Page 2


As part of Heroku Private Spaces we attach extra Elastic Network Interfaces to instances, and we do that in Go with aws-sdk-go.

The process isn’t the most idempotent and we recently discovered we were occasionally leaking ENIs. This could happen if we created an ENI and then encountered an error later in the process, such as when attaching it to an instance. I set out this morning to find a better way.

When an ENI is created, it can be assigned a description. Previously we used descriptions only for the ENI’s function (eg, “nat”) and not anything specific to the instance the ENI was intended for. After seeing that listing ENIs allows filtering on the description, I decided to make that the foundation of the new approach.

One of my favorite localized Go refactorings is reducing nesting by using return as early as possible. Take this example, based on a recently-refactored function at Heroku:

func example() error {
  if err := start(); err != nil {
    existing, err := fetchExisting()
    if err != nil {
      return err
    }

    if existing.IsWorking() {
      return nil
    } else {
      return errors.New("found existing but it's not working")
    }
  }

  return nil
}

This can be hard to follow due to nesting inside if ...; err != nil and use of else. I prefer to return as early as possible and avoid else. Applying that, it now looks something like this:

At Heroku we use Travis CI to run project tests on push to GitHub. While Travis CI offers PostgreSQL in their environment, it’s version 9.1. A project I’m working on recently started using PostgreSQL 9.2’s JSON data type, which 9.1 does not have.

Needing 9.2, I searched for ways to make it available in the Travis CI environment. I found guides that suggested upgrading PostgreSQL in a before_script but I didn’t have much luck with that approach. Plus, it would add time to each build which I was hoping to avoid. I knew Heroku Postgres offered 9.2 by default, what I really wanted was a fresh Heroku Postgres database for every test run.

Since July 30th, I’ve been using ledger (on GitHub) to track my personal finances. What did I use before? I’m ashamed to say nothing beyond my banks’ sites.

I stumbled upon ledger via this blog post, linked from Hacker News. It took me a while to try it, for a few reasons. First, I had a weird notion that there would be a better time in my various “fiscal cycles” to start using such a thing. Should I wait until the end of the monthly statement periods for my various accounts? No, this was just procrastination. Second, I need to easily deal in both USD and CAD. I live in Canada and am paid in CAD but being a US citizen from Arizona I still have many dealings in the US that involve USD. My Canadian and US RBC accounts are linked and it’s easy (and instant) to transfer between them, though I usually only go from my Canadian accounts to my US accounts. That had been a big barrier in trying things like bucketwise, though I do like its concept.

« Older posts Newer posts »