nixpkgs-update: add queue
This commit is contained in:
parent
b87603f6cf
commit
77ed21e32b
3 changed files with 103 additions and 0 deletions
|
@ -3,4 +3,5 @@
|
||||||
- Logs: [https://nixpkgs-update-logs.nix-community.org](https://nixpkgs-update-logs.nix-community.org)
|
- Logs: [https://nixpkgs-update-logs.nix-community.org](https://nixpkgs-update-logs.nix-community.org)
|
||||||
- Nixpkgs Pull Requests: [https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+author%3Ar-ryantm](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+author%3Ar-ryantm)
|
- Nixpkgs Pull Requests: [https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+author%3Ar-ryantm](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+author%3Ar-ryantm)
|
||||||
- Matrix: [https://matrix.to/#/#nixpkgs-update:nixos.org](https://matrix.to/#/#nixpkgs-update:nixos.org)
|
- Matrix: [https://matrix.to/#/#nixpkgs-update:nixos.org](https://matrix.to/#/#nixpkgs-update:nixos.org)
|
||||||
|
- Queue: [https://nixpkgs-update-logs.nix-community.org/~supervisor/queue.html](https://nixpkgs-update-logs.nix-community.org/~supervisor/queue.html)
|
||||||
- Source: [https://github.com/nix-community/nixpkgs-update](https://github.com/nix-community/nixpkgs-update)
|
- Source: [https://github.com/nix-community/nixpkgs-update](https://github.com/nix-community/nixpkgs-update)
|
||||||
|
|
|
@ -191,6 +191,30 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemd.services.nixpkgs-update-queue = {
|
||||||
|
after = [ config.systemd.services.nixpkgs-update-supervisor.name ];
|
||||||
|
wantedBy = [ config.systemd.targets.multi-user.name ];
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "simple";
|
||||||
|
User = "r-ryantm";
|
||||||
|
Group = "r-ryantm";
|
||||||
|
Restart = "on-failure";
|
||||||
|
RestartSec = "5s";
|
||||||
|
LogsDirectory = "nixpkgs-update/";
|
||||||
|
LogsDirectoryMode = "755";
|
||||||
|
RuntimeDirectory = "nixpkgs-update-queue";
|
||||||
|
RuntimeDirectoryMode = "755";
|
||||||
|
};
|
||||||
|
|
||||||
|
path = [ pkgs.python3 ];
|
||||||
|
|
||||||
|
script = ''
|
||||||
|
cd "$LOGS_DIRECTORY/~supervisor"
|
||||||
|
python3 ${./update_queue.py}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
systemd.services.nixpkgs-update-delete-old-logs = {
|
systemd.services.nixpkgs-update-delete-old-logs = {
|
||||||
startAt = "daily";
|
startAt = "daily";
|
||||||
# delete logs older than 18 months, delete worker logs older than 3 months, delete empty directories
|
# delete logs older than 18 months, delete worker logs older than 3 months, delete empty directories
|
||||||
|
|
78
hosts/build02/update_queue.py
Normal file
78
hosts/build02/update_queue.py
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
import sqlite3
|
||||||
|
import time
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
|
||||||
|
def get_db_connection(db_path):
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
conn.row_factory = sqlite3.Row
|
||||||
|
return conn
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_queue_data(conn):
|
||||||
|
query = """
|
||||||
|
SELECT
|
||||||
|
ROW_NUMBER() OVER (ORDER BY last_started ASC) AS number,
|
||||||
|
attr_path,
|
||||||
|
payload
|
||||||
|
FROM
|
||||||
|
'queue'
|
||||||
|
ORDER BY
|
||||||
|
last_started ASC
|
||||||
|
"""
|
||||||
|
return conn.execute(query).fetchall()
|
||||||
|
|
||||||
|
|
||||||
|
def generate_html_table(rows):
|
||||||
|
table_rows = "".join(
|
||||||
|
f"""
|
||||||
|
<tr>
|
||||||
|
<td>{row['number']}</td>
|
||||||
|
<td>{row['attr_path']}</td>
|
||||||
|
<td>{row['payload']}</td>
|
||||||
|
</tr>
|
||||||
|
"""
|
||||||
|
for row in rows
|
||||||
|
)
|
||||||
|
return table_rows
|
||||||
|
|
||||||
|
|
||||||
|
def export_html(db_path):
|
||||||
|
with get_db_connection(db_path) as conn:
|
||||||
|
results = fetch_queue_data(conn)
|
||||||
|
|
||||||
|
generated = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
|
||||||
|
|
||||||
|
html = f"""
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>nixpkgs-update queue</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>nixpkgs-update queue</h1>
|
||||||
|
<h3>this page is updated every 15 minutes, last updated: {generated}</h3>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>number</th>
|
||||||
|
<th>attribute path</th>
|
||||||
|
<th>payload</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{generate_html_table(results)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
with open("queue.html", "w") as f:
|
||||||
|
f.write(html)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
DB_PATH = "state.db"
|
||||||
|
while True:
|
||||||
|
export_html(DB_PATH)
|
||||||
|
time.sleep(15 * 60)
|
Loading…
Add table
Reference in a new issue