Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Recurring Tasks in Elixir

Recurring Tasks in Elixir

The problem: I want to email myself a weekly summary of Todo items I've completed. We know how to use cron or a variation of Ruby's Resque/Sidekiq scheduled jobs, but how would we approach this in Elixir?

We'll walk through a 40-line solution using a GenServer that will leave you wondering why we ever put up with installing an entire background job system for such a simple task.

Desmond Bowe

June 15, 2016
Tweet

More Decks by Desmond Bowe

Other Decks in Programming

Transcript

  1. cron • PRO • everywhere • ??? • CON •

    crontab -l • 00 09-18 * * 1-5 /usr/bin/my-sweet-script
  2. cron • PRO • everywhere • ??? • CON •

    crontab -l • 00 09-18 * * 1-5 /usr/bin/my-sweet-script
  3. cron • PRO • everywhere • ??? • CON •

    crontab -l • 00 09-18 * * 1-5 /usr/bin/my-sweet-script
  4. cron • PRO • everywhere • ??? • CON •

    crontab -l • 00 09-18 * * 1-5 /usr/bin/my-sweet-script • weird environment rules
  5. cron • PRO • everywhere • ??? • CON •

    crontab -l • 00 09-18 * * 1-5 /usr/bin/my-sweet-script • weird environment rules not a big deal on Heroku
  6. Resque/Sidekiq • PRO • reasonable syntax • access to your

    app • CON • 1,000s of lines of code • requires external database • requires extra copy of app
  7. GenServer • PRO • lightweight (~40 LOC) • doesn’t require

    separate app instance • leverages familiar Timex functionality • does not require additional database • can call any function in your app • CON
  8. GenServer • PRO • lightweight (~40 LOC) • doesn’t require

    separate app instance • leverages familiar Timex functionality • does not require additional database • can call any function in your app • CON • …
  9. GenServer • PRO • lightweight (~40 LOC) • doesn’t require

    separate app instance • leverages familiar Timex functionality • does not require additional database • can call any function in your app • CON • no built-in syntax for complex recurrence
  10. GenServer Other Thoughts • different schedules for users • use

    individual GenServers • have job requeue itself for next interval • expose the timer to read/cancel/update