What we do
Tools
Industries
Department
How we workLet's talk →
Home/Ruby Developer for Scripts, Gems and Sinatra
Ruby Development

Ruby Developer for Cron Scripts, Rake Tasks and Sinatra Apps Outside Rails

A cron job emails the stock report every morning. A small Sinatra app catches the payment webhooks. The iOS release goes out through a Fastfile. All three are Ruby, none of them is Rails, and the person who wrote them left a Gemfile.lock and not much else. Then the report doesn't arrive one day, and nobody can run the script by hand.

Ruby that turns up outside Rails

Ruby is all through business tooling, often in places nobody would call an app. Knowing which kind you've found tells you what the job is.

What you found What it's doing What breaks first
A .rb file in the crontab, or a Rakefile with scheduled tasks A job that pulls, cleans or sends data on a timer Cron's short PATH finds the system Ruby instead of the one the script was built for, so it fails only when it's run on schedule.
A config.ru and a small Sinatra or Roda app A webhook receiver or a small internal API A provider changes a payload field and the app quietly stores nothing, because no one checks what came in.
A Fastfile in a mobile app repository fastlane, automating builds, signing and store uploads An old fastlane version that can't keep up with Apple or Google changing their upload requirements.
A Gemfile pointing at a private repository An internal gem that other code depends on Nobody knows which apps pin which version, so a fix in the gem never reaches them.
Cookbooks and a Berksfile, or a Capfile Chef server configuration or Capistrano deploys, both written in Ruby The servers they describe have changed since, and running the old code against them does damage.
A _config.yml next to a Gemfile in the website repository A Jekyll static site The build only works on an old Ruby, so nobody can update the site's pages.

Bringing an orphaned Ruby script back to life

None of these steps change what the code does. They make it run the same way twice, on a machine that isn't its author's.

  1. 1

    Find out which Ruby it expects

    .ruby-version Gemfile.lock

    A .ruby-version file, or a ruby line in the Gemfile, names the version. The BUNDLED WITH line at the end of Gemfile.lock names the Bundler it was locked with.

    Watch for: Ruby 3.0 and older won't build against OpenSSL 3, which current Linux releases ship. That's often why an old script won't even install on a fresh server.

  2. 2

    Install from the lockfile, not from scratch

    bundle install bundle exec ruby report.rb

    bundle install reads Gemfile.lock and installs the exact gem versions it lists. Running through bundle exec makes the script use those versions and ignore whatever else is on the machine.

  3. 3

    Make the scheduler use the same Ruby

    Cron starts jobs with a bare PATH, so a script that works in your terminal can run under a different Ruby overnight. Call the version manager's Ruby by its full path, or run the job in a container with the right one built in.

  4. 4

    Take the secrets out of the code

    API keys and passwords move into environment variables or the host's secret store, and the script gets its own account in each system it logs into, not a former employee's.

  5. 5

    Log what each run did

    Rows read, rows written and the error if there was one, sent somewhere your team already looks. A run that finished with nothing to process deserves a line as well.

  6. 6

    Move to a supported Ruby on purpose

    Ruby 3.3, 3.4 and 4.0 get fixes now. Change the version on a branch, run the tests or a dry run against yesterday's data, and only then point the schedule at it.

    Watch for: older gems that relied on how keyword arguments worked before Ruby 3.0. They tend to fail at the first call that passes options.

Plain Ruby work, scoped as a project

n-frames builds and takes over Ruby work as a defined project: getting a script or gem running on a proper host, extending it, or replacing it when it's doing an integration's job badly. You end up with the code in a repository your company owns, a note on everything it touches, and a working run to compare against.

If the Ruby turns out to be a full web application, the Ruby on Rails developer page covers that work, including slow queries and version upgrades. A Ruby service other systems call is closer to API development, and a bigger server side with its own database sits under backend development.

Ruby without Rails, asked directly

Is this for Ruby on Rails, or Ruby used outside a framework?

Mostly Ruby outside a framework, or with a light one: scheduled scripts, Rake tasks, Sinatra apps, internal gems, fastlane and Chef code. n-frames works on Rails apps too, and the Rails page goes into that in depth.

What if our Ruby project is small and well-defined?

Then it's scoped as a small job: what goes in, what comes out, and how you'll know it worked. Moving one cron script onto a supported Ruby with logging is a modest piece of work. The scope only grows if the reading turns up something you'd want to hear about, and that's your decision.

How do you handle a script that was never really documented?

By running it before changing it. We get it working from its lockfile on a clean machine, then trace what it reads, what it writes and which systems it logs into. That trace becomes the documentation: a short file in the repository saying what the script does, when it runs and what to look at when it fails.

Is the Ruby quote really free, with no obligation?

Yes, it's free and you're not committed to anything. To quote, we need the code or access to wherever it runs, plus a sentence on what it's meant to do. If it lives on a server, the output of ruby -v and its crontab line help a lot.

Let's talk

Tell us the one thing your team does manually that eats up time. We read every message and reply within a day.