<commit_before>import time
from datetime import datetime
from django.core.management import setup_environ
from sendinel import settings
setup_environ(settings)

from sendinel.backend.models import ScheduledEvent

def run(run_only_one_time = False):
    while True:
        dueEvents = ScheduledEvent.objects \
                        .filter(state__exact = 'new') \
                        .filter(send_time__lte=datetime.now())
        for event in dueEvents:
            try:
                data = event.sendable.get_data_for_sending()
                print "Trying to send: %s" % str(event.sendable)
            except Exception as e:
                print "Failed to get data for " + event + " exception " + str(e)
                
                event.state = "failed"
                event.save()
                continue
            
            # TODO error handling
            try:
                for entry in data:
                    print "  sending: %s" % str(entry)
                    entry.send()
            except Exception as e:
                print "Failed to send: " + str(entry)
                event.state = "failed"
                event.save()
                    
            
            event.state = 'sent'
            event.save()
            del data
        del dueEvents
            #TODO Exception Handling
        if run_only_one_time: break
        time.sleep(5)


if __name__ == "__main__":
    run()<commit_msg>Debug prints should show something.<commit_after>import time
from datetime import datetime
from django.core.management import setup_environ
from sendinel import settings
setup_environ(settings)

from sendinel.backend.models import ScheduledEvent

def run(run_only_one_time = False):
    while True:
        dueEvents = ScheduledEvent.objects \
                        .filter(state__exact = 'new') \
                        .filter(send_time__lte=datetime.now())
        for event in dueEvents:
            try:
                data = event.sendable.get_data_for_sending()
                print "Trying to send: %s" % str(event.sendable)
            except Exception as e:
                print "Failed to get data for " + event + " exception " + str(e)
                
                event.state = "failed"
                event.save()
                continue
            
            # TODO error handling
            try:
                for entry in data:
                    print "  sending: %s" % str(entry)
                    entry.send()
            except Exception as e:
                print "Failed to send: " + str(entry) + " exception " + str(e)
                event.state = "failed"
                event.save()
                    
            
            event.state = 'sent'
            event.save()
            del data
        del dueEvents
            #TODO Exception Handling
        if run_only_one_time: break
        time.sleep(5)


if __name__ == "__main__":
    run()
{'fraction_non_alphanumeric': 0.07614213197969544, 'fraction_numerical': 0.0006768189509306261, 'mean_word_length': 1.3723916532905296, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1183289', 'n_tokens_mistral': 764, 'n_tokens_neox': 735, 'n_words': 209}