Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
2a4452e67f
|
|||
71d347632c
|
|||
33c5205ea6
|
|||
6a82c30db7
|
|||
cc0068647b
|
|||
8f9669a829
|
@ -3,11 +3,12 @@ kind: CronJob
|
|||||||
metadata:
|
metadata:
|
||||||
name: pv-energy-calculator
|
name: pv-energy-calculator
|
||||||
spec:
|
spec:
|
||||||
schedule: "1 1 * * *"
|
schedule: "15 * * * *"
|
||||||
jobTemplate:
|
jobTemplate:
|
||||||
spec:
|
spec:
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
|
restartPolicy: OnFailure
|
||||||
containers:
|
containers:
|
||||||
- name: pv-energy-calculator
|
- name: pv-energy-calculator
|
||||||
image: %IMAGE%
|
image: %IMAGE%
|
||||||
|
@ -31,7 +31,7 @@ kubectl create secret generic pv-energy-calculator \
|
|||||||
--dry-run=client \
|
--dry-run=client \
|
||||||
-o yaml \
|
-o yaml \
|
||||||
--save-config \
|
--save-config \
|
||||||
--from-literal=PGPASSWORD="$PGPASSWORD" \
|
--from-literal=PGPASSWORD="$PGPASSWORD" | \
|
||||||
kubectl apply -f - -n $NAMESPACE
|
kubectl apply -f - -n $NAMESPACE
|
||||||
|
|
||||||
cat $DEPLOYMENT_DIR/deploy-yml.tmpl | \
|
cat $DEPLOYMENT_DIR/deploy-yml.tmpl | \
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
|
|
||||||
sv() {
|
|
||||||
cat pvec.sql | sed 's/%Y%/'$1'/' | sed 's/%M%/'$2'/' | sed 's/%D%/'$3'/' | psql -d udi-hottis
|
|
||||||
}
|
|
||||||
|
|
||||||
sv 2025 01 02
|
|
||||||
|
|
||||||
|
|
45
src/main.py
45
src/main.py
@ -1,45 +0,0 @@
|
|||||||
import psycopg
|
|
||||||
from loguru import logger
|
|
||||||
|
|
||||||
def main():
|
|
||||||
try:
|
|
||||||
conn = psycopg.connect()
|
|
||||||
logger.info("Database connection opened")
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error when opening database connection {e}"(
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
with conn.cursor(cursor_factory=psycopg.extras.DictCursor) as cursor:
|
|
||||||
select_stmt = psycopg.sql.SQL("""
|
|
||||||
SELECT ...
|
|
||||||
""")
|
|
||||||
cursor.execute(select_stmt, (...))
|
|
||||||
row = cursor.fetchone()
|
|
||||||
|
|
||||||
if not row:
|
|
||||||
logger.error(f"No data found")
|
|
||||||
return
|
|
||||||
|
|
||||||
value = row["bla"]
|
|
||||||
|
|
||||||
# calculation
|
|
||||||
insert_stmt = psycopg.sql.SQL("""
|
|
||||||
INSERT ...
|
|
||||||
""")
|
|
||||||
cursor.execute(insert_stmt, (...))
|
|
||||||
conn.commit()
|
|
||||||
|
|
||||||
logger.info(f"Data successfully written to database")
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error when selecting or writing database {e}")
|
|
||||||
conn.rollback()
|
|
||||||
finally:
|
|
||||||
conn.close()
|
|
||||||
logger.info("Database connection closed")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user