require 'active_support/core_ext/numeric/time'

class SyncMailingList
  @queue = :mailinglist

  def self.perform
    new.perform
  end

  attr_writer :members, :queue

  def perform
    members.each do |member|
      if updated_within_24_hours?(member)
        queue.enqueue(UpdateMailingList, member.id, member.class.to_s.demodulize)
      end
    end
  end

  private

  def updated_within_24_hours?(member)
    member.updated_at > 24.hours.ago
  end

  def queue
    @queue ||= Resque
  end

  def members
    @members ||= CapsuleMembers.all
  end
end


require 'active_support/core_ext/numeric/time'

class SyncMailingList
  @queue = :mailinglist

  def self.perform
    new.perform
  end

  attr_writer :members, :queue
  attr_reader :since

  def initialize(since = 24.hours.ago)
    @since = since
  end

  def perform
    members.each do |member|
      if requires_update?(member)
        queue.enqueue(UpdateMailingList, member.id, member.class.to_s.demodulize)
      end
    end
  end

  private

  def requires_update?(member)
    member.updated_at > since
  end

  def queue
    @queue ||= Resque
  end

  def members
    @members ||= CapsuleMembers.all
  end
end


Allow time since to be passed in if required
Allow time since to be passed in if required

We provide a sensible default (24 hours ago) so that things continue to work but allow
the time period to be passed in so we can manually run this job in a
console as necessary.

For example:

    SyncMailingList.new(1.week.ago).perform
