Asymptotic optimality of a class of controlled non-Markov processes