The pendulum keeps swinging back and forth for Zack Wheeler. A few good starts, a few bad ones. A good month, a bad month.

The enigmatic right-hander is as easy to predict as the weather. Fortunately for the Mets, he’s hit an upswing at the perfect time, as they battle to remain in the wild-card race.

Wheeler allowed one earned run in his third straight start Tuesday, helping the Mets beat the Diamondbacks for the second straight night, 3-2 at Citi Field, and move to three games behind the Cubs for the second wild card.

“He was outstanding, in control of the game getting ahead. That’s a very good lineup. They got some really good hitters in there,” manager Mickey Callaway said. “He pitched like he should — like he’s capable of.”

Wheeler was shaky early on, allowing a first-inning run. But that was all the damage that would be done. The Diamondbacks did put at least one runner on base in five of the next six innings. But Wheeler held them to 1-for-4 with runners in scoring position.

“When you give up a run in the first like that, [you think] that’s all they’re going to get,” Wheeler said after allowing seven hits, walking two and striking out seven for his 10th win of the season in lowering his ERA to 4.21. “You have that mindset, try to put up zeroes. I was able to do that.”

It’s been a roller-coaster ride of a season for Wheeler, who reached 700 strikeouts for his career in the victory. After the Mets surprisingly held onto the free agent-to-be at the trade deadline, he twirled 15 consecutive shutout innings. He followed that up with three poor outings, allowing 13 earned runs over 16 innings. But now he’s headed back in the opposite direction, giving up three earned runs over 18 innings.

Purchase event tickets to The Amazin’ 1969 New York Mets: A World Championship for the Ages presented by The Paley Center for Media and New York Post. Enter promo code: NYPOST to unlock tickets only available for Post readers.