ruby - 在 ArchivesSpace 中编写简单的插件
问题描述
我正在以归档空间插件的形式为我们的归档空间实例编写一个健康检查插件。它是一个 Jruby 应用程序,插件的说明类似于 Ruby on Rails。在 rails 应用程序上似乎很简单但是当我按照插件文档但它仍然无法正常工作时,有人能指出我正确的方向吗,我基本上只需要存档空间 Url :/plugins/healthcheck/ 来点击存档空间接口 url,如果它响应 200 响应,则让页面在 html 中指示成功消息。以下是代码片段,感谢任何帮助!
-plugins
-healthcheck
-backend
-healthcheck. rb
-frontend
-controller
- healthcheck_controller.rb
健康检查.rb
class ArchivesSpaceService < Sinatra::Base
Endpoint.get('/healthcheck')
.returns([200, "{'reply', 'status:ok'}"]) \
end
healthcheck_controller.rb
require 'net/http'
require 'socket'
class ApplicationController < ActionController::Base
def healthcheck
hostname = "status of server " + Socket.gethostname
uri = 'http://example.com/index.html'
status_message = "System OK"
datetime = Time.now
begin
res = Net::HTTP.get_response(URI(uri))
status_code = res.code.to_i
if status_code > 399
status_code = 424
status_message = "One or more services are currently impacted"
img = "/img/fail.png"
else
img = "/img/pass.png"
end
render text: "<h>#{hostname} #{status_code} </h>ArchivesSpace Ok?:<br><img src='#{img}'> #{uri}<br><br>status:ok<br>" , status: status_code
end
end
end
解决方案
推荐阅读
- php - 有没有办法根据一定数量生成一定数量的 Woocommerce 优惠券?
- arrays - 有没有办法在没有 usinf for 循环的情况下取消嵌套和取消列出 MongoDb 查询内联?
- bootstrap-select - 如何在 Bootstrap-Select 中禁用/启用 Select?
- swift - 如何在 NSCellTextView Swift 5 中不截断文本
- node.js - 如何从 nodejs 中运行和启动 mongodb
- xamarin - Xamarin Forms 未在 Android 中显示警报但在 ios 中工作正常
- rust - 哪些 Rust 1.2 容器支持 trait 对象?
- scala - 如何只创建一次常量
- javascript - 如何在出现提示之前隐藏 div
- android - 为简单项目创建 APK 的 FlashDevelop 错误