[wip]django db timeout in epoll mode

class EventWorker():
    @classmethod
    def get_task(cls):
        """Get first waiting task with FIFO order

        :returns: task
        :rtype: dict or None
        """
        try:
            event_task = EventTask.objects.all().exclude(status__in=COMPLETE_STATUS).latest()
        except:
            logger.debug('get no task, continue...')
            return None
        return event_task

    @classmethod
    def start(cls):
        while True:
            task = cls.get_task()
            if not task:
                time.sleep(1)
                continue
            
            logger.info('get task {}, will start it.'.format(task))
            task.status = STATUS_IN_PROGRESS
            task.started_at = datetime.datetime.now()
            task.save()
            task_serializers = EventTaskSerializer(task)
            worker = EventHandler(task_serializers.data)
            worker.start()
            time.sleep(1)

EventWorker.start()

TODO:超过3小时后读不到task了,分析原因

comments powered by Disqus