def METHOD_NAME(zone, api, state):
    """
    :param zone:
    :param api:
    :param state:
    :return:
    """
    if not isinstance(api, pdnsapi.api.PDNSApi):
        raise Exception('api must be a PDNSApi instance, not a {}'.format(type(api)))
    if not isinstance(state, DomainState):
        raise Exception('state must be a DomainState instance, not a {}'.format(type(state)))
    if state.current_roll.complete:
        state.set_last_roll_date(state.current_roll.keytype, state.current_roll.step_datetimes[-1])
        state.current_roll = KeyRoll()
    api.set_zone_metadata(zone, PDNSKEYROLLER_STATE_metadata_kind, str(state))