Section 31. The service of all laborers, workmen and mechanics now or hereafter employed by any town which has accepted section twenty of chapter one hundred and six of the Revised Laws, or section forty-two of chapter five hundred and fourteen of the acts of nineteen hundred and nine, or said section forty-two, as affected by chapter four hundred and ninety-four of the acts of nineteen hundred and eleven, and which has not 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 any such town, is hereby restricted to eight hours in any one day. No officer 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 or mechanics shall require or permit any such laborer, workman or mechanic to work more than eight hours in any one day, except in cases of extraordinary emergency. But any such town may accept the preceding section and shall thereupon become subject thereto.