<commit_before>from couchexport.models import GroupExportConfiguration, SavedBasicExport
from couchdbkit.exceptions import ResourceNotFound
from datetime import datetime
import os
import json
from couchexport.tasks import Temp

def export_for_group(export_id, output_dir):
    try:
        config = GroupExportConfiguration.get(export_id)
    except ResourceNotFound:
        raise Exception("Couldn't find an export with id %s" % export_id)
    
    for config, schema in config.all_exports:
        tmp, _ = schema.get_export_files(format=config.format)
        payload = Temp(tmp).payload
        if output_dir == "couch":
            saved = SavedBasicExport.view("couchexport/saved_exports", 
                                          key=json.dumps(config.index),<commit_msg>rebuild checkpoints when something breaks while updating group exports<commit_after>from couchexport.models import GroupExportConfiguration, SavedBasicExport
from couchdbkit.exceptions import ResourceNotFound
from datetime import datetime
import os
import json
from couchexport.tasks import Temp, rebuild_schemas
from couchexport.export import SchemaMismatchException
from dimagi.utils.logging import notify_exception

def export_for_group(export_id, output_dir):
    try:
        config = GroupExportConfiguration.get(export_id)
    except ResourceNotFound:
        raise Exception("Couldn't find an export with id %s" % export_id)
    
    for config, schema in config.all_exports:
        try:
            tmp, _ = schema.get_export_files(format=config.format)
        except SchemaMismatchException, e:
            # fire off a delayed force update to prevent this from happening again
            rebuild_schemas.delay(config.index)
            msg = "Saved export failed for group export {index}. The specific error is {msg}."
            notify_exception(None, msg.format(index=config.index,
                                              msg=str(e)))
            # TODO: do we care enough to notify the user?
            # This is typically only called by things like celerybeat.
            continue

        payload = Temp(tmp).payload
        if output_dir == "couch":
            saved = SavedBasicExport.view("couchexport/saved_exports", 
                                          key=json.dumps(config.index),
{'fraction_non_alphanumeric': 0.06513243595310464, 'fraction_numerical': 0.0, 'mean_word_length': 2.8208955223880596, 'pattern_counts': {'":': 2, '<': 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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1178127', 'n_tokens_mistral': 582, 'n_tokens_neox': 572, 'n_words': 174}