OCT 4, 2016
Written by Nickie McCabe

Bootstrapping a Simple Blog Scheduler

This past quarter, one of our goals was to increase our blogging efforts. Blog posts not only provide us with a platform to share our ideas and give insight into the Corgibytes culture, but they are also another way for us to meaningfully reflect on our work. As the number of blog entries we were writing slowly crept upward, our Lead Content Whisperer, Jo, had a simple request: a way to schedule the publishing of blog posts in advance. I happily volunteered to make her request a reality.

Anatomy of a Website

Prior to volunteering for this task, I actually had very little knowledge of the ins and outs of how our website and blog were structured and deployed. This was a perfect excuse to take a peek and see how everything was connected. Here’s what I found: our website is hosted on an AWS S3 server and rendered using Jekyll. The source code is stored in a GitHub repository, and we use Codeship for continuous integration and delivery. So, with this knowledge, how could I give Jo the capability of scheduling blog posts in advance?

Building a Post Scheduler

After conferring with my colleagues and discussing various options, we decided the simplest approach would probably be best. Given the capabilities of Jekyll, Jo was already able to commit and push out blog posts with future publish dates. The posts weren’t published to the live website until the website code was rebuilt on the publish date. So, all that was really needed was to trigger Codeship to rebuild the code whenever a blog post was to be published. Again, in the vein of keeping things simple, we decided we would just rebuild the latest commit every morning at 6:00 a.m.

To accomplish this task, I turned to an old friend. As I’ve written about previously, Ein is our virtual office assistant. She’s very good at performing rote tasks, so I simply updated her schedule to rebuild our corgibytes-com project on Codeship every morning. This required calling the Codeship API to get the latest build ID of the project and invoking the codeship_restart_build script through the API.

Here’s a look at a portion of the code:

def restart_build(build_id)
    url = URI("https://codeship.com/api/v1/builds/#{build_id}/restart.json?api_key=#{@api_key}")
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    request = Net::HTTP::Post.new(url)
    response = http.request(request)
    JSON.parse(response.read_body)['status'] == 'success' ? true : false
  rescue Exception => e

Another Automated Success

As we’ve increased our content output, our blog scheduler has performed exactly as Jo envisioned. Jo can push new blog posts whenever it’s convenient for her and be assured they’ll go live on their post date. She can focus her time and energy on other tasks rather than worrying about publishing a new blog post on a specific day and time. And that has kept Jo quite happy!

So, what’s your approach to posting blog posts? Have you built something yourself? Do you use an existing third-party tool? Let us know in the comments! We’re always interested in learning more about other workflows!