<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def set_mode(self, mode):
        '''Set the global mode of the rejester system.

        This must be one of the constants :attr:`TERMINATE`,
        :attr:`RUN`, or :attr:`IDLE`.  :attr:`TERMINATE` instructs any
        running workers to do an orderly shutdown, completing current
        jobs then exiting.  :attr:`IDLE` instructs workers to stay
        running but not start new jobs.  :attr:`RUN` tells workers to
        do actual work.

        :param str mode: new rejester mode
        :raise rejester.exceptions.ProgrammerError: on invalid `mode`

        '''
        if mode not in [self.TERMINATE, self.RUN, self.IDLE]:
            raise ProgrammerError('mode=%r is not recognized' % mode)
        with self.registry.lock(identifier=self.worker_id) as session:
            session.set('modes', 'mode', mode)
        logger.info('set mode to %s', mode)