Beispiel #1
0
    def processMessages(self, topic, payload):
        self.logger.debug(
            "MQTT message received for topic '%s' payload '%s'." %
            (topic, payload))
        try:
            topicParts = topic.split("/")
            valveName = topicParts[2]

            valves = self.valves

            if topicParts[1] == "open":
                self.irrigate.queueJob(
                    model.Job(valve=valves[valveName],
                              sched=None,
                              duration=float(payload)))
                return

            if topicParts[1] == "suspend":
                if int(payload) == 0:
                    valves[valveName].suspended = False
                    self.logger.info(
                        "Un-suspended valve '%s' via MQTT command" % valveName)
                    return
                elif int(payload) == 1:
                    valves[valveName].suspended = True
                    self.logger.info("Suspended valve '%s' via MQTT command" %
                                     valveName)
                    return

            if topicParts[1] == "enabled":
                if int(payload) == 0:
                    valves[valveName].enabled = False
                    self.logger.info("Disabled valve '%s' via MQTT command" %
                                     valveName)
                    return
                elif int(payload) == 1:
                    valves[valveName].enabled = True
                    self.logger.info("Enabled valve '%s' via MQTT command" %
                                     valveName)
                    return

            self.logger.warning(
                "Invalid payload received for topic %s = '%s'" %
                (topic, payload))
        except Exception as ex:
            self.logger.error(
                "Error parsing payload received for topic %s = '%s'" %
                (topic, payload))
Beispiel #2
0
 def addJob(self, name, type, status):
     newJob = model.Job(Name=jobName, Type=jobType, Status=101)
     model.saveData()
Beispiel #3
0
    def addRender(self, project, shot, first, last, ver, path, RenderScenefile,
                  type, w, h, renderOutput, renderName, jobName, jobType,
                  format, curUserName, Schunk, cmd):
        print "go2"
        #jobName = "job_" + renderName + time.strftime('_%d%m%y_%H%M%S')
        chunk = int(Schunk)
        curShot = model.Shot.get_by(Name=unicode(shot))
        curProj = model.Project.get_by(Name=unicode(project))
        now = datetime.datetime.now()
        newRender = model.Render(Name=renderName,
                                 In=int(first),
                                 Out=int(last),
                                 Path=path,
                                 Date=now,
                                 version=int(ver),
                                 ScenePath=RenderScenefile,
                                 Type=type,
                                 Width=int(w),
                                 Height=int(h),
                                 Format=format,
                                 Job=jobName,
                                 User=curUserName)
        model.saveData()
        curShot.Renders.append(newRender)
        curShot.Seq.Renders.append(newRender)
        curProj.Renders.append(newRender)
        model.saveData()
        newJob = model.Job(Name=jobName, Type=jobType, Status=101)
        model.saveData()

        startFrame = int(first)
        curChunk = 0
        taskDir = renderOutput + "/tasks"

        for i in range(int(first), int(last), chunk):
            if curChunk == (int(last) - int(first)) / chunk - 1:
                shortName = "task" + "_" + "%04d" % i
                taskName = jobName + "_" + "%04d" % i
                taskFile = taskDir + "/" + taskName + ".txt"
                newTask = model.Task(Name=taskName,
                                     In=startFrame,
                                     Out=last,
                                     Type=jobType,
                                     ShortName=shortName,
                                     Status=101,
                                     Command=unicode(RenderScenefile +
                                                     " -taskFile " + taskFile))
                newJob.Tasks.append(newTask)
            else:
                shortName = "task" + "_" + "%04d" % i
                taskName = jobName + "_" + "%04d" % i
                taskFile = taskDir + "/" + taskName + ".txt"
                newTask = model.Task(Name=taskName,
                                     In=startFrame,
                                     Out=startFrame + chunk - 1,
                                     Type=jobType,
                                     ShortName=shortName,
                                     Status=101,
                                     Command=unicode(RenderScenefile +
                                                     " -taskFile " + taskFile))
                newJob.Tasks.append(newTask)
            startFrame += chunk
            curChunk += 1
            model.saveData()
Beispiel #4
0
    def timerThread(self):
        try:
            while True:
                now = datetime.now().replace(tzinfo=pytz.timezone(
                    self.cfg.timezone),
                                             second=0,
                                             microsecond=0)

                if now.hour == 0 and now.minute == 0:
                    for aValve in self.valves.values():
                        aValve.secondsDaily = 0

                if self.everyXMinutes("idleInterval",
                                      self.cfg.telemIdleInterval,
                                      False) and self.cfg.telemetry:
                    delta = (datetime.now() - self.startTime)
                    uptime = ((delta.days * 86400) + delta.seconds) // 60
                    self.mqtt.publish("/svc/uptime", uptime)
                    for valve in self.valves.values():
                        self.telemetryValve(valve)

                    for sensor in self.sensors.keys():
                        self.telemetrySensor(sensor, self.sensors[sensor])

                if self.everyXMinutes("activeinterval",
                                      self.cfg.telemActiveInterval,
                                      False) and self.cfg.telemetry:
                    for valve in self.valves.values():
                        if valve.handled:
                            self.telemetryValve(valve)

                if self.everyXMinutes("scheduler", 1, True):
                    # Must not evaluate more or less than once every minute otherwise running jobs will get queued again
                    for aValve in self.valves.values():
                        if aValve.enabled:
                            if aValve.schedules != None:
                                for valveSched in aValve.schedules.values():
                                    if self.evalSched(valveSched,
                                                      self.cfg.timezone, now):
                                        jobDuration = valveSched.duration
                                        if valveSched.sensor != None and valveSched.sensor.handler != None and valveSched.sensor.handler.started:
                                            try:
                                                factor = valveSched.sensor.handler.getFactor(
                                                )
                                                if factor != 1:
                                                    jobDuration = jobDuration * factor
                                                    self.logger.info(
                                                        "Job duration changed from '%s' to '%s' based on input from sensor."
                                                        % (valveSched.duration,
                                                           jobDuration))
                                            except Exception as ex:
                                                self.logger.error(
                                                    "Error probing sensor (getFactor) '%s': %s."
                                                    % (valveSched.sensor.type,
                                                       format(ex)))
                                        job = model.Job(
                                            valve=aValve,
                                            duration=jobDuration,
                                            sched=valveSched,
                                            sensor=valveSched.sensor)
                                        self.queueJob(job)

                time.sleep(1)
        except Exception as ex:
            self.logger.error(
                "Timer thread exited with error '%s'. Terminating Irrigate!" %
                format(ex))
            self.terminated = True