code: def refresh_if_needed(self):
          
          if self.state in (self.PENDING, self.STARTED):
              try:
                  response, = self._fetch_result()['tasks']
              except (KeyError, ValueError):
                  raise Exception(
                      "Unable to find results for task."
                  )
  
              if 'error' in response:
                  self.state == self.FAILURE
                  raise ServerError(response['error'])
  
              if 'state' in response:
                  self.state = response['state']
                  self.result = response['result']
docs: Refresh the status of the task from server if required.