Section 30. The service of all laborers, workmen, mechanics, foremen and inspectors now or hereafter employed by the commonwealth or any county therein or any town which, by vote of the city council, or of the voters at a town meeting, accepts this section or has accepted section one of chapter two hundred and forty of the General Acts of nineteen hundred and sixteen, or by any contractor or sub-contractor for or upon any public works of the commonwealth or of any county therein or of any such town is hereby restricted to eight hours in any one day, to forty-eight hours in any one week, and to six days in any one week. No officers of the commonwealth, except as provided herein, or of any county or of any such town, no such contractor or sub-contractor or other person whose duty it is to employ, direct or control the service of such laborers, workmen, mechanics, foremen or inspectors shall require or permit any such laborer, workman, mechanic, foreman or inspector to work more than eight hours in any one day, or more than forty-eight hours in any one week, or more than six days in any one week, except in cases of emergency. The provisions of this section shall not prohibit the employment by the state department of highways, or by any contractor or sub-contractor for said department, of laborers, workmen, mechanics, foremen or inspectors for more than eight hours in any one day in the construction or reconstruction of highways when, in the opinion of the attorney general, public necessity so requires.