def generate_print_poster(_print): last_pic = last_pic_of_print(_print, 'raw') if not last_pic: # This print does not have any raw pics return rotated_jpg_url = save_print_snapshot( _print.printer, last_pic, f'private/{_print.id}_poster.jpg', to_container=settings.TIMELAPSE_CONTAINER, rotated=True, to_long_term_storage=True) if rotated_jpg_url: _print.poster_url = rotated_jpg_url _print.save() # Save the unrotated snapshot so that it is still viewable even after the print is done. unrotated_jpg_url = save_print_snapshot( _print.printer, last_pic, f'snapshots/{_print.printer.id}/latest_unrotated.jpg', rotated=False, to_long_term_storage=False) cache.printer_pic_set(_print.printer.id, {'img_url': unrotated_jpg_url}, ex=IMG_URL_TTL_SECONDS)
def send_failure_alert(printer, is_warning=True, print_paused=False): LOGGER.info( f'Printer {printer.user.id} {"smells fishy" if is_warning else "is probably failing"}. Sending Alerts' ) if not printer.current_print: LOGGER.warn( f'Trying to alert on printer without current print. printer_id: {printer.id}' ) return (_, rotated_jpg_url) = save_print_snapshot( printer.current_print, last_pic_of_print(printer.current_print, 'tagged'), unrotated_jpg_path=None, rotated_jpg_path= f'snapshots/{printer.id}/{printer.current_print.id}/{str(timezone.now().timestamp())}_rotated.jpg' ) # Calls wrapped in individual try/except because anyone of them could fail, and we still want the flow to continue try: if printer.user.alert_by_email: send_failure_alert_email(printer, rotated_jpg_url, is_warning, print_paused) except: sentryClient.captureException() try: send_failure_alert_pushbullet(printer, rotated_jpg_url, is_warning, print_paused) except: sentryClient.captureException() try: send_failure_alert_telegram(printer, rotated_jpg_url, is_warning, print_paused) except: sentryClient.captureException() try: if printer.user.is_pro and printer.user.alert_by_sms: send_failure_alert_sms(printer, is_warning, print_paused) except: sentryClient.captureException() try: if printer.user.is_pro: send_failure_alert_slack(printer, rotated_jpg_url, is_warning, print_paused) except: sentryClient.captureException() try: send_failure_alert_discord(printer, rotated_jpg_url, is_warning, print_paused) except: capture_exception()
def generate_print_poster(_print): unrotated_jpg_url = save_print_snapshot( _print, last_pic_of_print(_print, 'raw'), f'snapshots/{_print.printer.id}/{_print.id}/{str(timezone.now().timestamp())}_unrotated.jpg', rotated=False, to_long_term_storage=False) if unrotated_jpg_url: cache.printer_pic_set(_print.printer.id, {'img_url': unrotated_jpg_url}, ex=IMG_URL_TTL_SECONDS) rotated_jpg_url = save_print_snapshot( _print, last_pic_of_print(_print, 'raw'), f'private/{_print.id}_poster.jpg', to_container=settings.TIMELAPSE_CONTAINER, rotated=True, to_long_term_storage=True) if rotated_jpg_url: _print.poster_url = rotated_jpg_url _print.save()
def generate_print_poster(_print): (unrotated_jpg_url, rotated_jpg_url) = save_print_snapshot(_print, last_pic_of_print(_print, 'raw'), unrotated_jpg_path=f'snapshots/{_print.printer.id}/{_print.id}/{str(timezone.now().timestamp())}_unrotated.jpg', rotated_jpg_path=f'private/{_print.id}_poster.jpg') if unrotated_jpg_url: redis.printer_pic_set(_print.printer.id, {'img_url': unrotated_jpg_url}, ex=IMG_URL_TTL_SECONDS) if rotated_jpg_url: _print.poster_url = rotated_jpg_url _print.save()
def send_failure_alert(printer: Printer, is_warning: bool, print_paused: bool) -> None: LOGGER.info( f'Printer {printer.user.id} {"smells fishy" if is_warning else "is probably failing"}. Sending Alerts' ) if not printer.current_print: LOGGER.warn( f'Trying to alert on printer without current print. printer_id: {printer.id}' ) return rotated_jpg_url = save_print_snapshot( printer, last_pic_of_print(printer.current_print, 'tagged'), f'snapshots/{printer.id}/{printer.current_print.id}/{str(timezone.now().timestamp())}_rotated.jpg', rotated=True, to_long_term_storage=False) handler.send_failure_alerts(printer=printer, is_warning=is_warning, print_paused=print_paused, print_=printer.current_print, img_url=rotated_jpg_url or '')
def send_failure_alert(printer, is_warning=True, print_paused=False): LOGGER.info(f'Printer {printer.user.id} {"smells fishy" if is_warning else "is probably failing"}. Sending Alerts') if not printer.current_print: LOGGER.warn(f'Trying to alert on printer without current print. printer_id: {printer.id}') return (_, rotated_jpg_url) = save_print_snapshot(printer.current_print, last_pic_of_print(printer.current_print, 'tagged'), unrotated_jpg_path=None, rotated_jpg_path=f'snapshots/{printer.id}/{printer.current_print.id}/{str(timezone.now().timestamp())}_rotated.jpg') # Fixme: any exception will cause subsequent notification channel to be tried at all. # This is also why SMS is currently at the end, since it'll fail with exception when area code is not allowed. if printer.user.alert_by_email: send_failure_alert_email(printer, rotated_jpg_url, is_warning, print_paused) send_failure_alert_pushbullet(printer, rotated_jpg_url, is_warning, print_paused) send_failure_alert_telegram(printer, rotated_jpg_url, is_warning, print_paused) if printer.user.is_pro and printer.user.alert_by_sms: send_failure_alert_sms(printer, is_warning, print_paused) if printer.user.is_pro: send_failure_alert_slack(printer, rotated_jpg_url, is_warning, print_paused)
def will_record_timelapse(_print): last_pic = last_pic_of_print(_print, 'raw') if not last_pic: # This print does not have any raw pics return False # Save the unrotated snapshot so that it is still viewable even after the print is done. unrotated_jpg_url = save_print_snapshot( _print.printer, last_pic, f'snapshots/{_print.printer.id}/latest_unrotated.jpg', rotated=False, to_long_term_storage=False) cache.printer_pic_set(_print.printer.id, {'img_url': unrotated_jpg_url}, ex=IMG_URL_TTL_SECONDS) min_timelapse_secs = _print.printer.min_timelapse_secs_on_cancel if _print.is_canceled( ) else _print.printer.min_timelapse_secs_on_finish if min_timelapse_secs < 0 or (_print.ended_at() - _print.started_at ).total_seconds() < min_timelapse_secs: _print.delete() clean_up_print_pics(_print) return False rotated_jpg_url = save_print_snapshot( _print.printer, last_pic, f'private/{_print.id}_poster.jpg', to_container=settings.TIMELAPSE_CONTAINER, rotated=True, to_long_term_storage=True) if rotated_jpg_url: _print.poster_url = rotated_jpg_url _print.save(keep_deleted=True) return True