<commit_before>desc "Mark all members of a Collection complete"
task complete_collection: :environment do
  colid = ENV['COLLECTION']
  abort "usage: COLLECTION=[collection id] rake complete_collection" unless colid
  begin
    col = Collection.find( colid )
    puts "completing objects in collection: #{col.title.first}"
    col.member_objects.each do |obj|
      advance(obj, 'metadata_review') if obj.state == 'pending'
      advance(obj, 'final_review') if obj.state == 'metadata_review'
      advance(obj, 'complete') if obj.state == 'final_review'
    end
  rescue => e
    puts "Error: #{e.message}"
  end
end

def advance(obj, state)
  puts "#{obj.id}: #{obj.state} -> #{state}"
  obj.state = state
  obj.save!
end<commit_msg>Fire an event when completing a collection<commit_after>desc "Mark all members of a Collection complete"
task complete_collection: :environment do
  colid = ENV['COLLECTION']
  abort "usage: COLLECTION=[collection id] rake complete_collection" unless colid
  begin
    col = Collection.find( colid )
    puts "completing objects in collection: #{col.title.first}"
    col.member_objects.each do |obj|
      advance(obj, 'metadata_review') if obj.state == 'pending'
      advance(obj, 'final_review') if obj.state == 'metadata_review'
      advance(obj, 'complete') if obj.state == 'final_review'
    end
  rescue => e
    puts "Error: #{e.message}"
  end
end

def advance(obj, state)
  puts "#{obj.id}: #{obj.state} -> #{state}"
  obj.state = state
  obj.save!
  manifest_event_generator.record_updated(obj)
end

def manifest_event_generator
  @manifest_event_generator ||= ManifestEventGenerator.new(Plum.messaging_client)
end
{'fraction_non_alphanumeric': 0.12214199759326114, 'fraction_numerical': 0.0, 'mean_word_length': 4.296178343949045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3811580', 'n_tokens_mistral': 520, 'n_tokens_neox': 531, 'n_words': 149}