<commit_before>require 'aws-sdk'

module Transcoder
  def self.handle_event(args)
    res = config.read_job({id: args['jobId']})
    job = res && res.job
    return false if !job || !job.user_metadata
    progress = Progress.find_by_global_id(job.user_metadata['progress_id'])
    record = nil
    new_record = {}
    if job.user_metadata['conversion_type'] == 'audio'
      record = ButtonSound.find_by_global_id(job.user_metadata['audio_id'])
      new_record['filename'] = job.outputs[0].key
      new_record['duration'] = job.outputs[0].duration
      new_record['content_type'] = 'audio/mp3'
    elsif job.user_metadata['conversion_type'] == 'video'
#      record = ButtonSound.find_by_global_id(job.user_metadata['video_id'])
      new_record['filename'] = job.outputs[0].key
      new_record['duration'] = job.outputs[0].duration
      new_record['content_type'] = 'video/mp4'
      new_record['thumbnail_filename'] = job.outputs[0].key + '.0000.png'
    else
      return false
    end
    if args['state'] == 'COMPLETED'
      record.update_media_object(new_record) if record
    elsif args['state'] == 'ERROR'
      # record the error on the record
      record.media_object_error({code: args['errorCode'], job: args['jobId']})<commit_msg>message is a subresult, apparently, in sns<commit_after>require 'aws-sdk'

module Transcoder
  def self.handle_event(args)
    args = JSON.parse(args['Message'])
    res = config.read_job({id: args['jobId']})
    job = res && res.job
    return false if !job || !job.user_metadata
    progress = Progress.find_by_global_id(job.user_metadata['progress_id'])
    record = nil
    new_record = {}
    if job.user_metadata['conversion_type'] == 'audio'
      record = ButtonSound.find_by_global_id(job.user_metadata['audio_id'])
      new_record['filename'] = job.outputs[0].key
      new_record['duration'] = job.outputs[0].duration
      new_record['content_type'] = 'audio/mp3'
    elsif job.user_metadata['conversion_type'] == 'video'
#      record = ButtonSound.find_by_global_id(job.user_metadata['video_id'])
      new_record['filename'] = job.outputs[0].key
      new_record['duration'] = job.outputs[0].duration
      new_record['content_type'] = 'video/mp4'
      new_record['thumbnail_filename'] = job.outputs[0].key + '.0000.png'
    else
      return false
    end
    if args['state'] == 'COMPLETED'
      record.update_media_object(new_record) if record
    elsif args['state'] == 'ERROR'
      # record the error on the record
      record.media_object_error({code: args['errorCode'], job: args['jobId']})
{'fraction_non_alphanumeric': 0.1449727201870616, 'fraction_numerical': 0.00857365549493375, 'mean_word_length': 3.984466019417476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7613550', 'n_tokens_mistral': 837, 'n_tokens_neox': 828, 'n_words': 147}