In this paper, we study AC microgrid dynamics under a completely decentralized primary control, and a secondary frequency control the implementation of which is distributed over a communication network with communication links that are time-varying and can be (i) bidirectional, or (ii) unidirectional. For a certain class of controllers, the closed-loop system dynamics solve a certain multi-agent optimization problem by performing two steps: (i) gradient-descent, and (ii) distributed averaging. The proposed framework allows to explore many of the existing distributed algorithms developed for solving general multi-agent optimization problems over time-varying communication networks. In particular, we use the subgradient-push algorithm to design a distributed frequency controller, and we present the convergence analysis for the closed-loop system. We also dwell on this framework and propose a distributed frequency controller that does not require agents (power generators) to know their out-degree, which is a necessary assumption for the convergence of the subgradient-push algorithm.