mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-31 22:59:55 +00:00
add watcher cache support
This commit is contained in:
@ -33,7 +33,7 @@ class AhrimanView(BaseView):
|
||||
get current service status
|
||||
:return: 200 with service status object
|
||||
'''
|
||||
return json_response(AhrimanView.status_view(self.service.status))
|
||||
return json_response(self.service.status.view())
|
||||
|
||||
async def post(self) -> Response:
|
||||
'''
|
||||
|
@ -17,14 +17,9 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from dataclasses import asdict
|
||||
from typing import Any, Dict
|
||||
|
||||
from aiohttp.web import View
|
||||
|
||||
from ahriman.core.watcher.watcher import Watcher
|
||||
from ahriman.models.build_status import BuildStatus
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
class BaseView(View):
|
||||
@ -39,28 +34,3 @@ class BaseView(View):
|
||||
'''
|
||||
watcher: Watcher = self.request.app['watcher']
|
||||
return watcher
|
||||
|
||||
@staticmethod
|
||||
def package_view(package: Package, status: BuildStatus) -> Dict[str, Any]:
|
||||
'''
|
||||
generate json package view
|
||||
:param package: package definitions
|
||||
:param status: package build status
|
||||
:return: json-friendly dictionary
|
||||
'''
|
||||
return {
|
||||
'status': BaseView.status_view(status),
|
||||
'package': asdict(package)
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def status_view(status: BuildStatus) -> Dict[str, Any]:
|
||||
'''
|
||||
generate json status view
|
||||
:param status: build status
|
||||
:return: json-friendly dictionary
|
||||
'''
|
||||
return {
|
||||
'status': status.status.value,
|
||||
'timestamp': status.timestamp
|
||||
}
|
||||
|
@ -41,7 +41,10 @@ class PackageView(BaseView):
|
||||
except KeyError:
|
||||
raise HTTPNotFound()
|
||||
|
||||
response = PackageView.package_view(package, status)
|
||||
response = {
|
||||
'package': package.view(),
|
||||
'status': status.view()
|
||||
}
|
||||
return json_response(response)
|
||||
|
||||
async def delete(self) -> Response:
|
||||
@ -71,7 +74,7 @@ class PackageView(BaseView):
|
||||
data = await self.request.json()
|
||||
|
||||
try:
|
||||
package = Package(**data['package']) if 'package' in data else None
|
||||
package = Package.from_json(data['package']) if 'package' in data else None
|
||||
status = BuildStatusEnum(data['status'])
|
||||
except Exception as e:
|
||||
raise HTTPBadRequest(text=str(e))
|
||||
|
@ -33,8 +33,10 @@ class PackagesView(BaseView):
|
||||
:return: 200 with package description on success
|
||||
'''
|
||||
response = [
|
||||
PackagesView.package_view(package, status)
|
||||
for package, status in self.service.packages
|
||||
{
|
||||
'package': package.view(),
|
||||
'status': status.view()
|
||||
} for package, status in self.service.packages
|
||||
]
|
||||
return json_response(response)
|
||||
|
||||
|
Reference in New Issue
Block a user