<commit_before>class EntryImage
  include Sidekiq::Worker
  sidekiq_options retry: false

  def perform(entry_id, image = nil)
    @entry = Entry.find(entry_id)
    @image = image
    if @image
      receive
    else
      schedule
    end
  rescue ActiveRecord::RecordNotFound
  end

  def schedule
    if !@entry.processed_image?
      options = build_options
      Sidekiq::Client.push(
        'args'  => EntryImage.build_find_image_args(@entry, options),
        'class' => 'FindImage',
        'queue' => 'images',
        'retry' => false
      )
    end
  end

  def build_options
    options = {
      public_id: @entry.public_id
    }
    if @entry.tweet?
      tweet = (@entry.tweet.retweeted_status?) ? @entry.tweet.retweeted_status : @entry.tweet
      if tweet.media?
        options["urls"] = [tweet.media.first.media_url_https.to_s]
      elsif tweet.urls?
        options["urls"] = tweet.urls.map {|url| url.expanded_url.to_s}
      end
    end
    options
  end

  def receive
    @entry.update_attributes(image: @image)
  end

  def self.build_find_image_args(entry, options = {})
    [entry.id, entry.feed_id, entry.url, entry.fully_qualified_url, entry.feed.site_url, entry.content, options]
  end

end<commit_msg>Pass public_id to image args<commit_after>class EntryImage
  include Sidekiq::Worker
  sidekiq_options retry: false

  def perform(entry_id, image = nil)
    @entry = Entry.find(entry_id)
    @image = image
    if @image
      receive
    else
      schedule
    end
  rescue ActiveRecord::RecordNotFound
  end

  def schedule
    if !@entry.processed_image?
      options = build_options
      Sidekiq::Client.push(
        'args'  => EntryImage.build_find_image_args(@entry, options),
        'class' => 'FindImage',
        'queue' => 'images',
        'retry' => false
      )
    end
  end

  def build_options
    options = {}
    if @entry.tweet?
      tweet = (@entry.tweet.retweeted_status?) ? @entry.tweet.retweeted_status : @entry.tweet
      if tweet.media?
        options["urls"] = [tweet.media.first.media_url_https.to_s]
      elsif tweet.urls?
        options["urls"] = tweet.urls.map {|url| url.expanded_url.to_s}
      end
    end
    options
  end

  def receive
    @entry.update_attributes(image: @image)
  end

  def self.build_find_image_args(entry, options = {})
    [entry.id, entry.feed_id, entry.url, entry.fully_qualified_url, entry.feed.site_url, entry.content, entry.public_id, options]
  end

end
{'fraction_non_alphanumeric': 0.11084043848964677, 'fraction_numerical': 0.0, 'mean_word_length': 2.78494623655914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2846766', 'n_tokens_mistral': 840, 'n_tokens_neox': 831, 'n_words': 170}