def run(self, **kwargs):
        """
        Does the magic!
        """
        logger.info('UpdateLocationsIfNecessaryTask was called')

        # read last ip count
        try:
            with open(app_settings.IP_ASSEMBLER_IP_CHANGED_FILE, 'r') as f:
                content_list = f.readlines()
                if len(content_list) == 0:
                    ip_count_old = -1
                else:
                    ip_count_old = int(content_list[0])
        except IOError:
            ip_count_old = -1

        logger.info('read IP count of %(count)d' % {'count': ip_count_old})

        # if IPs have significantly changed, update the locations
        ip_count_now = IP.objects.count()
        if ip_count_now == -1 or ip_count_now > ip_count_old + app_settings.IP_ASSEMBLER_IP_CHANGED_THRESHOLD:
            logger.info('Checking IP counts, last: %(ip_count_old)d - now: %(ip_count_now)d' % {
                'ip_count_old': ip_count_old,
                'ip_count_now': ip_count_now
            })

            # call the updater task
            UpdateHtaccessLocationsTask().delay()

            # write the new count to the file
            try:
                open(app_settings.IP_ASSEMBLER_IP_CHANGED_FILE, 'w').close()
                with open(app_settings.IP_ASSEMBLER_IP_CHANGED_FILE, 'w') as f:
                    f.write(str(ip_count_now))
            except IOError:
                logger.exception('unable to write to file %(file_path)s' % {'file_path': app_settings.IP_ASSEMBLER_IP_CHANGED_FILE})
        else:
            logger.info('nothing to do here')
Does the magic!