<commit_before>class VideoWorker < BackgrounDRb::MetaWorker
  set_worker_name :video_worker
  def create(args = nil)
    logger.info("Creating converter worker.")
  end
  
  #Queue up the video for conversion
  def queue_convert(args)
    conversion = Conversion.find(args[:conversion_id])
    conversion.update_attributes({:status => "queued"})
    thread_pool.defer(:convert,args)
  end
  
  #Run the conversion of the video
  def convert(args = nil)
    #Open all the objects we'll need
    logger.info("Calling convert method for conversion #{args[:conversion_id]}.")
    conversion = Conversion.find(args[:conversion_id])
    video = conversion.video
    profile = conversion.profile
    conversion.append_to_log "Starting conversion work on #{video.id}: #{video.name} - #{video.asset.path}"
    logger.info("Starting conversion work on #{video.id}: #{video.name} - #{video.asset.path}")
    conversion.update_attributes({:status => "active", :start_time => Time.now})
    
    #Create the temporary file, and prepare the command
    tempfile = Tempfile.new([File.basename(video.asset_file_name, File.extname(video.asset_file_name)), ".#{profile.extension}"])
    command = profile.command
    command.sub!("outfile", tempfile.path).sub!("infile", video.asset.path)
    conversion.append_to_log command
    logger.info(command)
    conversion.append_to_log "Closing tempfile accessor"
    logger.info("Closing tempfile accessor")
    tempfile.close
    
    #Run the command
    conversion.append_to_log "Starting command"
    logger.info("Exec'ing command")
    system command
    
    #Start to save the final output
    conversion.append_to_log "Command complete"
    logger.info("Exec complete!  Opening tempfile up again")
    conversion.update_attributes({:status => "saving"})
    tempfile.open
    
    #Verify the file isn't empty, indicating a conversion error
    if tempfile.size <= 0
      conversion.append_to_log "Expected output file is empty.  Cancelling."
      logger.info("Expected output file is empty.  Cancelling.")
      conversion.update_attributes({:status => "failed", :end_time => Time.now})
    else
      #Build the new video object, mark it for no auto-thumbnail generation
      conversion.append_to_log "Starting save"
      logger.info("Starting save")
      new_v = Video.new(:name => video.name, :parent_id => video.id, :profile_id => profile.id, :no_thumbs => true)<commit_msg>Reduced pool size, added height and width parameters to command<commit_after>class VideoWorker < BackgrounDRb::MetaWorker
  set_worker_name :video_worker
  pool_size 5
  def create(args = nil)
    logger.info("Creating converter worker.")
  end
  
  #Queue up the video for conversion
  def queue_convert(args)
    conversion = Conversion.find(args[:conversion_id])
    conversion.update_attributes({:status => "queued"})
    thread_pool.defer(:convert,args)
  end
  
  #Run the conversion of the video
  def convert(args = nil)
    #Open all the objects we'll need
    logger.info("Calling convert method for conversion #{args[:conversion_id]}.")
    conversion = Conversion.find(args[:conversion_id])
    video = conversion.video
    profile = conversion.profile
    conversion.append_to_log "Starting conversion work on #{video.id}: #{video.name} - #{video.asset.path}"
    logger.info("Starting conversion work on #{video.id}: #{video.name} - #{video.asset.path}")
    conversion.update_attributes({:status => "active", :start_time => Time.now})
    
    #Create the temporary file, and prepare the command
    tempfile = Tempfile.new([File.basename(video.asset_file_name, File.extname(video.asset_file_name)), ".#{profile.extension}"])
    command = profile.command
    command.sub!("outfile", tempfile.path).sub!("infile", video.asset.path)
    command.sub!(":width", video.width).sub!(":height", video.height)
    conversion.append_to_log command
    logger.info(command)
    conversion.append_to_log "Closing tempfile accessor"
    logger.info("Closing tempfile accessor")
    tempfile.close
    
    #Run the command
    conversion.append_to_log "Starting command"
    logger.info("Exec'ing command")
    system command
    
    #Start to save the final output
    conversion.append_to_log "Command complete"
    logger.info("Exec complete!  Opening tempfile up again")
    conversion.update_attributes({:status => "saving"})
    tempfile.open
    
    #Verify the file isn't empty, indicating a conversion error
    if tempfile.size <= 0
      conversion.append_to_log "Expected output file is empty.  Cancelling."
      logger.info("Expected output file is empty.  Cancelling.")
      conversion.update_attributes({:status => "failed", :end_time => Time.now})
    else
      #Build the new video object, mark it for no auto-thumbnail generation
      conversion.append_to_log "Starting save"
      logger.info("Starting save")
      new_v = Video.new(:name => video.name, :parent_id => video.id, :profile_id => profile.id, :no_thumbs => true)
{'fraction_non_alphanumeric': 0.11524537409493162, 'fraction_numerical': 0.0006033789219629927, 'mean_word_length': 3.9680319680319682, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 23, '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': '2199584', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1430, 'n_words': 379}