Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination and logging fixes #183

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scheduler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import traceback

from apscheduler.schedulers.blocking import BlockingScheduler
from raven.base import Client as RavenClient
Expand Down Expand Up @@ -41,7 +42,7 @@ def destalinate_job():
except Exception as e: # pylint: disable=W0703
raven_client.captureException()
if not get_config().sentry_dsn:
raise e
raise traceback.format_exc()
logging.info("END: destalinate_job")


Expand Down
48 changes: 44 additions & 4 deletions slacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,60 @@ def get_all_channel_objects(self, exclude_archived=True):
return all channels
if exclude_archived (default: True), only shows non-archived channels
"""
next_page = True
channels = []

url_template = self.url + "channels.list?exclude_archived={}&token={}"
if exclude_archived:
exclude_archived = 1
else:
exclude_archived = 0
url = url_template.format(exclude_archived, self.token)
payload = self.get_with_retry_to_json(url)
assert 'channels' in payload
return payload['channels']
orig_url = url

while next_page is True:
response = self.get_with_retry_to_json(url)
channels += response['channels']

if 'response_metadata' in response:
if 'next_cursor' in response['response_metadata']:
if response['response_metadata']['next_cursor']:
cursor = response['response_metadata']['next_cursor']

if cursor:
url = orig_url + "&cursor=" + response['response_metadata']['next_cursor']
else:
next_page = False

cursor = None

return channels

def get_all_user_objects(self):
next_page = True
members = []

url = self.url + "users.list?token=" + self.token
return self.get_with_retry_to_json(url)['members']
orig_url = url

while next_page is True:
response = self.get_with_retry_to_json(url)
members += response['members']

if 'response_metadata' in response:
if 'next_cursor' in response['response_metadata']:
if response['response_metadata']['next_cursor']:
cursor = response['response_metadata']['next_cursor']

if cursor:
url = orig_url + "&cursor=" \
+ response['response_metadata']['next_cursor']
else:
next_page = False

cursor = None

return members

def archive(self, channel_name):
url_template = self.url + "channels.archive?token={}&channel={}"
Expand Down
4 changes: 2 additions & 2 deletions utils/slack_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, slackbot, level):

def emit(self, record):
"""Do whatever it takes to actually log the specified logging record."""
self.slackbot.say(self.config.log_channel, record.getMessage())
self.slackbot.say(get_config().log_channel, record.getMessage())


def set_up_slack_logger(slackbot=None):
Expand All @@ -35,7 +35,7 @@ def set_up_slack_logger(slackbot=None):
"""
logger = logging.getLogger()

if logger.handlers:
if len(logger.handlers) > 1:
# We've likely already ran through the rest of this method:
return

Expand Down