def __on_message__()

in lab/03-Package-Deploy/iot-jobs/app/ota.py [0:0]


    def __on_message__(self, client, userdata, message):
        logging.debug("New message. Topic: %s; Message: %s;" % (message.topic, message.payload))
        
        if message.topic.endswith('notify'):
            self.model_update_check()

        elif message.topic.endswith('accepted'):
            resp = json.loads(message.payload)            
            logging.debug(resp)
            if resp.get('queuedJobs') is not None: # request to list jobs
                # get the description of each queued job
                for j in resp['queuedJobs']:
                    ## get the job description
                    self.publish('$aws/things/%s/jobs/%s/get' % ( self.device_name, j['jobId'] ) )
                    break
            elif resp.get('inProgressJobs') is not None: # request to list jobs
                # get the description of each queued job
                for j in resp['inProgressJobs']:
                    ## get the job description
                    self.publish('$aws/things/%s/jobs/%s/get' % ( self.device_name, j['jobId'] ) )
                    break
            elif resp.get('execution') is not None: # request to get job description            
                # check if this is a job description message
                job_meta = resp.get('execution')
            
                # we have the job metadata, let's process it
                self.__update_job_status__(job_meta['jobId'], 'IN_PROGRESS', 'Trying to get/load the model')
                self.__process_job__(job_meta['jobId'], job_meta['jobDocument'])
            else:
                logging.debug('Other message: ', resp)