def flush(self, force=False):
    now = tz_now()
    if (force or any([(len(events) >= 1000) for events in self.buff.values()])):
        for (cls, events) in self.buff.items():
            logger.debug(f'{cls.__name__}.objects.bulk_create({len(events)})')
            for e in events:
                if (not e.created):
                    e.created = now
                e.modified = now
            try:
                cls.objects.bulk_create(events)
            except Exception:
                for e in events:
                    try:
                        e.save()
                    except Exception:
                        logger.exception('Database Error Saving Job Event')
            for e in events:
                emit_event_detail(e)
        self.buff = {}
def flush(self, force=False):
    now = tz_now()
    if (force or any([(len(events) >= 1000) for events in self.buff.values()])):
        for (cls, events) in self.buff.items():
            logger.debug(f'{cls.__name__}.objects.bulk_create({len(events)})')
            for e in events:
                if (not e.created):
                    e.created = now
                e.modified = now
            try:
                cls.objects.bulk_create(events)
            except Exception:
                for e in events:
                    try:
                        e.save()
                    except Exception:
                        logger.exception('Database Error Saving Job Event')
            for e in events:
                emit_event_detail(e)
        self.buff = {}