All perfect praise be to Allah the Lord of the Worlds. May His peace and blessings be upon our Prophet Mohammad and upon all his family and companions.
Turning towards the direction of the Qibla (Direction of prayer) is among the conditions for the validity of prayer. The evidence on this is that Allah the Almighty says {What means}: "We see the turning of thy face (for guidance to the heavens: now Shall We turn thee to a Qibla that shall please thee. Turn then Thy face in the direction of the sacred Mosque: Wherever ye are, turn your faces in that direction." {Al-Baqarah, 144}. Another evidence is that the Prophet (PBUH) prayed facing the Kabah after he had prayed towards Baitul-Maqdis for sixteen months.
However, jurists have disagreed about facing the direction of the Qibla or the Kabah itself. For more details, kindly check {Nehayat Al-Mattlab, Vol.2:103} by Al-Jowaini.
Deviating greatly to either the left or the right of the Kabah itself renders one`s prayer invalid; however, deviating slightly makes the praying person within the direction of the Kabah and renders their prayer valid. Al-Rafe`I, a Shafi`ie jurist, said: " Deviation is of two types: First, The praying person isn`t facing the Qibla because he is abundantly deviated from it. Second, the praying person is slightly deviated from the Qibla, but is still in its direction." {Fateh Al-Aziz, Vol.3:244}.
Consequently, the rig worker must turn towards the Qibla when making Takbiratul Ihram and perform all pillars of prayer: Qiyam (Standing position), Ruku` (Belt-low bowing) and Sujud (Prostration). When the rig turns away from the direction of the Qibla, the worker must immediately go back to the direction of the Qibla and his prayer is considered valid, even if this kept happening during the prayer. However, if he didn`t turn his chest towards the Qibla, then his prayer is considered invalid.
It was stated in the Shafie book {Moghni al-Mohtaj, Vol.1:335}: "It isn`t permissible for the one offering an obligatory prayer while on a ship to leave Qiyam except for an excuse, such as sea sickness. However, if the wind changed the direction of the ship, then he must turn his chest towards the direction of the Qibla and resume his prayer; otherwise, his prayer is considered invalid.
However, if it was impossible for the worker to keep his chest towards the direction of the Qibla due to the continuous rotation of the rig, then he may pray as he is out of respect for the time of the prayer. Nonetheless, he must re-perform the prayer when the rig stops moving or when he comes to land. And Allah the Almighty knows best.