def handle(self, *args, **options): from the_tale.common.postponed_tasks.prototypes import PostponedTaskPrototype from the_tale.forum.prototypes import SubCategoryReadInfoPrototype, ThreadReadInfoPrototype from the_tale.post_service.prototypes import MessagePrototype PostponedTaskPrototype.remove_old_tasks() ThreadReadInfoPrototype.remove_old_infos() SubCategoryReadInfoPrototype.remove_old_infos() MessagePrototype.remove_old_messages()
def handle(self, *args, **options): from the_tale.common.postponed_tasks.prototypes import PostponedTaskPrototype from the_tale.forum.prototypes import SubCategoryReadInfoPrototype, ThreadReadInfoPrototype from the_tale.post_service.prototypes import MessagePrototype PostponedTaskPrototype.remove_old_tasks() ThreadReadInfoPrototype.remove_old_infos() SubCategoryReadInfoPrototype.remove_old_infos() MessagePrototype.remove_old_messages()
def test_remove_old_messages(self): message_1 = MessagePrototype.create(handler=TestHandler()) message_1._model.state = MESSAGE_STATE.PROCESSED message_1.save() message_2 = MessagePrototype.create(handler=TestHandler()) message_2._model.created_at -= datetime.timedelta(seconds=post_service_settings.MESSAGE_LIVE_TIME) message_2._model.state = MESSAGE_STATE.PROCESSED message_2.save() message_3 = MessagePrototype.create(handler=TestHandler()) message_3._model.created_at -= datetime.timedelta(seconds=post_service_settings.MESSAGE_LIVE_TIME) message_3.save() MessagePrototype.remove_old_messages() self.assertEqual(MessagePrototype._db_count(), 2) self.assertEqual(MessagePrototype._db_get_object(0).id, message_1.id) self.assertEqual(MessagePrototype._db_get_object(1).id, message_3.id)
def test_remove_old_messages(self): message_1 = MessagePrototype.create(handler=TestHandler()) message_1._model.state = MESSAGE_STATE.PROCESSED message_1.save() message_2 = MessagePrototype.create(handler=TestHandler()) message_2._model.created_at -= datetime.timedelta( seconds=post_service_settings.MESSAGE_LIVE_TIME) message_2._model.state = MESSAGE_STATE.PROCESSED message_2.save() message_3 = MessagePrototype.create(handler=TestHandler()) message_3._model.created_at -= datetime.timedelta( seconds=post_service_settings.MESSAGE_LIVE_TIME) message_3.save() MessagePrototype.remove_old_messages() self.assertEqual(MessagePrototype._db_count(), 2) self.assertEqual(MessagePrototype._db_get_object(0).id, message_1.id) self.assertEqual(MessagePrototype._db_get_object(1).id, message_3.id)