示例#1
0
    def configure(self, cfg):
        """ Configuration and initialization is delayed to allow working
            with CherryPy configuration API
        """
        self.config = cfg
        create_tables(get_db_connection(self.config))

        self.worker_set = WorkerSet(cfg)
        for w in Watch.load_all(get_db_connection(self.config)):
            self.worker_set.add(w.id)
示例#2
0
    def edit(self, **kwargs):
        connection = get_db_connection(self.config)

        try:
            watch = Watch.load(self.id, connection)
                
            if not watch:
                raise cherrypy.NotFound()

            if cherrypy.request.method == 'POST':
                valid_dict, errors = validate_twill_form(connection, kwargs, watch)
                if len(errors):
                    connection.rollback()
                else:
                    for k,v in valid_dict.iteritems():
                        setattr(watch, k, v)
                    watch.update(connection)
                    connection.commit()
                    self.worker_set.restart(self.id)
                    raise cherrypy.HTTPRedirect(cherrypy.url('/'), status=303)
            else:
                errors = []

            return self.render('edit.html', watch=watch, data=kwargs, errors=errors)
        except Exception:
            connection.rollback()
            raise
示例#3
0
 def restart(self):
     watch = Watch.load(self.id, get_db_connection(self.config))
     if not watch:
         raise cherrypy.NotFound()
     
     self.worker_set.restart(self.id)
     raise cherrypy.HTTPRedirect(cherrypy.url('/'), status=303)
示例#4
0
    def check_now(self):
        """ Force a check immediately """
        watch = Watch.load(self.id, get_db_connection(self.config))
        if not watch:
            raise cherrypy.NotFound()

        self.worker_set.check_now(self.id)
        raise cherrypy.HTTPRedirect(cherrypy.url('/'), status=303)
示例#5
0
    def status(self):
        watches = Watch.load_all(get_db_connection(self.config))

        data = {}
        for watch in watches:
            data[str(watch.id)] = watch.dict()
            data[str(watch.id)].update(self.worker_set.worker_status_dict(watch.id))

        cherrypy.response.headers['Content-Type'] = "application/json"
        return simplejson.dumps(data)
示例#6
0
    def status(self):
        watch = Watch.load(self.id, get_db_connection(self.config))
        if not watch:
            raise cherrypy.NotFound()

        data = watch.dict()
        data.update(self.worker_set.worker_status_dict(watch.id))

        cherrypy.response.headers['Content-Type'] = "application/json"
        return simplejson.dumps(data)
示例#7
0
    def main(self):
        """ Process main function """
        # to make sure we do not use inherited descriptor
        # from the parent process
        close_db_connection()
        self.connection = get_db_connection(self.config)
        self.watch = Watch.load(self.id, self.connection)


        if self.watch:
            logger.info("Starting worker for watch `%s` (id: %s)" % (self.watch.name, self.id))
            self.tick_interval = self.watch.interval
            twillmanager.async.Worker.main(self)
        else:
            logger.warn("Failed to start worker for watch (id: %s) - no such watch" % self.id)
示例#8
0
    def delete(self):
        connection = get_db_connection(self.config)

        try:
            watch = Watch.load(self.id, connection)
            if not watch:
                raise cherrypy.NotFound()

            if cherrypy.request.method == 'POST':
                watch.delete(connection)
                self.worker_set.remove(self.id)
                connection.commit()
                raise cherrypy.HTTPRedirect(cherrypy.url('/'), status=303)

            return self.render('delete.html', watch=watch)
        except Exception:
            connection.rollback()
            raise
示例#9
0
    def new(self, **kwargs):
        watch = None
        if cherrypy.request.method == 'POST':
            c = get_db_connection(self.config)
            try:
                valid_dict, errors = validate_twill_form(c, kwargs)
                if len(errors):
                    c.rollback()
                else:
                    watch = Watch(**valid_dict)
                    watch.save(c)
                    c.commit()
                    self.worker_set.add(watch.id)
            except Exception:
                c.rollback()
                raise
        else:
            errors = []

        if watch:
            raise cherrypy.HTTPRedirect(cherrypy.url('/'), status=303)
        else:
            return self.render('new.html', data=kwargs, errors=errors)
示例#10
0
 def index(self):
     watches = Watch.load_all(get_db_connection(self.config))
     return self.render('index.html', watches=watches, worker_set=self.worker_set)