def run_job(self, job_id): with engine.begin() as conn: enabled = (conn.execute( select([hydroponic_zones.c.enabled]).where( hydroponic_zones.c.zone_name == self.zone_name))).scalar() if enabled: with engine.begin() as conn: running = (conn.execute( select([ hydroponic_zones.c.running ]).where(hydroponic_zones.c.zone_name == self.zone_name)) ).scalar() if running: log.debug( f'Zone {self.zone_number} ({self.zone_name}) is already running.' ) else: self.running = True with engine.begin() as conn: # With this db update we are updating the individual zone db record for the zone that is running. conn.execute(hydroponic_zones.update().where( hydroponic_zones.c.zone_name == self.zone_name).values( {hydroponic_zones.c.running: True})) conn.execute(hydroponic_zones.update().where( hydroponic_zones.c.zone_name == self.zone_name).values( {hydroponic_zones.c.running_manually: False})) conn.execute(scheduled_jobs.update().where( scheduled_jobs.c.job_id == job_id).values( {scheduled_jobs.c.job_running: True})) # With this db update we are updating the system_wide indication that "a" or "any" zone is running. # To access this, call use_database.zones_running_now() and it will return True or False on a systemwide # basis. conn.execute(zones_currently_running.update().values( {zones_currently_running.c.currently_running: True})) conn.execute(zones_currently_running.update().values( {zones_currently_running.c.run_manually: False})) conn.execute(zones_currently_running.update().values( {zones_currently_running.c.run_by_job: True})) conn.execute(zones_currently_running.update().values( {zones_currently_running.c.job_id: job_id})) mcp.pinMode(self.gpio, 1) mcp.digitalWrite(self.gpio, 1) log.debug( f'Zone {self.zone_number} ({self.zone_name}) is now RUNNING.' ) else: log.debug( f'ERROR: Zone {self.zone_number} ({self.zone_name}) is DISABLED. Please enable it first.' )
def stop(self): with engine.begin() as conn: enabled = (conn.execute( select([ zones.c.enabled ]).where(zones.c.zone_name == self.zone_name))).scalar() if enabled: with engine.begin() as conn: running = (conn.execute( select([ zones.c.running ]).where(zones.c.zone_name == self.zone_name))).scalar() if running: self.running = False with engine.begin() as conn: # With this db update we are updating the individual zone db record for the zone that is running. conn.execute(zones.update().where( zones.c.zone_name == self.zone_name).values( {zones.c.running: False})) conn.execute(zones.update().where( zones.c.zone_name == self.zone_name).values( {zones.c.running_manually: False})) # With this db update we are updating the system_wide indication that "a" or "any" zone is running. # To access this, call use_database.zones_running_now() and it will return True or False on a systemwide # basis. conn.execute(zones_currently_running.update().values( {zones_currently_running.c.currently_running: False})) conn.execute(zones_currently_running.update().values( {zones_currently_running.c.run_manually: False})) conn.execute(zones_currently_running.update().values( {zones_currently_running.c.run_by_job: False})) conn.execute(zones_currently_running.update().values( {zones_currently_running.c.job_id: 0})) mcp.digitalWrite(self.gpio, 0) log.debug( f'Zone {self.zone_number} ({self.zone_name}) is now STOPPED.' ) else: log.debug( f'Zone {self.zone_number} ({self.zone_name}) is not currently running.' ) else: log.debug( f'ERROR: Zone {self.zone_number} ({self.zone_name}) is DISABLED. Please enable it first.' )
def forced_stopped_jobs(action, job_id): with engine.begin() as conn: if action == 'readall': return (conn.execute(select([scheduled_jobs]).where(scheduled_jobs.c.forced_stop_manually == True))).fetchall() elif action == 'check': return (conn.execute(select([zones_currently_running.c.force_stopped]))).scalar() elif action == 'update': conn.execute(scheduled_jobs.update().where(scheduled_jobs.c.job_id == job_id).values({scheduled_jobs.c.forced_stop_manually: False})) elif action == 'reset': conn.execute(zones_currently_running.update().values({zones_currently_running.c.force_stopped: False}))
def stop_job(self, job_id, forced): with engine.begin() as conn: running = (conn.execute( select([ zones.c.running ]).where(zones.c.zone_name == self.zone_name))).scalar() if running: self.running = False with engine.begin() as conn: # With this db update we are updating the individual zone db record for the zone that is running. conn.execute(zones.update().where( zones.c.zone_name == self.zone_name).values( {zones.c.running: False})) conn.execute(zones.update().where( zones.c.zone_name == self.zone_name).values( {zones.c.running_manually: False})) conn.execute(scheduled_jobs.update().where( scheduled_jobs.c.job_id == job_id).values( {scheduled_jobs.c.job_running: False})) if forced: conn.execute(scheduled_jobs.update().where( scheduled_jobs.c.job_id == job_id).values( {scheduled_jobs.c.forced_stop_manually: True})) conn.execute(zones_currently_running.update().values( {zones_currently_running.c.force_stopped: True})) # With this db update we are updating the system_wide indication that "a" or "any" zone is running. # To access this, call use_database.zones_running_now() and it will return True or False on a systemwide # basis. conn.execute(zones_currently_running.update().values( {zones_currently_running.c.currently_running: False})) conn.execute(zones_currently_running.update().values( {zones_currently_running.c.run_manually: False})) conn.execute(zones_currently_running.update().values( {zones_currently_running.c.run_by_job: False})) conn.execute(zones_currently_running.update().values( {zones_currently_running.c.job_id: 0})) mcp.digitalWrite(self.gpio, 0) log.debug( f'Zone {self.zone_number} ({self.zone_name}) is now STOPPED.') else: log.debug( f'Zone {self.zone_number} ({self.zone_name}) is not currently running!!.' )
def update_running(is_running): with engine.begin() as conn: conn.execute(zones_currently_running.update().values({zones_currently_running.c.currently_running: is_running}))