Beispiel #1
0
    def seed(self):

        lock_file = helpers.get_lock_file(self)
        if lock_file:
            log.debug('generating tileset')
            try:
                pid = helpers.seed_process_spawn(self)
                lock_file.write("{}\n".format(pid))
                res = {'status': 'started'}
            except (SeedConfigurationError, ConfigurationError) as e:
                log.error(
                    'Something went wrong when generating.. removing lock file'
                )
                res = {'status': 'unable to start', 'error': e.message}
            finally:
                lock_file.flush()
                lock_file.close()
                helpers.remove_lock_file(self)
        else:
            log.debug(
                'tileset.generate, will NOT generate. already running, pid: {}'
                .format(helpers.get_pid_from_lock_file(self)))
            res = {'status': 'already started'}

        return res
    def stop(self):
        print '---- tileset.stop'
        res = {'status': 'not in progress'}
        pid_str = helpers.get_pid_from_lock_file(self.id)
        process = helpers.get_process_from_pid(pid_str)
        if process:
            print '---- tileset.stop, will stop, pid: {}'.format(pid_str)
            res = {'status': 'stopped'}
            children = process.children()
            for c in children:
                c.terminate()
            process.terminate()
        else:
            if pid_str == 'preparing_to_start':
                res = {'status': 'debug, prevent start!'}
                # TODO: prevent it from starting!
                print '--- process not running but may be started shortly'
            elif helpers.is_int_str(pid_str):
                print '---- tileset.stop, process not running but cleaned lck file'

        helpers.remove_lock_file(self.id)
        return res
    def generate(self):
        print '---- tileset.generate'
        lock_file = helpers.get_lock_file(self.id)
        if lock_file:
            print '---- tileset.generate, will generate'
            try:
                pid = helpers.seed_process_spawn(self)
                lock_file.write("{}\n".format(pid))
                res = {'status': 'started'}
            except (SeedConfigurationError, ConfigurationError) as e:
                print '--- Something went wrong when generating.. removing lock file'
                helpers.remove_lock_file(self.id)
                res = {'status': 'unable to start',
                       'error': e.message}
            finally:
                lock_file.flush()
                lock_file.close()
        else:
            print '---- tileset.generate, will NOT generate. already running, pid: {}'.format(helpers.get_pid_from_lock_file(self.id))
            res = {'status': 'already started'}

        return res
Beispiel #4
0
    def stop(self):
        print '---- tileset.stop'
        res = {'status': 'not in progress'}
        pid_str = helpers.get_pid_from_lock_file(self.id)
        process = helpers.get_process_from_pid(pid_str)
        if process:
            print '---- tileset.stop, will stop, pid: {}'.format(pid_str)
            res = {'status': 'stopped'}
            children = process.children()
            for c in children:
                c.terminate()
            process.terminate()
        else:
            if pid_str == 'preparing_to_start':
                res = {'status': 'debug, prevent start!'}
                # TODO: prevent it from starting!
                print '--- process not running but may be started shortly'
            elif helpers.is_int_str(pid_str):
                print '---- tileset.stop, process not running but cleaned lck file'

        helpers.remove_lock_file(self.id)
        return res