DEDHAM – A former Weymouth school cafeteria worker has pleaded guilty to raping a 15-year-old boy during two separate holiday parties at his home.

Janelle Foley, 38, of Weymouth, pleaded guilty Wednesday morning to four counts of rape and abuse of a child, according to a spokesman for the Norfolk County District Attorney’s Office. Norfolk Superior Court Judge Thomas Connors sentenced Foley to two-and-a-half to four-and-half years in state prison.

Foley, a mother of four, was indicted by a Norfolk County grand jury in 2014. She had previously pleaded not guilty to the charges and had been free on $5,000 bail while awaiting trial.

The plea change came as the court was preparing to select a jury to hear the case.

“We felt a state prison sentence was appropriate in this case,” Norfolk District Attorney Michael W. Morrissey said after the plea. “We were ready to go to trial. I am relieved for the victim in this case that the convictions were secured without needing to testify at trial.”

Connors denied Foley’s request that she remain free for two weeks before beginning her sentence and she was taken into custody following Wednesday’s hearing.

Once she’s released from prison she will have to serve five years probation. During that time she will have to wear a GPS monitoring bracelet, register as a sex offender and abstain from drugs and alcohol. She’s also barred from having unsupervised contact with children except her own and from working or volunteering with children and she must receive mental health counseling.

Prosecutors said Foley sexually assaulted the boy, who was 15 at the time, during Thanksgiving and New Year’s parties in the boy’s family home.

Because the alleged victim is a minor, court officials impounded records in the case, shielding the records from public view.

At the time of her arrest, Foley had been working for a little over two years as a cafeteria worker at the Chapman Middle School in Weymouth. The victim was not a student at the school at the time of the rape.

Foley was placed on unpaid administrative leave from her job after her arrest and she is no longer a school employee, Superintendent Kenneth Salim said. Citing confidentiality rules Salim declined to say whether Foley was fired or left on her own, or when her employment ended.

During a 2014 court hearing, Foley’s former defense attorney said she is a lifelong Weymouth resident with no criminal record who suffers from depression and “substance issues.”

She was arrested at her home about a week after the New Year’s party.

Christian Schiavone may be reached at cschiavone@ledger.com or follow on Twitter @CSchiavo_Ledger.