Whenever a peremptory mandamus is directed to a public officer, body or board, commanding the performance of any public duty specially enjoined by law, if it appears to the court that such officer or any member of such body or board, without just excuse, refuses or neglects to perform the duty so enjoined, the court may impose a fine not exceeding two hundred and fifty dollars [($250)] upon every such officer or member of such body or board; such fine, when collected, shall be paid into the state treasury, and the payment of such fine is a bar to an action for any penalty incurred by such officer or member of such body or board, by reason of his refusal or neglect to perform the duty so enjoined.