<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def app_update_state(app_id,state):
 """ update app state """

    try:
        create_at = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        conn = get_conn()
        c = conn.cursor()
        c.execute("UPDATE app SET state='{0}',change_at='{1}' WHERE id='{2}'".format(state, create_at, app_id))
        conn.commit()
        conn.close()
        print 'UPDATE app %s state to %s succeed!' % (app_id,state)
    except Exception, e:
        raise RuntimeError( 'update app %s state to %s failed! %s' % (app_id,state,e) )