def status(self): """ Human-readable output of request status. """ if self.screenshot_id is not None: return _("uploaded") if self.locked and self.locked < lock_timeout(): return _("failed") if self.redirected: return _("loading") if self.locked: return _("starting") return ''
def status(self): """ Human-readable output of request status. """ if self.screenshot_id is not None: return _("uploaded") if self.locked and self.locked < lock_timeout(): return _("failed") if self.redirected: return _("loading") if self.locked: return _("starting") return ''
def status(http_request, request_group_id): """ List the status of all screenshot requests in a group. Arguments ~~~~~~~~~ * id int (request group id from requests.submit) Return value ~~~~~~~~~~~~ * status list (request status for each requested browser) The list will contain a dictionary for each browser, with the following entries: * browser string (browser name) * status string (pending / starting / loading / uploaded / failed) * seconds int (estimated or actual time between request and upload) * hashkey string (after the screenshot is uploaded) You can use the hashkey to generate the resulting PNG file URL, for example if the hashkey is beef1234: * http://api.browsershots.org/png/original/be/beef1234.png * http://api.browsershots.org/png/512/be/beef1234.png * http://api.browsershots.org/png/160/be/beef1234.png The /be/ part is the first two characters of the hashkey. Normally, the hashkey consists of 32 random lowercase hex characters. """ try: request_group = RequestGroup.objects.get(id=request_group_id) except RequestGroup.DoesNotExist: raise Fault(404, "Request group not found.") results = [] matching_browsers = request_group.matching_browsers() requests = request_group.request_set.all() preload_foreign_keys(requests, browser_group=True, platform=True) this_lock_timeout = lock_timeout() for request in requests: platform_name = request.platform.name.lower() browser_name = request.browser_group.name.lower() major = str(request.major) minor = str(request.minor) name = '_'.join((platform_name, browser_name, major, minor)) name = name.replace(' ', '-') hashkey = '' if request.screenshot_id is not None: status = 'uploaded' seconds = (request.screenshot.uploaded - request_group.submitted).seconds hashkey = request.screenshot.hashkey elif request.locked and request.locked < this_lock_timeout: status = 'failed' seconds = 0 elif request.redirected: status = 'loading' seconds = (request.redirected - request_group.submitted).seconds + 45 elif request.locked: status = 'starting' seconds = (request.locked - request_group.submitted).seconds + 60 else: status = 'pending' seconds = request.queue_estimate(matching_browsers) or 0 results.append({ 'browser': name, 'status': status, 'seconds': seconds, 'hashkey': hashkey, }) return results
def status(http_request, request_group_id): """ List the status of all screenshot requests in a group. Arguments ~~~~~~~~~ * id int (request group id from requests.submit) Return value ~~~~~~~~~~~~ * status list (request status for each requested browser) The list will contain a dictionary for each browser, with the following entries: * browser string (browser name) * status string (pending / starting / loading / uploaded / failed) * seconds int (estimated or actual time between request and upload) * hashkey string (after the screenshot is uploaded) You can use the hashkey to generate the resulting PNG file URL, for example if the hashkey is beef1234: * http://api.browsershots.org/png/original/be/beef1234.png * http://api.browsershots.org/png/512/be/beef1234.png * http://api.browsershots.org/png/160/be/beef1234.png The /be/ part is the first two characters of the hashkey. Normally, the hashkey consists of 32 random lowercase hex characters. """ try: request_group = RequestGroup.objects.get(id=request_group_id) except RequestGroup.DoesNotExist: raise Fault(404, "Request group not found.") results = [] matching_browsers = request_group.matching_browsers() requests = request_group.request_set.all() preload_foreign_keys(requests, browser_group=True, platform=True) this_lock_timeout = lock_timeout() for request in requests: platform_name = request.platform.name.lower() browser_name = request.browser_group.name.lower() major = str(request.major) minor = str(request.minor) name = '_'.join((platform_name, browser_name, major, minor)) name = name.replace(' ', '-') hashkey = '' if request.screenshot_id is not None: status = 'uploaded' seconds = (request.screenshot.uploaded - request_group.submitted).seconds hashkey = request.screenshot.hashkey elif request.locked and request.locked < this_lock_timeout: status = 'failed' seconds = 0 elif request.redirected: status = 'loading' seconds = (request.redirected - request_group.submitted).seconds + 45 elif request.locked: status = 'starting' seconds = (request.locked - request_group.submitted).seconds + 60 else: status = 'pending' seconds = request.queue_estimate(matching_browsers) or 0 results.append({'browser': name, 'status': status, 'seconds': seconds, 'hashkey': hashkey, }) return results