In the case of a specific story, you have to ask what makes sense.
In terms of the mandatory 24-hour waiting period between long rests...players can always wander off and go burn the rest of the day foraging, chatting, and otherwise being idle. If they elect to take a long-rest part way through a 'dungeon crawl' make sure you consider exactly what that means for them.
For the number of encounters they can handle in a day, per the DMG, it recommends:
most adventuring parties can handle about six to eight medium or hard encounters in a day. If the adventure had more easy encounters, the adventurers can get through more. If it has more deadly encounters, they can handle fewer. (DMG84)
Remember that this is a guideline. And guidelines tend to be broken on occasion.
So, for the specific case of a published adventure, here are some considerations:
1: Look at the encounters, compare them to the XP Thresholds for encounter difficulty in the DMG. If the single dungeon (in this case, the hatchery) contains a few Easy encounters, then the party can handle it in one day, no problem.
2: Consider what makes sense. The party is raiding a hatchery that is heavily guarded. If they roll through, clear half the hatchery, then pitch a tent in a random back room...they are going to either get ambushed, or the hatchery may be evacuated while they are sitting there wasting the day. Or, at the very least, the hatchery will be on high alert and ready for them when they elect to continue...meaning ambushes, traps, fortifications, etc.
So, here are some possibilities.
First, the module may be intentionally straining your players. This happens sometimes. Forcing players to push through when they are short on resources can sometimes lead to some very creative solutions. Alternately, your players might just be burning through resources faster than they should....you really shouldn't be wasting spell slots when a pair of kobolds attacks you. If your players find themselves running short on resources, but still running into encounters, they are likely to become more conservative with their power.
Second, if necessary, allow your players to waste the rest of the day so they can take a long rest. But...consider the ramifications of them doing so. At the very least, they will put the place they are attacking on high-alert. Surprising enemies will become impossible, and I would expect the enemies to dig in and fortify their positions. They might set up ambushes ahead of the players. Or, they might decide that this location is a lost cause, and sneak out. Whatever the case may be, make sure your players know that taking a nap in the middle of an assault is probably not the best plan ever.
So, to give the general gist of it...
Yes, players can always choose to waste the rest of the day so that they can take a long rest. But you have to consider how the NPCs will respond to having a full day to discover what has been happening in their lair.
Resources are regained at the end of a long rest.
The barbarian's rage class feature states:
you must finish a long rest before you can rage again.
Spellcaster's spell slot section states:
You regain all expended spell slots when you finish a long rest.
For hit points and hit die:
At the end of a long rest, a character regains all lost hit points. The character also regains spent Hit Dice...
So it doesn't matter what is spent during the rest as long as the PCs get to finish that rest. This also means that any resources spent before the rest started remain spent during the rest and ensuing combat, until the long rest is completed.
It's also worth noting that it's not intended for the PCs to be able to gain the benefits of a short rest during a long rest, as per this unofficial guidance by rules designer Jeremy Crawford on Twitter:
Q: can a PC benefit from short rests during a long rest? A PC (fighter) is abusing second wind to save hit dies.
A: The intent is that you can't take a short rest and a long rest at the same time.
Obviously a DM can rule whichever way they want but the designers didn't intend for a long rest to include a short rest.
Best Answer
The DMG discusses random encounters, pp. 85-87.
One application of the guidelines presented there might be:
Every hour the players are resting in a dangerous area, roll a D20. On an 18 or higher, a random encounters occurs.
If there is a random encounter, roll a D6:
You can of course pre-determine specific monsters or groups of monsters appropriate to the environment and your party's level ahead of time.
This system means that during an eight hour rest, there's a ~72% chance the party will have at least one random encounter.
Also remember that characters who haven't completed a long rest get no benefit from the rest, so during such a random encounter, the characters will be as depleted as they were when they began the rest. And, of course, once the players complete a long rest, they must wait 16 hours before they can start another 8-hour long rest period that they would benefit from.