# Buggy code
def render_task_status(tasklist):
    renderedtasklist = list()
    for task in tasklist:
        if task["user"] == current_user.nickname or current_user.role_admin():
            if task["formStarttime"]:
                task["starttime"] = format_datetime(
                    task["formStarttime"], format="short", locale=web.get_locale()
                )
            else:
                if "starttime" not in task:
                    task["starttime"] = ""

            # localize the task status
            if isinstance(task["stat"], int):
                if task["stat"] == worker.STAT_WAITING:
                    task["status"] = _("Waiting")
                elif task["stat"] == worker.STAT_FAIL:
                    task["status"] = _("Failed")
                elif task["stat"] == worker.STAT_STARTED:
                    task["status"] = _("Started")
                elif task["stat"] == worker.STAT_FINISH_SUCCESS:
                    task["status"] = _("Finished")
                else:
                    task["status"] = _("Unknown Status")

            # localize the task type
            if isinstance(task["taskType"], int):
                if task["taskType"] == worker.TASK_EMAIL:
                    task["taskMessage"] = _("E-mail: ") + task["taskMess"]
                elif task["taskType"] == worker.TASK_CONVERT:
                    task["taskMessage"] = _("Convert: ") + task["taskMess"]
                elif task["taskType"] == worker.TASK_UPLOAD:
                    task["taskMessage"] = _("Upload: ") + task["taskMess"]
                elif task["taskType"] == worker.TASK_CONVERT_ANY:
                    task["taskMessage"] = _("Convert: ") + task["taskMess"]
                else:
                    task["taskMessage"] = _("Unknown Task: ") + task["taskMess"]

            renderedtasklist.append(task)

    return renderedtasklist


# Traceback (ValueError)
[2019-06-28 22:37:50,052] ERROR in app: Exception on /tasks [GET]
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/lib/python2.7/site-packages/flask_login/utils.py", line 261, in decorated_view
return func(*args, **kwargs)
File "/calibre-web/app/cps/web.py", line 1646, in get_tasks_status
tasks=helper.global_WorkerThread.get_taskstatus()
File "/calibre-web/app/cps/worker.py", line 225, in get_taskstatus
datetime.now() - self.queue[self.current]['starttime'])
File "/calibre-web/app/cps/worker.py", line 489, in _formatRuntime
if int(v) > 0:
ValueError: invalid literal for int() with base 10: '1 day, 5'
::ffff:172.17.0.1 - - [2019-06-28 22:37:50] "GET /tasks HTTP/1.1" 500 411 0.011915

# Fixed code
def render_task_status(tasklist):
    renderedtasklist = list()
    for task in tasklist:
        if task["user"] == current_user.nickname or current_user.role_admin():
            if task["formStarttime"]:
                task["starttime"] = format_datetime(
                    task["formStarttime"], format="short", locale=web.get_locale()
                )
            else:
                if "starttime" not in task:
                    task["starttime"] = ""

            task["runtime"] = format_runtime(task["formRuntime"])

            # localize the task status
            if isinstance(task["stat"], int):
                if task["stat"] == worker.STAT_WAITING:
                    task["status"] = _("Waiting")
                elif task["stat"] == worker.STAT_FAIL:
                    task["status"] = _("Failed")
                elif task["stat"] == worker.STAT_STARTED:
                    task["status"] = _("Started")
                elif task["stat"] == worker.STAT_FINISH_SUCCESS:
                    task["status"] = _("Finished")
                else:
                    task["status"] = _("Unknown Status")

            # localize the task type
            if isinstance(task["taskType"], int):
                if task["taskType"] == worker.TASK_EMAIL:
                    task["taskMessage"] = _("E-mail: ") + task["taskMess"]
                elif task["taskType"] == worker.TASK_CONVERT:
                    task["taskMessage"] = _("Convert: ") + task["taskMess"]
                elif task["taskType"] == worker.TASK_UPLOAD:
                    task["taskMessage"] = _("Upload: ") + task["taskMess"]
                elif task["taskType"] == worker.TASK_CONVERT_ANY:
                    task["taskMessage"] = _("Convert: ") + task["taskMess"]
                else:
                    task["taskMessage"] = _("Unknown Task: ") + task["taskMess"]

            renderedtasklist.append(task)

    return renderedtasklist