Skip to content

Commit

Permalink
fix Py2 issue with issue #111
Browse files Browse the repository at this point in the history
  • Loading branch information
wjo1212 committed Jan 7, 2019
1 parent 7b1cefe commit 4b35787
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions aliyun/log/consumer/shard_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .tasks import consumer_fetch_task, consumer_initialize_task, \
consumer_process_task, consumer_shutdown_task
from .exceptions import ClientWorkerException
import six


class ShardConsumerWorker(object):
Expand Down Expand Up @@ -200,10 +201,9 @@ def _sample_log_error(self, result):
if current_time - self.last_log_error_time <= 5:
return

self.logger.warning(exc, exc_info=exc)
self.logger.warning(exc, exc_info=result.exc_info)
self.last_log_error_time = current_time


def _update_status(self, task_succcess):
if self.consumer_status == ConsumerStatus.SHUTTING_DOWN:
# if no task or previous task suceeds, shutting-down -> shutdown complete
Expand Down
14 changes: 12 additions & 2 deletions aliyun/log/consumer/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from .config import CursorPosition
from ..logexception import LogException
import time
import six
import sys

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -60,10 +62,20 @@ def process(self, log_groups, check_point_tracker):
class TaskResult(object):
def __init__(self, task_exception):
self.task_exception = task_exception
self._exc_info = None
if six.PY2 and task_exception is not None:
self._exc_info = sys.exc_info()

def get_exception(self):
return self.task_exception

@property
def exc_info(self):
if six.PY3:
return self.task_exception
else:
return self._exc_info


class ProcessTaskResult(TaskResult):
def __init__(self, rollback_check_point):
Expand Down Expand Up @@ -113,8 +125,6 @@ def consumer_process_task(processor, log_groups, check_point_tracker):
check_point = processor.process(log_groups, check_point_tracker)
check_point_tracker.flush_check()
except Exception as e:
import traceback
traceback.print_exc()
return TaskResult(e)
return ProcessTaskResult(check_point)

Expand Down

0 comments on commit 4b35787

Please sign in to comment.