mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-05-22 06:36:14 +00:00
Compare commits
3 Commits
master
..
a69e3338b1
| Author | SHA1 | Date | |
|---|---|---|---|
| a69e3338b1 | |||
| 96ebb3793d | |||
| 3265bb913f |
@@ -26,10 +26,6 @@ jobs:
|
|||||||
|
|
||||||
- uses: docker/setup-buildx-action@v3
|
- uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Set image date
|
|
||||||
id: args
|
|
||||||
run: echo "::set-output name=date::$(date -d yesterday +'%Y-%m-%d')"
|
|
||||||
|
|
||||||
- name: Login to docker hub
|
- name: Login to docker hub
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
@@ -57,8 +53,6 @@ jobs:
|
|||||||
- name: Build an image and push
|
- name: Build an image and push
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
build-args: |
|
|
||||||
BUILD_DATE=${{ steps.args.outputs.date }}
|
|
||||||
file: docker/Dockerfile
|
file: docker/Dockerfile
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pacman -S --noconfirm --asdeps base-devel python-build python-flit python-instal
|
|||||||
# optional dependencies
|
# optional dependencies
|
||||||
if [[ -z $MINIMAL_INSTALL ]]; then
|
if [[ -z $MINIMAL_INSTALL ]]; then
|
||||||
# web server
|
# web server
|
||||||
pacman -S --noconfirm python-aioauth-client python-aiohttp python-aiohttp-apispec-git python-aiohttp-cors python-aiohttp-jinja2 python-aiohttp-security python-aiohttp-session python-aiohttp-sse-git python-cryptography python-jinja
|
pacman -S --noconfirm python-aioauth-client python-aiohttp python-aiohttp-apispec-git python-aiohttp-cors python-aiohttp-jinja2 python-aiohttp-security python-aiohttp-session python-cryptography python-jinja
|
||||||
# additional features
|
# additional features
|
||||||
pacman -S --noconfirm gnupg ipython python-boto3 python-cerberus python-matplotlib rsync
|
pacman -S --noconfirm gnupg ipython python-boto3 python-cerberus python-matplotlib rsync
|
||||||
fi
|
fi
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ version: 2
|
|||||||
build:
|
build:
|
||||||
os: ubuntu-lts-latest
|
os: ubuntu-lts-latest
|
||||||
tools:
|
tools:
|
||||||
python: "3.13"
|
python: "3.12"
|
||||||
apt_packages:
|
apt_packages:
|
||||||
- graphviz
|
- graphviz
|
||||||
|
|
||||||
|
|||||||
+3
-5
@@ -1,15 +1,13 @@
|
|||||||
# build image
|
# build image
|
||||||
FROM archlinux:base AS build
|
FROM archlinux:base AS build
|
||||||
|
|
||||||
ARG BUILD_DATE
|
|
||||||
|
|
||||||
# install environment
|
# install environment
|
||||||
## create build user
|
## create build user
|
||||||
RUN useradd -m -d "/home/build" -s "/usr/bin/nologin" build
|
RUN useradd -m -d "/home/build" -s "/usr/bin/nologin" build
|
||||||
|
|
||||||
## extract container creation date and set mirror for this timestamp, set PKGEXT and refresh database next
|
## extract container creation date and set mirror for this timestamp, set PKGEXT and refresh database next
|
||||||
RUN echo "Server = https://archive.archlinux.org/repos/${BUILD_DATE//-/\/}/\$repo/os/\$arch" > "/etc/pacman.d/mirrorlist" && \
|
RUN echo "Server = https://archive.archlinux.org/repos/$(stat -c "%y" "/var/lib/pacman" | cut -d " " -f 1 | sed "s,-,/,g")/\$repo/os/\$arch" > "/etc/pacman.d/mirrorlist" && \
|
||||||
pacman -Syyuu --noconfirm
|
pacman -Sy
|
||||||
## setup package cache
|
## setup package cache
|
||||||
RUN runuser -u build -- mkdir "/tmp/pkg" && \
|
RUN runuser -u build -- mkdir "/tmp/pkg" && \
|
||||||
echo "PKGDEST=/tmp/pkg" >> "/etc/makepkg.conf" && \
|
echo "PKGDEST=/tmp/pkg" >> "/etc/makepkg.conf" && \
|
||||||
@@ -110,7 +108,7 @@ RUN cp "/etc/pacman.d/mirrorlist" "/etc/pacman.d/mirrorlist.orig" && \
|
|||||||
echo "Server = file:///var/cache/pacman/pkg" > "/etc/pacman.d/mirrorlist" && \
|
echo "Server = file:///var/cache/pacman/pkg" > "/etc/pacman.d/mirrorlist" && \
|
||||||
cp "/etc/pacman.conf" "/etc/pacman.conf.orig" && \
|
cp "/etc/pacman.conf" "/etc/pacman.conf.orig" && \
|
||||||
sed -i "s/SigLevel *=.*/SigLevel = Optional/g" "/etc/pacman.conf" && \
|
sed -i "s/SigLevel *=.*/SigLevel = Optional/g" "/etc/pacman.conf" && \
|
||||||
pacman -Syyuu --noconfirm
|
pacman -Sy
|
||||||
## install package and its optional dependencies
|
## install package and its optional dependencies
|
||||||
RUN pacman -S --noconfirm ahriman
|
RUN pacman -S --noconfirm ahriman
|
||||||
RUN pacman -S --noconfirm --asdeps \
|
RUN pacman -S --noconfirm --asdeps \
|
||||||
|
|||||||
@@ -7,10 +7,8 @@ for PACKAGE in "$@"; do
|
|||||||
# clone the remote source
|
# clone the remote source
|
||||||
git clone https://aur.archlinux.org/"$PACKAGE".git "$BUILD_DIR"
|
git clone https://aur.archlinux.org/"$PACKAGE".git "$BUILD_DIR"
|
||||||
cd "$BUILD_DIR"
|
cd "$BUILD_DIR"
|
||||||
# FIXME monkey patch PKGBUILD for python
|
|
||||||
sed -i 's/python -m build/python -m build --skip-dependency-check/g' "PKGBUILD"
|
|
||||||
# checkout to the image date
|
# checkout to the image date
|
||||||
git checkout "$(git rev-list -1 --before="$BUILD_DATE" master)"
|
git checkout "$(git rev-list -1 --before="$(stat -c "%y" "/var/lib/pacman" | cut -d " " -f 1)" master)"
|
||||||
# build and install the package
|
# build and install the package
|
||||||
makepkg --nocheck --noconfirm --install --rmdeps --syncdeps
|
makepkg --nocheck --noconfirm --install --rmdeps --syncdeps
|
||||||
cd /
|
cd /
|
||||||
|
|||||||
@@ -188,7 +188,6 @@ Web server settings. This feature requires ``aiohttp`` libraries to be installed
|
|||||||
* ``host`` - host to bind, string, optional.
|
* ``host`` - host to bind, string, optional.
|
||||||
* ``index_url`` - full URL of the repository index page, string, optional.
|
* ``index_url`` - full URL of the repository index page, string, optional.
|
||||||
* ``max_body_size`` - max body size in bytes to be validated for archive upload, integer, optional. If not set, validation will be disabled.
|
* ``max_body_size`` - max body size in bytes to be validated for archive upload, integer, optional. If not set, validation will be disabled.
|
||||||
* ``max_queue_size`` - max queue size for server sent event streams, integer, optional, default ``0``. If set to ``0``, queue is unlimited.
|
|
||||||
* ``port`` - port to bind, integer, optional.
|
* ``port`` - port to bind, integer, optional.
|
||||||
* ``service_only`` - disable status routes (including logs), boolean, optional, default ``no``.
|
* ``service_only`` - disable status routes (including logs), boolean, optional, default ``no``.
|
||||||
* ``static_path`` - path to directory with static files, string, required.
|
* ``static_path`` - path to directory with static files, string, required.
|
||||||
@@ -196,7 +195,7 @@ Web server settings. This feature requires ``aiohttp`` libraries to be installed
|
|||||||
* ``templates`` - path to templates directories, space separated list of paths, required.
|
* ``templates`` - path to templates directories, space separated list of paths, required.
|
||||||
* ``unix_socket`` - path to the listening unix socket, string, optional. If set, server will create the socket on the specified address which can (and will) be used by application. Note, that unlike usual host/port configuration, unix socket allows to perform requests without authorization.
|
* ``unix_socket`` - path to the listening unix socket, string, optional. If set, server will create the socket on the specified address which can (and will) be used by application. Note, that unlike usual host/port configuration, unix socket allows to perform requests without authorization.
|
||||||
* ``unix_socket_unsafe`` - set unsafe (o+w) permissions to unix socket, boolean, optional, default ``yes``. This option is enabled by default, because it is supposed that unix socket is created in safe environment (only web service is supposed to be used in unsafe), but it can be disabled by configuration.
|
* ``unix_socket_unsafe`` - set unsafe (o+w) permissions to unix socket, boolean, optional, default ``yes``. This option is enabled by default, because it is supposed that unix socket is created in safe environment (only web service is supposed to be used in unsafe), but it can be disabled by configuration.
|
||||||
* ``wait_timeout`` - wait timeout in seconds, maximum amount of time to be waited before lock will be free, integer, optional. If set to ``0``, wait infinitely.
|
* ``wait_timeout`` - wait timeout in seconds, maximum amount of time to be waited before lock will be free, integer, optional.
|
||||||
|
|
||||||
``archive`` group
|
``archive`` group
|
||||||
-----------------
|
-----------------
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|||||||
import AppLayout from "components/layout/AppLayout";
|
import AppLayout from "components/layout/AppLayout";
|
||||||
import { AuthProvider } from "contexts/AuthProvider";
|
import { AuthProvider } from "contexts/AuthProvider";
|
||||||
import { ClientProvider } from "contexts/ClientProvider";
|
import { ClientProvider } from "contexts/ClientProvider";
|
||||||
import { EventStreamProvider } from "contexts/EventStreamProvider";
|
|
||||||
import { NotificationProvider } from "contexts/NotificationProvider";
|
import { NotificationProvider } from "contexts/NotificationProvider";
|
||||||
import { RepositoryProvider } from "contexts/RepositoryProvider";
|
import { RepositoryProvider } from "contexts/RepositoryProvider";
|
||||||
import { ThemeProvider } from "contexts/ThemeProvider";
|
import { ThemeProvider } from "contexts/ThemeProvider";
|
||||||
@@ -43,9 +42,7 @@ export default function App(): React.JSX.Element {
|
|||||||
<ClientProvider>
|
<ClientProvider>
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<RepositoryProvider>
|
<RepositoryProvider>
|
||||||
<EventStreamProvider>
|
<AppLayout />
|
||||||
<AppLayout />
|
|
||||||
</EventStreamProvider>
|
|
||||||
</RepositoryProvider>
|
</RepositoryProvider>
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
</ClientProvider>
|
</ClientProvider>
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021-2026 ahriman team.
|
||||||
|
*
|
||||||
|
* This file is part of ahriman
|
||||||
|
* (see https://github.com/arcan1s/ahriman).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
import CheckIcon from "@mui/icons-material/Check";
|
||||||
|
import TimerIcon from "@mui/icons-material/Timer";
|
||||||
|
import TimerOffIcon from "@mui/icons-material/TimerOff";
|
||||||
|
import { IconButton, ListItemIcon, ListItemText, Menu, MenuItem, Tooltip } from "@mui/material";
|
||||||
|
import type { AutoRefreshInterval } from "models/AutoRefreshInterval";
|
||||||
|
import React, { useState } from "react";
|
||||||
|
|
||||||
|
interface AutoRefreshControlProps {
|
||||||
|
currentInterval: number;
|
||||||
|
intervals: AutoRefreshInterval[];
|
||||||
|
onIntervalChange: (interval: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AutoRefreshControl({
|
||||||
|
currentInterval,
|
||||||
|
intervals,
|
||||||
|
onIntervalChange,
|
||||||
|
}: AutoRefreshControlProps): React.JSX.Element | null {
|
||||||
|
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
if (intervals.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const enabled = currentInterval > 0;
|
||||||
|
|
||||||
|
return <>
|
||||||
|
<Tooltip title="Auto-refresh">
|
||||||
|
<IconButton
|
||||||
|
aria-label="Auto-refresh"
|
||||||
|
color={enabled ? "primary" : "default"}
|
||||||
|
onClick={event => setAnchorEl(event.currentTarget)}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
{enabled ? <TimerIcon fontSize="small" /> : <TimerOffIcon fontSize="small" />}
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
<Menu
|
||||||
|
anchorEl={anchorEl}
|
||||||
|
onClose={() => setAnchorEl(null)}
|
||||||
|
open={Boolean(anchorEl)}
|
||||||
|
>
|
||||||
|
<MenuItem
|
||||||
|
onClick={() => {
|
||||||
|
onIntervalChange(0);
|
||||||
|
setAnchorEl(null);
|
||||||
|
}}
|
||||||
|
selected={!enabled}
|
||||||
|
>
|
||||||
|
<ListItemIcon>
|
||||||
|
{!enabled && <CheckIcon fontSize="small" />}
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText>Off</ListItemText>
|
||||||
|
</MenuItem>
|
||||||
|
{intervals.map(interval =>
|
||||||
|
<MenuItem
|
||||||
|
key={interval.interval}
|
||||||
|
onClick={() => {
|
||||||
|
onIntervalChange(interval.interval);
|
||||||
|
setAnchorEl(null);
|
||||||
|
}}
|
||||||
|
selected={enabled && interval.interval === currentInterval}
|
||||||
|
>
|
||||||
|
<ListItemIcon>
|
||||||
|
{enabled && interval.interval === currentInterval && <CheckIcon fontSize="small" />}
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText>{interval.text}</ListItemText>
|
||||||
|
</MenuItem>,
|
||||||
|
)}
|
||||||
|
</Menu>
|
||||||
|
</>;
|
||||||
|
}
|
||||||
@@ -32,22 +32,27 @@ import PkgbuildTab from "components/package/PkgbuildTab";
|
|||||||
import { type TabKey, tabs } from "components/package/TabKey";
|
import { type TabKey, tabs } from "components/package/TabKey";
|
||||||
import { QueryKeys } from "hooks/QueryKeys";
|
import { QueryKeys } from "hooks/QueryKeys";
|
||||||
import { useAuth } from "hooks/useAuth";
|
import { useAuth } from "hooks/useAuth";
|
||||||
|
import { useAutoRefresh } from "hooks/useAutoRefresh";
|
||||||
import { useClient } from "hooks/useClient";
|
import { useClient } from "hooks/useClient";
|
||||||
import { useNotification } from "hooks/useNotification";
|
import { useNotification } from "hooks/useNotification";
|
||||||
import { useRepository } from "hooks/useRepository";
|
import { useRepository } from "hooks/useRepository";
|
||||||
|
import type { AutoRefreshInterval } from "models/AutoRefreshInterval";
|
||||||
import type { Dependencies } from "models/Dependencies";
|
import type { Dependencies } from "models/Dependencies";
|
||||||
import type { PackageStatus } from "models/PackageStatus";
|
import type { PackageStatus } from "models/PackageStatus";
|
||||||
import type { Patch } from "models/Patch";
|
import type { Patch } from "models/Patch";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { StatusHeaderStyles } from "theme/StatusColors";
|
import { StatusHeaderStyles } from "theme/StatusColors";
|
||||||
|
import { defaultInterval } from "utils";
|
||||||
|
|
||||||
interface PackageInfoDialogProps {
|
interface PackageInfoDialogProps {
|
||||||
|
autoRefreshIntervals: AutoRefreshInterval[];
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
packageBase: string | null;
|
packageBase: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PackageInfoDialog({
|
export default function PackageInfoDialog({
|
||||||
|
autoRefreshIntervals,
|
||||||
onClose,
|
onClose,
|
||||||
open,
|
open,
|
||||||
packageBase,
|
packageBase,
|
||||||
@@ -72,11 +77,14 @@ export default function PackageInfoDialog({
|
|||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const autoRefresh = useAutoRefresh("package-info-autoreload-button", defaultInterval(autoRefreshIntervals));
|
||||||
|
|
||||||
const { data: packageData } = useQuery<PackageStatus[]>({
|
const { data: packageData } = useQuery<PackageStatus[]>({
|
||||||
enabled: open,
|
enabled: open,
|
||||||
queryFn: localPackageBase && currentRepository ?
|
queryFn: localPackageBase && currentRepository ?
|
||||||
() => client.fetch.fetchPackage(localPackageBase, currentRepository) : skipToken,
|
() => client.fetch.fetchPackage(localPackageBase, currentRepository) : skipToken,
|
||||||
queryKey: localPackageBase && currentRepository ? QueryKeys.package(localPackageBase, currentRepository) : ["packages"],
|
queryKey: localPackageBase && currentRepository ? QueryKeys.package(localPackageBase, currentRepository) : ["packages"],
|
||||||
|
refetchInterval: autoRefresh.interval > 0 ? autoRefresh.interval : false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: dependencies } = useQuery<Dependencies>({
|
const { data: dependencies } = useQuery<Dependencies>({
|
||||||
@@ -174,6 +182,7 @@ export default function PackageInfoDialog({
|
|||||||
{activeTab === "logs" && localPackageBase && currentRepository &&
|
{activeTab === "logs" && localPackageBase && currentRepository &&
|
||||||
<BuildLogsTab
|
<BuildLogsTab
|
||||||
packageBase={localPackageBase}
|
packageBase={localPackageBase}
|
||||||
|
refreshInterval={autoRefresh.interval}
|
||||||
repository={currentRepository}
|
repository={currentRepository}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@@ -198,8 +207,11 @@ export default function PackageInfoDialog({
|
|||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|
||||||
<PackageInfoActions
|
<PackageInfoActions
|
||||||
|
autoRefreshInterval={autoRefresh.interval}
|
||||||
|
autoRefreshIntervals={autoRefreshIntervals}
|
||||||
isAuthorized={isAuthorized}
|
isAuthorized={isAuthorized}
|
||||||
isHeld={status?.is_held ?? false}
|
isHeld={status?.is_held ?? false}
|
||||||
|
onAutoRefreshIntervalChange={autoRefresh.setInterval}
|
||||||
onHoldToggle={() => void handleHoldToggle()}
|
onHoldToggle={() => void handleHoldToggle()}
|
||||||
onRefreshDatabaseChange={setRefreshDatabase}
|
onRefreshDatabaseChange={setRefreshDatabase}
|
||||||
onRemove={() => void handleRemove()}
|
onRemove={() => void handleRemove()}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export default function AppLayout(): React.JSX.Element {
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<PackageTable />
|
<PackageTable autoRefreshIntervals={info?.autorefresh_intervals ?? []} />
|
||||||
|
|
||||||
<Footer
|
<Footer
|
||||||
docsEnabled={info?.docs_enabled ?? false}
|
docsEnabled={info?.docs_enabled ?? false}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import { keepPreviousData, skipToken, useQuery } from "@tanstack/react-query";
|
|||||||
import CodeBlock from "components/common/CodeBlock";
|
import CodeBlock from "components/common/CodeBlock";
|
||||||
import { QueryKeys } from "hooks/QueryKeys";
|
import { QueryKeys } from "hooks/QueryKeys";
|
||||||
import { useAutoScroll } from "hooks/useAutoScroll";
|
import { useAutoScroll } from "hooks/useAutoScroll";
|
||||||
import { useBuildLogStream } from "hooks/useBuildLogStream";
|
|
||||||
import { useClient } from "hooks/useClient";
|
import { useClient } from "hooks/useClient";
|
||||||
import type { LogRecord } from "models/LogRecord";
|
import type { LogRecord } from "models/LogRecord";
|
||||||
import type { RepositoryId } from "models/RepositoryId";
|
import type { RepositoryId } from "models/RepositoryId";
|
||||||
@@ -38,6 +37,7 @@ interface Logs {
|
|||||||
|
|
||||||
interface BuildLogsTabProps {
|
interface BuildLogsTabProps {
|
||||||
packageBase: string;
|
packageBase: string;
|
||||||
|
refreshInterval: number;
|
||||||
repository: RepositoryId;
|
repository: RepositoryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,10 +50,10 @@ function convertLogs(records: LogRecord[], filter?: (record: LogRecord) => boole
|
|||||||
|
|
||||||
export default function BuildLogsTab({
|
export default function BuildLogsTab({
|
||||||
packageBase,
|
packageBase,
|
||||||
|
refreshInterval,
|
||||||
repository,
|
repository,
|
||||||
}: BuildLogsTabProps): React.JSX.Element {
|
}: BuildLogsTabProps): React.JSX.Element {
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
useBuildLogStream(packageBase, repository);
|
|
||||||
const [selectedVersionKey, setSelectedVersionKey] = useState<string | null>(null);
|
const [selectedVersionKey, setSelectedVersionKey] = useState<string | null>(null);
|
||||||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
||||||
|
|
||||||
@@ -61,6 +61,7 @@ export default function BuildLogsTab({
|
|||||||
enabled: !!packageBase,
|
enabled: !!packageBase,
|
||||||
queryFn: () => client.fetch.fetchPackageLogs(packageBase, repository),
|
queryFn: () => client.fetch.fetchPackageLogs(packageBase, repository),
|
||||||
queryKey: QueryKeys.logs(packageBase, repository),
|
queryKey: QueryKeys.logs(packageBase, repository),
|
||||||
|
refetchInterval: refreshInterval > 0 ? refreshInterval : false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Build version selectors from all logs
|
// Build version selectors from all logs
|
||||||
@@ -116,6 +117,7 @@ export default function BuildLogsTab({
|
|||||||
)
|
)
|
||||||
: skipToken,
|
: skipToken,
|
||||||
queryKey: QueryKeys.logsVersion(packageBase, repository, activeVersion?.version ?? "", activeVersion?.processId ?? ""),
|
queryKey: QueryKeys.logsVersion(packageBase, repository, activeVersion?.version ?? "", activeVersion?.processId ?? ""),
|
||||||
|
refetchInterval: refreshInterval > 0 ? refreshInterval : false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Derive displayed logs: prefer fresh polled data when available
|
// Derive displayed logs: prefer fresh polled data when available
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ export default function PackageDetailsGrid({ dependencies, pkg }: PackageDetails
|
|||||||
<Grid size={{ md: 5, xs: 8 }}>
|
<Grid size={{ md: 5, xs: 8 }}>
|
||||||
<Typography variant="body2">
|
<Typography variant="body2">
|
||||||
{aurUrl &&
|
{aurUrl &&
|
||||||
<Link href={aurUrl} rel="noopener noreferrer" target="_blank" underline="hover">{aurUrl}</Link>
|
<Link href={aurUrl} rel="noopener noreferrer" target="_blank" underline="hover">AUR link</Link>
|
||||||
}
|
}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -22,11 +22,16 @@ import PauseCircleIcon from "@mui/icons-material/PauseCircle";
|
|||||||
import PlayArrowIcon from "@mui/icons-material/PlayArrow";
|
import PlayArrowIcon from "@mui/icons-material/PlayArrow";
|
||||||
import PlayCircleIcon from "@mui/icons-material/PlayCircle";
|
import PlayCircleIcon from "@mui/icons-material/PlayCircle";
|
||||||
import { Button, Checkbox, DialogActions, FormControlLabel } from "@mui/material";
|
import { Button, Checkbox, DialogActions, FormControlLabel } from "@mui/material";
|
||||||
|
import AutoRefreshControl from "components/common/AutoRefreshControl";
|
||||||
|
import type { AutoRefreshInterval } from "models/AutoRefreshInterval";
|
||||||
import type React from "react";
|
import type React from "react";
|
||||||
|
|
||||||
interface PackageInfoActionsProps {
|
interface PackageInfoActionsProps {
|
||||||
|
autoRefreshInterval: number;
|
||||||
|
autoRefreshIntervals: AutoRefreshInterval[];
|
||||||
isAuthorized: boolean;
|
isAuthorized: boolean;
|
||||||
isHeld: boolean;
|
isHeld: boolean;
|
||||||
|
onAutoRefreshIntervalChange: (interval: number) => void;
|
||||||
onHoldToggle: () => void;
|
onHoldToggle: () => void;
|
||||||
onRefreshDatabaseChange: (checked: boolean) => void;
|
onRefreshDatabaseChange: (checked: boolean) => void;
|
||||||
onRemove: () => void;
|
onRemove: () => void;
|
||||||
@@ -35,8 +40,11 @@ interface PackageInfoActionsProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function PackageInfoActions({
|
export default function PackageInfoActions({
|
||||||
|
autoRefreshInterval,
|
||||||
|
autoRefreshIntervals,
|
||||||
isAuthorized,
|
isAuthorized,
|
||||||
isHeld,
|
isHeld,
|
||||||
|
onAutoRefreshIntervalChange,
|
||||||
onHoldToggle,
|
onHoldToggle,
|
||||||
onRefreshDatabaseChange,
|
onRefreshDatabaseChange,
|
||||||
onRemove,
|
onRemove,
|
||||||
@@ -61,5 +69,10 @@ export default function PackageInfoActions({
|
|||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
<AutoRefreshControl
|
||||||
|
currentInterval={autoRefreshInterval}
|
||||||
|
intervals={autoRefreshIntervals}
|
||||||
|
onIntervalChange={onAutoRefreshIntervalChange}
|
||||||
|
/>
|
||||||
</DialogActions>;
|
</DialogActions>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,14 @@ import PackageTableToolbar from "components/table/PackageTableToolbar";
|
|||||||
import StatusCell from "components/table/StatusCell";
|
import StatusCell from "components/table/StatusCell";
|
||||||
import { useDebounce } from "hooks/useDebounce";
|
import { useDebounce } from "hooks/useDebounce";
|
||||||
import { usePackageTable } from "hooks/usePackageTable";
|
import { usePackageTable } from "hooks/usePackageTable";
|
||||||
|
import type { AutoRefreshInterval } from "models/AutoRefreshInterval";
|
||||||
import type { PackageRow } from "models/PackageRow";
|
import type { PackageRow } from "models/PackageRow";
|
||||||
import React, { useMemo } from "react";
|
import React, { useMemo } from "react";
|
||||||
|
|
||||||
|
interface PackageTableProps {
|
||||||
|
autoRefreshIntervals: AutoRefreshInterval[];
|
||||||
|
}
|
||||||
|
|
||||||
function createListColumn(
|
function createListColumn(
|
||||||
field: keyof PackageRow,
|
field: keyof PackageRow,
|
||||||
headerName: string,
|
headerName: string,
|
||||||
@@ -54,8 +59,8 @@ function createListColumn(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PackageTable(): React.JSX.Element {
|
export default function PackageTable({ autoRefreshIntervals }: PackageTableProps): React.JSX.Element {
|
||||||
const table = usePackageTable();
|
const table = usePackageTable(autoRefreshIntervals);
|
||||||
const apiRef = useGridApiRef();
|
const apiRef = useGridApiRef();
|
||||||
const debouncedSearch = useDebounce(table.searchText, 300);
|
const debouncedSearch = useDebounce(table.searchText, 300);
|
||||||
|
|
||||||
@@ -113,6 +118,11 @@ export default function PackageTable(): React.JSX.Element {
|
|||||||
onRemoveClick: () => void table.handleRemove(),
|
onRemoveClick: () => void table.handleRemove(),
|
||||||
onUpdateClick: () => void table.handleUpdate(),
|
onUpdateClick: () => void table.handleUpdate(),
|
||||||
}}
|
}}
|
||||||
|
autoRefresh={{
|
||||||
|
autoRefreshIntervals,
|
||||||
|
currentInterval: table.autoRefreshInterval,
|
||||||
|
onIntervalChange: table.onAutoRefreshIntervalChange,
|
||||||
|
}}
|
||||||
isAuthorized={table.isAuthorized}
|
isAuthorized={table.isAuthorized}
|
||||||
hasSelection={table.selectionModel.length > 0}
|
hasSelection={table.selectionModel.length > 0}
|
||||||
onSearchChange={table.setSearchText}
|
onSearchChange={table.setSearchText}
|
||||||
@@ -165,6 +175,7 @@ export default function PackageTable(): React.JSX.Element {
|
|||||||
<PackageRebuildDialog onClose={() => table.setDialogOpen(null)} open={table.dialogOpen === "rebuild"} />
|
<PackageRebuildDialog onClose={() => table.setDialogOpen(null)} open={table.dialogOpen === "rebuild"} />
|
||||||
<KeyImportDialog onClose={() => table.setDialogOpen(null)} open={table.dialogOpen === "keyImport"} />
|
<KeyImportDialog onClose={() => table.setDialogOpen(null)} open={table.dialogOpen === "keyImport"} />
|
||||||
<PackageInfoDialog
|
<PackageInfoDialog
|
||||||
|
autoRefreshIntervals={autoRefreshIntervals}
|
||||||
onClose={() => table.setSelectedPackage(null)}
|
onClose={() => table.setSelectedPackage(null)}
|
||||||
open={table.selectedPackage !== null}
|
open={table.selectedPackage !== null}
|
||||||
packageBase={table.selectedPackage}
|
packageBase={table.selectedPackage}
|
||||||
|
|||||||
@@ -30,10 +30,18 @@ import ReplayIcon from "@mui/icons-material/Replay";
|
|||||||
import SearchIcon from "@mui/icons-material/Search";
|
import SearchIcon from "@mui/icons-material/Search";
|
||||||
import VpnKeyIcon from "@mui/icons-material/VpnKey";
|
import VpnKeyIcon from "@mui/icons-material/VpnKey";
|
||||||
import { Box, Button, Divider, IconButton, InputAdornment, Menu, MenuItem, TextField, Tooltip } from "@mui/material";
|
import { Box, Button, Divider, IconButton, InputAdornment, Menu, MenuItem, TextField, Tooltip } from "@mui/material";
|
||||||
|
import AutoRefreshControl from "components/common/AutoRefreshControl";
|
||||||
|
import type { AutoRefreshInterval } from "models/AutoRefreshInterval";
|
||||||
import type { BuildStatus } from "models/BuildStatus";
|
import type { BuildStatus } from "models/BuildStatus";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { StatusColors } from "theme/StatusColors";
|
import { StatusColors } from "theme/StatusColors";
|
||||||
|
|
||||||
|
export interface AutoRefreshProps {
|
||||||
|
autoRefreshIntervals: AutoRefreshInterval[];
|
||||||
|
currentInterval: number;
|
||||||
|
onIntervalChange: (interval: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ToolbarActions {
|
export interface ToolbarActions {
|
||||||
onAddClick: () => void;
|
onAddClick: () => void;
|
||||||
onDashboardClick: () => void;
|
onDashboardClick: () => void;
|
||||||
@@ -48,6 +56,7 @@ export interface ToolbarActions {
|
|||||||
|
|
||||||
interface PackageTableToolbarProps {
|
interface PackageTableToolbarProps {
|
||||||
actions: ToolbarActions;
|
actions: ToolbarActions;
|
||||||
|
autoRefresh: AutoRefreshProps;
|
||||||
hasSelection: boolean;
|
hasSelection: boolean;
|
||||||
isAuthorized: boolean;
|
isAuthorized: boolean;
|
||||||
onSearchChange: (text: string) => void;
|
onSearchChange: (text: string) => void;
|
||||||
@@ -57,6 +66,7 @@ interface PackageTableToolbarProps {
|
|||||||
|
|
||||||
export default function PackageTableToolbar({
|
export default function PackageTableToolbar({
|
||||||
actions,
|
actions,
|
||||||
|
autoRefresh,
|
||||||
hasSelection,
|
hasSelection,
|
||||||
isAuthorized,
|
isAuthorized,
|
||||||
onSearchChange,
|
onSearchChange,
|
||||||
@@ -133,6 +143,12 @@ export default function PackageTableToolbar({
|
|||||||
reload
|
reload
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
<AutoRefreshControl
|
||||||
|
currentInterval={autoRefresh.currentInterval}
|
||||||
|
intervals={autoRefresh.autoRefreshIntervals}
|
||||||
|
onIntervalChange={autoRefresh.onIntervalChange}
|
||||||
|
/>
|
||||||
|
|
||||||
<Box sx={{ flexGrow: 1 }} />
|
<Box sx={{ flexGrow: 1 }} />
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021-2026 ahriman team.
|
||||||
|
*
|
||||||
|
* This file is part of ahriman
|
||||||
|
* (see https://github.com/arcan1s/ahriman).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
import { useLocalStorage } from "hooks/useLocalStorage";
|
||||||
|
import { type Dispatch, type SetStateAction, useEffect, useState } from "react";
|
||||||
|
|
||||||
|
interface AutoRefreshResult {
|
||||||
|
interval: number;
|
||||||
|
setInterval: Dispatch<SetStateAction<number>>;
|
||||||
|
setPaused: Dispatch<SetStateAction<boolean>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useAutoRefresh(key: string, defaultInterval: number): AutoRefreshResult {
|
||||||
|
const storageKey = `ahriman-${key}`;
|
||||||
|
const [interval, setInterval] = useLocalStorage<number>(storageKey, defaultInterval);
|
||||||
|
const [paused, setPaused] = useState(false);
|
||||||
|
|
||||||
|
// Apply defaultInterval when it becomes available (e.g. after info endpoint loads)
|
||||||
|
// but only if the user hasn't explicitly set a preference
|
||||||
|
useEffect(() => {
|
||||||
|
if (defaultInterval > 0 && window.localStorage.getItem(storageKey) === null) {
|
||||||
|
setInterval(defaultInterval);
|
||||||
|
}
|
||||||
|
}, [storageKey, defaultInterval, setInterval]);
|
||||||
|
|
||||||
|
const effectiveInterval = paused ? 0 : interval;
|
||||||
|
|
||||||
|
return {
|
||||||
|
interval: effectiveInterval,
|
||||||
|
setInterval,
|
||||||
|
setPaused,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021-2026 ahriman team.
|
|
||||||
*
|
|
||||||
* This file is part of ahriman
|
|
||||||
* (see https://github.com/arcan1s/ahriman).
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
|
||||||
import { buildEventStreamUrl } from "hooks/useEventStream";
|
|
||||||
import type { LogRecord } from "models/LogRecord";
|
|
||||||
import type { RepositoryId } from "models/RepositoryId";
|
|
||||||
import { useEffect } from "react";
|
|
||||||
|
|
||||||
interface BuildLogEvent {
|
|
||||||
created: number;
|
|
||||||
message: string;
|
|
||||||
process_id: string;
|
|
||||||
version: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function appendLogRecord(existing: LogRecord[] | undefined, record: LogRecord): LogRecord[] {
|
|
||||||
return [...existing ?? [], record];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useBuildLogStream(packageBase: string, repository: RepositoryId): void {
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const source = new EventSource(buildEventStreamUrl(repository, ["build-log"], packageBase));
|
|
||||||
|
|
||||||
source.addEventListener("build-log", (event: MessageEvent<string>) => {
|
|
||||||
const data = JSON.parse(event.data) as BuildLogEvent;
|
|
||||||
|
|
||||||
const record: LogRecord = {
|
|
||||||
created: data.created,
|
|
||||||
message: data.message,
|
|
||||||
process_id: data.process_id,
|
|
||||||
version: data.version,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Append to the all-logs cache
|
|
||||||
queryClient.setQueryData<LogRecord[]>(
|
|
||||||
["logs", repository.key, packageBase],
|
|
||||||
existing => appendLogRecord(existing, record),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Append to the version-specific cache
|
|
||||||
queryClient.setQueryData<LogRecord[]>(
|
|
||||||
["logs", repository.key, packageBase, record.version, record.process_id],
|
|
||||||
existing => appendLogRecord(existing, record),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
source.close();
|
|
||||||
};
|
|
||||||
}, [queryClient, packageBase, repository]);
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021-2026 ahriman team.
|
|
||||||
*
|
|
||||||
* This file is part of ahriman
|
|
||||||
* (see https://github.com/arcan1s/ahriman).
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import type { QueryClient } from "@tanstack/react-query";
|
|
||||||
import type { RepositoryId } from "models/RepositoryId";
|
|
||||||
import { useEffect } from "react";
|
|
||||||
|
|
||||||
const GLOBAL_EVENT_TYPES = [
|
|
||||||
"package-held",
|
|
||||||
"package-outdated",
|
|
||||||
"package-removed",
|
|
||||||
"package-status-changed",
|
|
||||||
"package-update-failed",
|
|
||||||
"package-updated",
|
|
||||||
"service-status-changed",
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
function invalidateForEvent(
|
|
||||||
queryClient: QueryClient,
|
|
||||||
repositoryKey: string,
|
|
||||||
eventType: string,
|
|
||||||
objectId?: string,
|
|
||||||
): void {
|
|
||||||
switch (eventType) {
|
|
||||||
case "package-status-changed":
|
|
||||||
case "package-updated":
|
|
||||||
case "package-removed":
|
|
||||||
case "package-held":
|
|
||||||
void queryClient.invalidateQueries({ queryKey: ["packages", repositoryKey] });
|
|
||||||
void queryClient.invalidateQueries({ queryKey: ["status", repositoryKey] });
|
|
||||||
if (objectId) {
|
|
||||||
void queryClient.invalidateQueries({ queryKey: ["packages", repositoryKey, objectId] });
|
|
||||||
void queryClient.invalidateQueries({ queryKey: ["events", repositoryKey, objectId] });
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "service-status-changed":
|
|
||||||
void queryClient.invalidateQueries({ queryKey: ["status", repositoryKey] });
|
|
||||||
break;
|
|
||||||
case "package-outdated":
|
|
||||||
case "package-update-failed":
|
|
||||||
void queryClient.invalidateQueries({ queryKey: ["packages", repositoryKey] });
|
|
||||||
if (objectId) {
|
|
||||||
void queryClient.invalidateQueries({ queryKey: ["packages", repositoryKey, objectId] });
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildEventStreamUrl(
|
|
||||||
repository: RepositoryId,
|
|
||||||
events?: readonly string[],
|
|
||||||
objectId?: string,
|
|
||||||
): string {
|
|
||||||
const params = new URLSearchParams(repository.toQuery());
|
|
||||||
if (events) {
|
|
||||||
for (const event of events) {
|
|
||||||
params.append("event", event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (objectId) {
|
|
||||||
params.set("object_id", objectId);
|
|
||||||
}
|
|
||||||
return `/api/v1/events/stream?${params.toString()}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useEventStream(queryClient: QueryClient, repository: RepositoryId | null): void {
|
|
||||||
useEffect(() => {
|
|
||||||
if (!repository) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const source = new EventSource(buildEventStreamUrl(repository, GLOBAL_EVENT_TYPES));
|
|
||||||
|
|
||||||
for (const eventType of GLOBAL_EVENT_TYPES) {
|
|
||||||
source.addEventListener(eventType, (event: MessageEvent<string>) => {
|
|
||||||
const data = JSON.parse(event.data) as { object_id?: string };
|
|
||||||
invalidateForEvent(queryClient, repository.key, eventType, data.object_id ?? undefined);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
source.close();
|
|
||||||
};
|
|
||||||
}, [queryClient, repository]);
|
|
||||||
}
|
|
||||||
@@ -20,37 +20,46 @@
|
|||||||
import { skipToken, useQuery } from "@tanstack/react-query";
|
import { skipToken, useQuery } from "@tanstack/react-query";
|
||||||
import { QueryKeys } from "hooks/QueryKeys";
|
import { QueryKeys } from "hooks/QueryKeys";
|
||||||
import { useAuth } from "hooks/useAuth";
|
import { useAuth } from "hooks/useAuth";
|
||||||
|
import { useAutoRefresh } from "hooks/useAutoRefresh";
|
||||||
import { useClient } from "hooks/useClient";
|
import { useClient } from "hooks/useClient";
|
||||||
import { useRepository } from "hooks/useRepository";
|
import { useRepository } from "hooks/useRepository";
|
||||||
|
import type { AutoRefreshInterval } from "models/AutoRefreshInterval";
|
||||||
import type { BuildStatus } from "models/BuildStatus";
|
import type { BuildStatus } from "models/BuildStatus";
|
||||||
import { PackageRow } from "models/PackageRow";
|
import { PackageRow } from "models/PackageRow";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
|
import { defaultInterval } from "utils";
|
||||||
|
|
||||||
export interface UsePackageDataResult {
|
export interface UsePackageDataResult {
|
||||||
|
autoRefresh: ReturnType<typeof useAutoRefresh>;
|
||||||
isAuthorized: boolean;
|
isAuthorized: boolean;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
rows: PackageRow[];
|
rows: PackageRow[];
|
||||||
status: BuildStatus | undefined;
|
status: BuildStatus | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePackageData(): UsePackageDataResult {
|
export function usePackageData(autoRefreshIntervals: AutoRefreshInterval[]): UsePackageDataResult {
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
const { currentRepository } = useRepository();
|
const { currentRepository } = useRepository();
|
||||||
const { isAuthorized } = useAuth();
|
const { isAuthorized } = useAuth();
|
||||||
|
|
||||||
|
const autoRefresh = useAutoRefresh("table-autoreload-button", defaultInterval(autoRefreshIntervals));
|
||||||
|
|
||||||
const { data: packages = [], isLoading } = useQuery({
|
const { data: packages = [], isLoading } = useQuery({
|
||||||
queryFn: currentRepository ? () => client.fetch.fetchPackages(currentRepository) : skipToken,
|
queryFn: currentRepository ? () => client.fetch.fetchPackages(currentRepository) : skipToken,
|
||||||
queryKey: currentRepository ? QueryKeys.packages(currentRepository) : ["packages"],
|
queryKey: currentRepository ? QueryKeys.packages(currentRepository) : ["packages"],
|
||||||
|
refetchInterval: autoRefresh.interval > 0 ? autoRefresh.interval : false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: status } = useQuery({
|
const { data: status } = useQuery({
|
||||||
queryFn: currentRepository ? () => client.fetch.fetchServerStatus(currentRepository) : skipToken,
|
queryFn: currentRepository ? () => client.fetch.fetchServerStatus(currentRepository) : skipToken,
|
||||||
queryKey: currentRepository ? QueryKeys.status(currentRepository) : ["status"],
|
queryKey: currentRepository ? QueryKeys.status(currentRepository) : ["status"],
|
||||||
|
refetchInterval: autoRefresh.interval > 0 ? autoRefresh.interval : false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const rows = useMemo(() => packages.map(descriptor => new PackageRow(descriptor)), [packages]);
|
const rows = useMemo(() => packages.map(descriptor => new PackageRow(descriptor)), [packages]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
autoRefresh,
|
||||||
isLoading,
|
isLoading,
|
||||||
isAuthorized,
|
isAuthorized,
|
||||||
rows,
|
rows,
|
||||||
|
|||||||
@@ -21,10 +21,13 @@ import type { GridFilterModel } from "@mui/x-data-grid";
|
|||||||
import { usePackageActions } from "hooks/usePackageActions";
|
import { usePackageActions } from "hooks/usePackageActions";
|
||||||
import { usePackageData } from "hooks/usePackageData";
|
import { usePackageData } from "hooks/usePackageData";
|
||||||
import { useTableState } from "hooks/useTableState";
|
import { useTableState } from "hooks/useTableState";
|
||||||
|
import type { AutoRefreshInterval } from "models/AutoRefreshInterval";
|
||||||
import type { BuildStatus } from "models/BuildStatus";
|
import type { BuildStatus } from "models/BuildStatus";
|
||||||
import type { PackageRow } from "models/PackageRow";
|
import type { PackageRow } from "models/PackageRow";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export interface UsePackageTableResult {
|
export interface UsePackageTableResult {
|
||||||
|
autoRefreshInterval: number;
|
||||||
columnVisibility: Record<string, boolean>;
|
columnVisibility: Record<string, boolean>;
|
||||||
dialogOpen: "dashboard" | "add" | "rebuild" | "keyImport" | null;
|
dialogOpen: "dashboard" | "add" | "rebuild" | "keyImport" | null;
|
||||||
filterModel: GridFilterModel;
|
filterModel: GridFilterModel;
|
||||||
@@ -34,6 +37,7 @@ export interface UsePackageTableResult {
|
|||||||
handleUpdate: () => Promise<void>;
|
handleUpdate: () => Promise<void>;
|
||||||
isAuthorized: boolean;
|
isAuthorized: boolean;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
onAutoRefreshIntervalChange: (interval: number) => void;
|
||||||
paginationModel: { page: number; pageSize: number };
|
paginationModel: { page: number; pageSize: number };
|
||||||
rows: PackageRow[];
|
rows: PackageRow[];
|
||||||
searchText: string;
|
searchText: string;
|
||||||
@@ -49,14 +53,23 @@ export interface UsePackageTableResult {
|
|||||||
status: BuildStatus | undefined;
|
status: BuildStatus | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePackageTable(): UsePackageTableResult {
|
export function usePackageTable(autoRefreshIntervals: AutoRefreshInterval[]): UsePackageTableResult {
|
||||||
const { rows, isLoading, isAuthorized, status } = usePackageData();
|
const { rows, isLoading, isAuthorized, status, autoRefresh } = usePackageData(autoRefreshIntervals);
|
||||||
const tableState = useTableState();
|
const tableState = useTableState();
|
||||||
const actions = usePackageActions(tableState.selectionModel, tableState.setSelectionModel);
|
const actions = usePackageActions(tableState.selectionModel, tableState.setSelectionModel);
|
||||||
|
|
||||||
|
// Pause auto-refresh when dialog is open
|
||||||
|
const isDialogOpen = tableState.dialogOpen !== null || tableState.selectedPackage !== null;
|
||||||
|
const setPaused = autoRefresh.setPaused;
|
||||||
|
useEffect(() => {
|
||||||
|
setPaused(isDialogOpen);
|
||||||
|
}, [isDialogOpen, setPaused]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
autoRefreshInterval: autoRefresh.interval,
|
||||||
isLoading,
|
isLoading,
|
||||||
isAuthorized,
|
isAuthorized,
|
||||||
|
onAutoRefreshIntervalChange: autoRefresh.setInterval,
|
||||||
rows,
|
rows,
|
||||||
status,
|
status,
|
||||||
...actions,
|
...actions,
|
||||||
|
|||||||
+4
-12
@@ -17,16 +17,8 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
export interface AutoRefreshInterval {
|
||||||
import { useEventStream } from "hooks/useEventStream";
|
interval: number;
|
||||||
import { useRepository } from "hooks/useRepository";
|
is_active: boolean;
|
||||||
import type { ReactNode } from "react";
|
text: string;
|
||||||
|
|
||||||
export function EventStreamProvider({ children }: { children: ReactNode }): ReactNode {
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const { currentRepository } = useRepository();
|
|
||||||
|
|
||||||
useEventStream(queryClient, currentRepository);
|
|
||||||
|
|
||||||
return children;
|
|
||||||
}
|
}
|
||||||
@@ -18,10 +18,12 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import type { AuthInfo } from "models/AuthInfo";
|
import type { AuthInfo } from "models/AuthInfo";
|
||||||
|
import type { AutoRefreshInterval } from "models/AutoRefreshInterval";
|
||||||
import type { RepositoryId } from "models/RepositoryId";
|
import type { RepositoryId } from "models/RepositoryId";
|
||||||
|
|
||||||
export interface InfoResponse {
|
export interface InfoResponse {
|
||||||
auth: AuthInfo;
|
auth: AuthInfo;
|
||||||
|
autorefresh_intervals: AutoRefreshInterval[];
|
||||||
docs_enabled: boolean;
|
docs_enabled: boolean;
|
||||||
index_url?: string;
|
index_url?: string;
|
||||||
repositories: RepositoryId[];
|
repositories: RepositoryId[];
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
import type { AutoRefreshInterval } from "models/AutoRefreshInterval";
|
||||||
|
|
||||||
export const DETAIL_TABLE_PROPS = {
|
export const DETAIL_TABLE_PROPS = {
|
||||||
density: "compact" as const,
|
density: "compact" as const,
|
||||||
disableColumnSorting: true,
|
disableColumnSorting: true,
|
||||||
@@ -25,6 +27,10 @@ export const DETAIL_TABLE_PROPS = {
|
|||||||
sx: { height: 400, mt: 1 },
|
sx: { height: 400, mt: 1 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function defaultInterval(intervals: AutoRefreshInterval[]): number {
|
||||||
|
return intervals.find(interval => interval.is_active)?.interval ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Array<T> {
|
interface Array<T> {
|
||||||
unique(): T[];
|
unique(): T[];
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ host = 127.0.0.1
|
|||||||
;index_url =
|
;index_url =
|
||||||
; Max file size in bytes which can be uploaded to the server. Requires ${web:enable_archive_upload} to be enabled.
|
; Max file size in bytes which can be uploaded to the server. Requires ${web:enable_archive_upload} to be enabled.
|
||||||
;max_body_size =
|
;max_body_size =
|
||||||
; Max event queue size used for server sent event endpoints (0 is infinite)
|
|
||||||
;max_queue_size = 0
|
|
||||||
; Port to listen. Must be set, if the web service is enabled.
|
; Port to listen. Must be set, if the web service is enabled.
|
||||||
;port =
|
;port =
|
||||||
; Disable status (e.g. package status, logs, etc) endpoints. Useful for build only modes.
|
; Disable status (e.g. package status, logs, etc) endpoints. Useful for build only modes.
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class Configuration(configparser.RawConfigParser):
|
|||||||
"""
|
"""
|
||||||
configparser.RawConfigParser.__init__(
|
configparser.RawConfigParser.__init__(
|
||||||
self,
|
self,
|
||||||
dict_type=ConfigurationMultiDict if allow_multi_key else dict,
|
dict_type=ConfigurationMultiDict if allow_multi_key else dict, # type: ignore[arg-type]
|
||||||
allow_no_value=allow_no_value,
|
allow_no_value=allow_no_value,
|
||||||
strict=False,
|
strict=False,
|
||||||
empty_lines_in_values=not allow_multi_key,
|
empty_lines_in_values=not allow_multi_key,
|
||||||
|
|||||||
@@ -150,6 +150,6 @@ class ShellTemplate(Template):
|
|||||||
break
|
break
|
||||||
|
|
||||||
kwargs.update(mapping)
|
kwargs.update(mapping)
|
||||||
kwargs.update(dict(generator(kwargs)))
|
substituted = dict(generator(kwargs))
|
||||||
|
|
||||||
return self.safe_substitute(kwargs)
|
return self.safe_substitute(kwargs | substituted)
|
||||||
|
|||||||
@@ -19,8 +19,7 @@
|
|||||||
#
|
#
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from asyncio import Lock, Queue, QueueFull, QueueShutDown
|
from asyncio import Lock, Queue, QueueFull
|
||||||
from dataclasses import dataclass
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from ahriman.core.log import LazyLogging
|
from ahriman.core.log import LazyLogging
|
||||||
@@ -30,22 +29,6 @@ from ahriman.models.event import EventType
|
|||||||
SSEvent = tuple[str, dict[str, Any]]
|
SSEvent = tuple[str, dict[str, Any]]
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class _Subscription:
|
|
||||||
"""
|
|
||||||
internal event bus subscription record
|
|
||||||
|
|
||||||
Attributes:
|
|
||||||
topics(list[EventType] | None): event type filter, ``None`` means all
|
|
||||||
object_id(str | None): object identifier filter, ``None`` means all
|
|
||||||
queue(Queue[SSEvent]): per-subscriber event queue
|
|
||||||
"""
|
|
||||||
|
|
||||||
topics: list[EventType] | None
|
|
||||||
object_id: str | None
|
|
||||||
queue: Queue[SSEvent]
|
|
||||||
|
|
||||||
|
|
||||||
class EventBus(LazyLogging):
|
class EventBus(LazyLogging):
|
||||||
"""
|
"""
|
||||||
event bus implementation
|
event bus implementation
|
||||||
@@ -62,7 +45,7 @@ class EventBus(LazyLogging):
|
|||||||
self.max_size = max_size
|
self.max_size = max_size
|
||||||
|
|
||||||
self._lock = Lock()
|
self._lock = Lock()
|
||||||
self._subscribers: dict[str, _Subscription] = {}
|
self._subscribers: dict[str, tuple[list[EventType] | None, Queue[SSEvent | None]]] = {}
|
||||||
|
|
||||||
async def broadcast(self, event_type: EventType, object_id: str | None, **kwargs: Any) -> None:
|
async def broadcast(self, event_type: EventType, object_id: str | None, **kwargs: Any) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -77,48 +60,42 @@ class EventBus(LazyLogging):
|
|||||||
event.update(kwargs)
|
event.update(kwargs)
|
||||||
|
|
||||||
async with self._lock:
|
async with self._lock:
|
||||||
snapshot = list(self._subscribers.items())
|
for subscriber_id, (topics, queue) in self._subscribers.items():
|
||||||
|
if topics is not None and event_type not in topics:
|
||||||
for subscriber_id, subscription in snapshot:
|
continue
|
||||||
if subscription.topics is not None and event_type not in subscription.topics:
|
try:
|
||||||
continue
|
queue.put_nowait((event_type, event))
|
||||||
if subscription.object_id is not None and object_id != subscription.object_id:
|
except QueueFull:
|
||||||
continue
|
self.logger.warning("discard message to slow subscriber %s", subscriber_id)
|
||||||
|
|
||||||
try:
|
|
||||||
subscription.queue.put_nowait((event_type, event))
|
|
||||||
except QueueFull:
|
|
||||||
self.logger.warning("discard message to slow subscriber %s", subscriber_id)
|
|
||||||
except QueueShutDown:
|
|
||||||
pass
|
|
||||||
|
|
||||||
async def shutdown(self) -> None:
|
async def shutdown(self) -> None:
|
||||||
"""
|
"""
|
||||||
gracefully shutdown all subscribers
|
gracefully shutdown all subscribers
|
||||||
"""
|
"""
|
||||||
async with self._lock:
|
async with self._lock:
|
||||||
for subscription in self._subscribers.values():
|
for _, queue in self._subscribers.values():
|
||||||
subscription.queue.shutdown()
|
try:
|
||||||
|
queue.put_nowait(None)
|
||||||
|
except QueueFull:
|
||||||
|
pass
|
||||||
|
queue.shutdown()
|
||||||
|
|
||||||
async def subscribe(self, topics: list[EventType] | None = None,
|
async def subscribe(self, topics: list[EventType] | None = None) -> tuple[str, Queue[SSEvent | None]]:
|
||||||
object_id: str | None = None) -> tuple[str, Queue[SSEvent]]:
|
|
||||||
"""
|
"""
|
||||||
register new subscriber
|
register new subscriber
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
topics(list[EventType] | None, optional): list of event types to filter by. If ``None`` is set,
|
topics(list[EventType] | None, optional): list of event types to filter by. If ``None`` is set,
|
||||||
all events will be delivered (Default value = None)
|
all events will be delivered (Default value = None)
|
||||||
object_id(str | None, optional): object identifier to filter by. If ``None`` is set,
|
|
||||||
events for all objects will be delivered (Default value = None)
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
tuple[str, Queue[SSEvent]]: subscriber identifier and associated queue
|
tuple[str, Queue[SSEvent | None]]: subscriber identifier and associated queue
|
||||||
"""
|
"""
|
||||||
subscriber_id = str(uuid.uuid4())
|
subscriber_id = str(uuid.uuid4())
|
||||||
queue: Queue[SSEvent] = Queue(self.max_size)
|
queue: Queue[SSEvent | None] = Queue(self.max_size)
|
||||||
|
|
||||||
async with self._lock:
|
async with self._lock:
|
||||||
self._subscribers[subscriber_id] = _Subscription(topics=topics, object_id=object_id, queue=queue)
|
self._subscribers[subscriber_id] = (topics, queue)
|
||||||
|
|
||||||
return subscriber_id, queue
|
return subscriber_id, queue
|
||||||
|
|
||||||
@@ -130,6 +107,7 @@ class EventBus(LazyLogging):
|
|||||||
subscriber_id(str): subscriber unique identifier
|
subscriber_id(str): subscriber unique identifier
|
||||||
"""
|
"""
|
||||||
async with self._lock:
|
async with self._lock:
|
||||||
subscription = self._subscribers.pop(subscriber_id, None)
|
result = self._subscribers.pop(subscriber_id, None)
|
||||||
if subscription is not None:
|
if result is not None:
|
||||||
subscription.queue.shutdown()
|
_, queue = result
|
||||||
|
queue.shutdown()
|
||||||
|
|||||||
@@ -31,7 +31,3 @@ class EventBusFilterSchema(RepositoryIdSchema):
|
|||||||
"description": "Event type filter",
|
"description": "Event type filter",
|
||||||
"example": [EventType.PackageUpdated],
|
"example": [EventType.PackageUpdated],
|
||||||
})
|
})
|
||||||
object_id = fields.String(metadata={
|
|
||||||
"description": "Object identifier filter",
|
|
||||||
"example": "ahriman",
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -209,8 +209,8 @@ class BaseView(View, CorsViewMixin):
|
|||||||
HTTPBadRequest: if supplied parameters are invalid
|
HTTPBadRequest: if supplied parameters are invalid
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
limit = int(self.request.query.get("limit", -1))
|
limit = int(self.request.query.get("limit", default=-1))
|
||||||
offset = int(self.request.query.get("offset", 0))
|
offset = int(self.request.query.get("offset", default=0))
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
raise HTTPBadRequest(reason=str(ex))
|
raise HTTPBadRequest(reason=str(ex))
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#
|
#
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from aiohttp.web import HTTPBadRequest, StreamResponse
|
from aiohttp.web import StreamResponse
|
||||||
from aiohttp_sse import EventSourceResponse, sse_response
|
from aiohttp_sse import EventSourceResponse, sse_response
|
||||||
from asyncio import Queue, QueueShutDown, wait_for
|
from asyncio import Queue, QueueShutDown, wait_for
|
||||||
from typing import ClassVar
|
from typing import ClassVar
|
||||||
@@ -44,21 +44,23 @@ class EventBusView(BaseView):
|
|||||||
ROUTES = ["/api/v1/events/stream"]
|
ROUTES = ["/api/v1/events/stream"]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def _run(response: EventSourceResponse, queue: Queue[SSEvent]) -> None:
|
async def _run(response: EventSourceResponse, queue: Queue[SSEvent | None]) -> None:
|
||||||
"""
|
"""
|
||||||
read events from queue and send them to the client
|
read events from queue and send them to the client
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
response(EventSourceResponse): SSE response instance
|
response(EventSourceResponse): SSE response instance
|
||||||
queue(Queue[SSEvent]): subscriber queue
|
queue(Queue[SSEvent | None]): subscriber queue
|
||||||
"""
|
"""
|
||||||
while response.is_connected():
|
while response.is_connected():
|
||||||
try:
|
try:
|
||||||
event_type, data = await wait_for(queue.get(), timeout=response.ping_interval)
|
message = await wait_for(queue.get(), timeout=response.ping_interval)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
continue
|
continue
|
||||||
except QueueShutDown:
|
|
||||||
break
|
if message is None:
|
||||||
|
break # terminate queue on sentinel event
|
||||||
|
event_type, data = message
|
||||||
|
|
||||||
await response.send(json.dumps(data), event=event_type)
|
await response.send(json.dumps(data), event=event_type)
|
||||||
|
|
||||||
@@ -67,7 +69,6 @@ class EventBusView(BaseView):
|
|||||||
summary="Live updates",
|
summary="Live updates",
|
||||||
description="Stream live updates via SSE",
|
description="Stream live updates via SSE",
|
||||||
permission=GET_PERMISSION,
|
permission=GET_PERMISSION,
|
||||||
error_400_enabled=True,
|
|
||||||
error_404_description="Repository is unknown",
|
error_404_description="Repository is unknown",
|
||||||
schema=SSESchema(many=True),
|
schema=SSESchema(many=True),
|
||||||
query_schema=EventBusFilterSchema,
|
query_schema=EventBusFilterSchema,
|
||||||
@@ -78,19 +79,12 @@ class EventBusView(BaseView):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
StreamResponse: 200 with streaming updates
|
StreamResponse: 200 with streaming updates
|
||||||
|
|
||||||
Raises:
|
|
||||||
HTTPBadRequest: if invalid event type is supplied
|
|
||||||
"""
|
"""
|
||||||
try:
|
topics = [EventType(event) for event in self.request.query.getall("event", [])] or None
|
||||||
topics = [EventType(event) for event in self.request.query.getall("event", [])] or None
|
|
||||||
except ValueError as ex:
|
|
||||||
raise HTTPBadRequest(reason=str(ex))
|
|
||||||
object_id = self.request.query.get("object_id")
|
|
||||||
event_bus = self.service().event_bus
|
event_bus = self.service().event_bus
|
||||||
|
|
||||||
async with sse_response(self.request) as response:
|
async with sse_response(self.request) as response:
|
||||||
subscription_id, queue = await event_bus.subscribe(topics, object_id=object_id)
|
subscription_id, queue = await event_bus.subscribe(topics)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self._run(response, queue)
|
await self._run(response, queue)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ def event_bus() -> EventBus:
|
|||||||
fixture for event bus
|
fixture for event bus
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
EventBus: event bus test instance
|
EventBus: even bus test instance
|
||||||
"""
|
"""
|
||||||
return EventBus(0)
|
return EventBus(0)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from asyncio import QueueShutDown
|
|
||||||
|
|
||||||
from ahriman.core.status.event_bus import EventBus
|
from ahriman.core.status.event_bus import EventBus
|
||||||
from ahriman.models.event import EventType
|
from ahriman.models.event import EventType
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
@@ -51,25 +49,15 @@ async def test_broadcast_queue_full(event_bus: EventBus, package_ahriman: Packag
|
|||||||
assert queue.qsize() == 1
|
assert queue.qsize() == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_broadcast_queue_shutdown(event_bus: EventBus, package_ahriman: Package) -> None:
|
|
||||||
"""
|
|
||||||
must skip subscriber whose queue was shutdown concurrently
|
|
||||||
"""
|
|
||||||
_, queue = await event_bus.subscribe()
|
|
||||||
queue.shutdown()
|
|
||||||
|
|
||||||
await event_bus.broadcast(EventType.PackageUpdated, package_ahriman.base)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_shutdown(event_bus: EventBus) -> None:
|
async def test_shutdown(event_bus: EventBus) -> None:
|
||||||
"""
|
"""
|
||||||
must shutdown all subscriber queues on shutdown
|
must send sentinel to all subscribers on shutdown
|
||||||
"""
|
"""
|
||||||
_, queue = await event_bus.subscribe()
|
_, queue = await event_bus.subscribe()
|
||||||
|
|
||||||
await event_bus.shutdown()
|
await event_bus.shutdown()
|
||||||
with pytest.raises(QueueShutDown):
|
message = queue.get_nowait()
|
||||||
queue.get_nowait()
|
assert message is None
|
||||||
|
|
||||||
|
|
||||||
async def test_shutdown_queue_full(event_bus: EventBus, package_ahriman: Package) -> None:
|
async def test_shutdown_queue_full(event_bus: EventBus, package_ahriman: Package) -> None:
|
||||||
@@ -94,38 +82,13 @@ async def test_subscribe(event_bus: EventBus) -> None:
|
|||||||
assert subscriber_id in event_bus._subscribers
|
assert subscriber_id in event_bus._subscribers
|
||||||
|
|
||||||
|
|
||||||
async def test_broadcast_with_object_id(event_bus: EventBus, package_ahriman: Package) -> None:
|
|
||||||
"""
|
|
||||||
must broadcast event to subscribers with matching object_id
|
|
||||||
"""
|
|
||||||
_, queue = await event_bus.subscribe(object_id=package_ahriman.base)
|
|
||||||
await event_bus.broadcast(EventType.PackageUpdated, package_ahriman.base)
|
|
||||||
assert not queue.empty()
|
|
||||||
|
|
||||||
|
|
||||||
async def test_broadcast_object_id_isolation(event_bus: EventBus, package_ahriman: Package) -> None:
|
|
||||||
"""
|
|
||||||
must not broadcast event to subscribers with non-matching object_id
|
|
||||||
"""
|
|
||||||
_, queue = await event_bus.subscribe(object_id="other-package")
|
|
||||||
await event_bus.broadcast(EventType.PackageUpdated, package_ahriman.base)
|
|
||||||
assert queue.empty()
|
|
||||||
|
|
||||||
|
|
||||||
async def test_subscribe_with_topics(event_bus: EventBus) -> None:
|
async def test_subscribe_with_topics(event_bus: EventBus) -> None:
|
||||||
"""
|
"""
|
||||||
must register subscriber with topic filter
|
must register subscriber with topic filter
|
||||||
"""
|
"""
|
||||||
subscriber_id, _ = await event_bus.subscribe([EventType.BuildLog])
|
subscriber_id, _ = await event_bus.subscribe([EventType.BuildLog])
|
||||||
assert event_bus._subscribers[subscriber_id].topics == [EventType.BuildLog]
|
topics, _ = event_bus._subscribers[subscriber_id]
|
||||||
|
assert topics == [EventType.BuildLog]
|
||||||
|
|
||||||
async def test_subscribe_with_object_id(event_bus: EventBus, package_ahriman: Package) -> None:
|
|
||||||
"""
|
|
||||||
must register subscriber with object_id filter
|
|
||||||
"""
|
|
||||||
subscriber_id, _ = await event_bus.subscribe(object_id=package_ahriman.base)
|
|
||||||
assert event_bus._subscribers[subscriber_id].object_id == package_ahriman.base
|
|
||||||
|
|
||||||
|
|
||||||
async def test_unsubscribe(event_bus: EventBus) -> None:
|
async def test_unsubscribe(event_bus: EventBus) -> None:
|
||||||
|
|||||||
@@ -33,9 +33,8 @@ async def test_get_permission() -> None:
|
|||||||
"""
|
"""
|
||||||
must return correct permission for the request
|
must return correct permission for the request
|
||||||
"""
|
"""
|
||||||
for method in ("GET",):
|
request = pytest.helpers.request("", "", "GET")
|
||||||
request = pytest.helpers.request("", "", method)
|
assert await EventBusView.get_permission(request) == UserAccess.Full
|
||||||
assert await EventBusView.get_permission(request) == UserAccess.Full
|
|
||||||
|
|
||||||
|
|
||||||
def test_routes() -> None:
|
def test_routes() -> None:
|
||||||
@@ -53,7 +52,7 @@ async def test_run_timeout() -> None:
|
|||||||
|
|
||||||
async def _shutdown() -> None:
|
async def _shutdown() -> None:
|
||||||
await asyncio.sleep(0.05)
|
await asyncio.sleep(0.05)
|
||||||
queue.shutdown()
|
await queue.put(None)
|
||||||
|
|
||||||
response = AsyncMock()
|
response = AsyncMock()
|
||||||
response.is_connected = lambda: True
|
response.is_connected = lambda: True
|
||||||
@@ -99,34 +98,6 @@ async def test_get_with_topic_filter(client: TestClient, package_ahriman: Packag
|
|||||||
assert EventType.PackageRemoved not in body
|
assert EventType.PackageRemoved not in body
|
||||||
|
|
||||||
|
|
||||||
async def test_get_with_object_id_filter(client: TestClient, package_ahriman: Package) -> None:
|
|
||||||
"""
|
|
||||||
must filter events by object_id
|
|
||||||
"""
|
|
||||||
watcher = next(iter(client.app[WatcherKey].values()))
|
|
||||||
asyncio.create_task(_producer(watcher, package_ahriman))
|
|
||||||
request_schema = pytest.helpers.schema_request(EventBusView.get, location="querystring")
|
|
||||||
|
|
||||||
payload = {"object_id": "non-existent-package"}
|
|
||||||
assert not request_schema.validate(payload)
|
|
||||||
response = await client.get("/api/v1/events/stream", params=payload)
|
|
||||||
assert response.status == 200
|
|
||||||
|
|
||||||
body = await response.text()
|
|
||||||
assert "ahriman" not in body
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get_bad_request(client: TestClient) -> None:
|
|
||||||
"""
|
|
||||||
must return bad request for invalid event type
|
|
||||||
"""
|
|
||||||
response_schema = pytest.helpers.schema_response(EventBusView.get, code=400)
|
|
||||||
|
|
||||||
response = await client.get("/api/v1/events/stream", params={"event": "invalid"})
|
|
||||||
assert response.status == 400
|
|
||||||
assert not response_schema.validate(await response.json())
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get_not_found(client: TestClient) -> None:
|
async def test_get_not_found(client: TestClient) -> None:
|
||||||
"""
|
"""
|
||||||
must return not found for unknown repository
|
must return not found for unknown repository
|
||||||
@@ -143,5 +114,6 @@ async def test_get_connection_reset(client: TestClient, mocker: MockerFixture) -
|
|||||||
must handle connection reset
|
must handle connection reset
|
||||||
"""
|
"""
|
||||||
mocker.patch.object(EventBusView, "_run", side_effect=ConnectionResetError)
|
mocker.patch.object(EventBusView, "_run", side_effect=ConnectionResetError)
|
||||||
|
|
||||||
response = await client.get("/api/v1/events/stream")
|
response = await client.get("/api/v1/events/stream")
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
|
|||||||
Reference in New Issue
Block a user