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

Background Procrastination

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Background Procrastination

Sometimes it's good for programs to put things off for later. Talk given as a lightning talk at the May 2014 meeting of Dayton Clean Coders. http://daytoncleancoders.com

Michael Yockey

May 20, 2014

Transcript

11 slides
  1. “That’s why there’s the snooze bar. Nothing like starting off

    the day with a little procrastination" Photo by Rebecca O’Malley https://www.flickr.com/photos/25212862@N04/3970026388/
  2. class Importer! def self.schedule! Delayed::Job.enqueue Importer.new! end! ! def perform!

    import_source.each do |import_row|! record = Record.from_import(import_row)! # process record...! end! end! end Importer
  3. class Importer! def self.schedule! Delayed::Job.enqueue Importer.new! end! ! def perform!

    import_source.each do |import_row|! record = Record.from_import(import_row)! Processor.schedule record.id! end! end! end Importer
  4. class Processor! def self.schedule(id)! Delayed::Job.enqueue(Processor.new(id))! end! ! def initialize(record_id)! @record_id

    = record_id! end! ! def perform! return if complete?! # Process record...! end! ! def complete?! end! end Processor

More Decks by Michael Yockey

Other Decks in Programming