You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: update_rank.rb
    path of file: ./repos/chordbook/app/jobs
    
    the code of the file until where you have to start completion: # Updates `rank` column on all models
class UpdateRank < ApplicationJob
  queue_as :low

  WINDOW = 1.month

  def perform
    rank_songsheets
    rank_tracks
    rank_albums
    rank_artists
    rank_genres
  end

  # Rank songsheets by:
  # 1. Number of distinct recent players (all anonymous users count as 1)
  # 2. Number of track listeners
  # 3. Newest to oldest
  def rank_songsheets
    exec <<-EOQ, since: WINDOW.ago
      WITH
        players AS (
          SELECT (properties->>'id')::uuid AS id, COUNT(DISTINCT user_id) AS count
          FROM ahoy_events
          WHERE name = 'view' AND properties->>'
    
  def rank_genres
    exec <<-EOQ, since: WINDOW.ago
      WITH
        players AS (
          SELECT tracks.genre_id, COUNT(DISTINCT user_id) AS count
          FROM ahoy_events
          JOIN songsheets ON songsheets.id = (properties->>'id')::uuid
          JOIN tracks ON tracks.id = songsheets.track_id
          WHERE name = 'view' AND properties->>'type' = 'Songsheet' AND time > :since
          GROUP BY 1
        ),
        ranked AS (
          SELECT
            genres.id,
            ROW_NUMBER() over (ORDER BY
              players.count DESC NULLS LAST,
              genres.listeners DESC NULLS LAST
            ) AS row
          FROM genres
          LEFT OUTER JOIN players ON players.genre_id = genres.id
        )
      UPDATE genres
      SET rank = ranked.row
      FROM ranked
      WHERE ranked.id = genres.id
    EOQ
  end