<commit_before>class SendPeriodicEmailsJob < Struct.new(:frequency)

  def perform
    next_run_at = Time.new
    if frequency == 'daily'
      send_subscription_mails ActivityLog.scoped(:include => :activity_loggable, :conditions => ['created_at=?', Date.yesterday]), 'daily'
      next_run_at += 1.day
    elsif frequency == 'weekly'
      send_subscription_mails ActivityLog.scoped(:include => :activity_loggable, :conditions => ['created_at>=?', 7.days.ago]), 'weekly'
      next_run_at += 1.week
    elsif frequency == 'monthly'
      send_subscription_mails ActivityLog.scoped(:include => :activity_loggable, :conditions => ['created_at>=?', 30.days.ago]), 'monthly'
      next_run_at += 1.month
    end
     #add job for next period
    SendPeriodicEmailsJob.create_job(frequency, next_run_at, 1)
  end

  Subscription::FREQUENCIES.drop(1).each do |frequency|
    eval <<-END_EVAL
    def self.#{frequency}_exists?
      Delayed::Job.find(:first,:conditions=>['handler = ? AND locked_at IS ? AND failed_at IS ?',SendPeriodicEmailsJob.new('#{frequency}').to_yaml,nil,nil]) != nil
    end
    END_EVAL
  end

  def self.create_job frequency,t, priority=1
      Delayed::Job.enqueue(SendPeriodicEmailsJob.new(frequency),priority,t) unless send("#{frequency}_exists?")
  end<commit_msg>correct the activity_logs query for daily subscription<commit_after>class SendPeriodicEmailsJob < Struct.new(:frequency)

  def perform
    next_run_at = Time.new
    if frequency == 'daily'
      send_subscription_mails ActivityLog.scoped(:include => :activity_loggable, :conditions => ['created_at>=?', Date.yesterday]), 'daily'
      next_run_at += 1.day
    elsif frequency == 'weekly'
      send_subscription_mails ActivityLog.scoped(:include => :activity_loggable, :conditions => ['created_at>=?', 7.days.ago]), 'weekly'
      next_run_at += 1.week
    elsif frequency == 'monthly'
      send_subscription_mails ActivityLog.scoped(:include => :activity_loggable, :conditions => ['created_at>=?', 30.days.ago]), 'monthly'
      next_run_at += 1.month
    end
     #add job for next period
    SendPeriodicEmailsJob.create_job(frequency, next_run_at, 1)
  end

  Subscription::FREQUENCIES.drop(1).each do |frequency|
    eval <<-END_EVAL
    def self.#{frequency}_exists?
      Delayed::Job.find(:first,:conditions=>['handler = ? AND locked_at IS ? AND failed_at IS ?',SendPeriodicEmailsJob.new('#{frequency}').to_yaml,nil,nil]) != nil
    end
    END_EVAL
  end

  def self.create_job frequency,t, priority=1
      Delayed::Job.enqueue(SendPeriodicEmailsJob.new(frequency),priority,t) unless send("#{frequency}_exists?")
  end
{'fraction_non_alphanumeric': 0.13549618320610687, 'fraction_numerical': 0.006870229007633588, 'mean_word_length': 4.636559139784946, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3206251', 'n_tokens_mistral': 879, 'n_tokens_neox': 852, 'n_words': 165}