Пример #1
0
    def upload(self, key, filename, is_public=False, metadata=None):

        k = Key(self.bucket)
        k.key = key

        headers = {'Cache-Control': 'max-age=31536000'}
        content_type, encoding = mimetypes.guess_type(filename)
        if content_type is not None:
            headers['Content-Type'] = content_type
        if encoding == 'gzip':
            headers['Content-Encoding'] = 'gzip'

        if metadata is not None:
            for key in metadata:
                headers['x-amz-meta-' + key] = metadata[key]

        for _ in xrange(5):
            try:
                k.set_contents_from_filename(
                    filename,
                    headers=headers,
                    policy=('public-read' if is_public else 'private')
                )
                logger.info('Upload %s -> %s', filename, k.name)
                break

            except Exception as e:
                logger.exception(e)
                logger.warn('Try upload again')

        else:
            logger.error('Retry more than 5 times, give it up.')
            raise ExceedMaxRetryError()
Пример #2
0
def main():

    while True:
        try:
            watch_sqs()

        except Exception as e:
            logger.exception(e)
Пример #3
0
    def respond(self, api_record):

        ctrl_action = api_record.get('rails', {}).get('controller#action', '')

        for attempt in xrange(5):
            try:
                self.slack.chat.post_message(
                    setting.get('slack', 'channel'),
                    'Server error [%(ctrl_action)s]' % locals(),
                    username='******',
                    attachments=self._make_attachments(api_record),
                    icon_url=setting.get('slack', 'icon'))
                break

            except Exception as e:
                logger.exception(e)
                logger.error('Slack API failed, try again')
    def respond(self, api_record):

        ctrl_action = api_record.get('rails', {}).get('controller#action', '')

        for attempt in xrange(5):
            try:
                self.slack.chat.post_message(
                    setting.get('slack', 'channel'),
                    'Server error [%(ctrl_action)s]' % locals(),
                    username='******',
                    attachments=self._make_attachments(api_record),
                    icon_url=setting.get('slack', 'icon')
                )
                break

            except Exception as e:
                logger.exception(e)
                logger.error('Slack API failed, try again')
Пример #5
0
    def post(self):

        try:
            self.slack.chat.post_message(self.get_channel(),
                                         self.get_text(),
                                         username=self.get_username(),
                                         as_user=self.get_as_user(),
                                         parse=self.get_parse(),
                                         link_names=self.get_link_names(),
                                         attachments=self.get_attachments(),
                                         unfurl_links=self.get_unfurl_links(),
                                         unfurl_media=self.get_unfurl_media(),
                                         icon_url=self.get_icon_url(),
                                         icon_emoji=self.get_icon_emoji())

        except Exception as e:
            logger.exception(e)
            logger.error('Slack API failed, try again')
    def post(self):

        for _ in xrange(5):
            try:
                self.slack.chat.post_message(
                    self.get_channel(),
                    self.get_text(),
                    username=self.get_username(),
                    as_user=self.get_as_user(),
                    parse=self.get_parse(),
                    link_names=self.get_link_names(),
                    attachments=self.get_attachments(),
                    unfurl_links=self.get_unfurl_links(),
                    unfurl_media=self.get_unfurl_media(),
                    icon_url=self.get_icon_url(),
                    icon_emoji=self.get_icon_emoji()
                )
                break

            except Exception as e:
                logger.exception(e)
                logger.error('Slack API failed, try again')