A former middle school lunch lady accused of repeatedly molesting a 15-year-old boy pleaded guilty to four counts of rape of a child as jury selection was getting underway for her trial.

Janelle Foley, 38, was immediately sentenced yesterday by Norfolk Superior Court Judge Thomas A. Connors to 2 A to 4 A years in prison on the first count, to be followed by five years’ probation for the remaining three counts, Norfolk District Attorney Michael W. Morrissey said.

“We felt a state prison sentence was appropriate in this case,” 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.”

Foley had been out on GPS and $5,000 bail since her indictment in 2014, which alleged she sexually abused the teen during holiday parties at his family’s home.

The teen was not a student at the middle school where Foley worked, Morrissey said.

Foley requested a stay of sentence through February school vacation, which Connors denied. She was taken to Framingham to begin serving her sentence, Morrissey said.

Once released and on probation, Foley, a mother, will be monitored by GPS, must register as a sex offender and will be forbidden to have unsupervised contact with children under age 18, except for her own children.