The entire setup is wrong, as in, it just doesn't work. It is good enough for a Hollywood movie or for a fantasy adventure novel, but it makes no sense in a serious setting.
The problem is the attacking army.
Medieval armies were slow. Glacially slow. The city would learn that an army was headed towards it at least weeks if not months in advance. And an army cannot be hidden: it is big ugly thing moving slowly through the country, devastating everything in its path. Once the city learned that an army is coming, it would naturally adopt a defensive stance; hence our modern "state of siege".
So in practice, the city would already be prepared for defense; there would be no need to raise the alarm. The gate would be closed, towers and ramparts would be manned, regular patrols would sweep the approaches. Most likely, the city would also be in diplomatic communication with the attackers!
For example, in 1682 (yes, Early Modern, but still a great example) the Ottoman Empire decided to take Vienna. War was declared in August 1682. They managed to assemble a great army at Adrianople by March 1683. They arrived in Belgrade in May. The 200,000-strong army arrived at Vienna in July. During this time, the Austrians evacuated the city, leaving only a force of 15000 volunteers commanded by Ernst-Rüdiger von Starhemberg, emperor Leopold established a set of alliances and coordinated strategy with king Jan Sobieski of Poland. (Spoiler: the Ottomans failed to take Vienna.)
So in the normal course of things a medieval or early modern army cannot take a city by surprise. To take a city by surprise, some other factor must be in play; for example, it helps if the army is already in the city as supposed allies, or if the people of the city riot, or if the rulers flee and leave the defending forces without commanders. Or maybe decades of neglect have left the walls of the city unmaintained and indefensible. Or maybe the garrison consists of badly paid and untrained mercenaries who couldn't care less whether the city is taken or not.
Now, this doesn't mean that taking a city by surprise is not a worthy plot point. That such a feat is not actually reasonable in actual warfare is immaterial: we read adventure novels to be entertained. So make the timing suitable for your purpose; explain away the incompetence or treason of the defending military commanders; and so on. Basically, make something up, and just take care to avoid glaring impossibilities.