I had the same issue and a mechanic asked me to diagnose it with a number of steps like re-feeling the gas so that he can ensure there is proper pressure and then he will move to electronic parts before moving to the compressor.
However, since It was intermittent and there was cooling also, I decided to give it a try and directly check the relay, pull it off, check for any carbon deposit and you can replace it momentarily to verify if relay has a problem. And, yes, that was it.
I cleaned my AC relay (you can identify with the car manual) and it’s okay now.
Mostly, these components are pretty reliable if dont kept out of use for prlonged time. So, keep it working frequently to avoid any leak.
Hope this will help.