JobLog API

概述

JobLog API是用于查看和管理 Fess 作业执行日志的API。 可以获取和删除调度作业及爬虫作业的执行历史、执行结果和错误信息等。

基础URL

/api/admin/joblog

端点列表

方法 路径 说明
GET /logs 获取作业日志列表
GET /log/{id} 获取作业日志
DELETE /log/{id} 删除作业日志

获取作业日志列表

请求

GET /api/admin/joblog/logs

参数

参数 类型 必需 说明
size Integer 否 每页记录数(默认:25。可通过 fess_config.properties 中的 paging.page.size 更改)
page Integer 否 页码(从1开始,默认: 1)
id String 否 按作业日志ID过滤(完全匹配)

这些参数通过 JSON 请求体指定(例如 {"size": 50, "page": 1})。通过 URL 查询字符串指定的值(例如 ?size=50)会被忽略,因此未在请求体中指定时,始终返回前 25 条。

响应

{
  "response": {
    "status": 0,
    "logs": [
      {
        "id": "joblog_id_1",
        "job_name": "Default Crawler",
        "job_status": "ok",
        "target": "all",
        "script_type": "javascript",
        "script_data": "return container.getComponent(\"crawlJob\").execute();",
        "script_result": "Job completed successfully",
        "start_time": "1738116000000",
        "end_time": "1738118723000"
      },
      {
        "id": "joblog_id_2",
        "job_name": "Default Crawler",
        "job_status": "fail",
        "target": "all",
        "script_type": "javascript",
        "script_data": "return container.getComponent(\"crawlJob\").execute();",
        "script_result": "Error: Connection timeout",
        "start_time": "1738029600000",
        "end_time": "1738030215000"
      }
    ],
    "total": 100
  }
}

响应字段

字段 说明
id 作业日志ID
job_name 作业名称
job_status 作业状态(ok: 成功、fail: 失败、running: 执行中)
target 执行目标(调度器的目标名称,默认值为 all)
script_type 脚本类型(例: javascript)
script_data 执行脚本
script_result 执行结果
start_time 开始时刻(epoch毫秒;以字符串形式返回)
end_time 结束时刻(epoch毫秒;以字符串形式返回)。执行中的作业不返回此字段。

Note

响应中每个日志对象还包含一个内部字段 crud_mode (表示CRUD操作模式的整数值,在读取操作时始终为 0)。 客户端可安全忽略此字段。

获取作业日志

请求

GET /api/admin/joblog/log/{id}

响应

{
  "response": {
    "status": 0,
    "log": {
      "id": "joblog_id_1",
      "job_name": "Default Crawler",
      "job_status": "ok",
      "target": "all",
      "script_type": "javascript",
      "script_data": "return container.getComponent(\"crawlJob\").execute();",
      "script_result": "Crawl completed successfully.\nDocuments indexed: 1234\nDocuments updated: 567\nDocuments deleted: 12\nErrors: 0",
      "start_time": "1738116000000",
      "end_time": "1738118723000"
    }
  }
}

若指定ID的作业日志不存在,则返回 status 为非0值的错误响应。

删除作业日志

请求

DELETE /api/admin/joblog/log/{id}

响应

{
  "response": {
    "status": 0
  }
}

若指定ID的作业日志不存在,则返回 status 为非0值的错误响应。

使用示例

获取作业日志列表

curl -X GET "http://localhost:8080/api/admin/joblog/logs" \
     -H "Authorization: Bearer YOUR_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"size": 50, "page": 1}'

仅提取失败的作业

# 用jq过滤失败的作业
curl -X GET "http://localhost:8080/api/admin/joblog/logs" \
     -H "Authorization: Bearer YOUR_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"size": 1000}' | \
     jq '.response.logs[] | select(.job_status=="fail")'

获取作业日志

curl -X GET "http://localhost:8080/api/admin/joblog/log/joblog_id_1" \
     -H "Authorization: Bearer YOUR_TOKEN"

删除作业日志

curl -X DELETE "http://localhost:8080/api/admin/joblog/log/joblog_id_1" \
     -H "Authorization: Bearer YOUR_TOKEN"

计算作业成功率

curl -X GET "http://localhost:8080/api/admin/joblog/logs" \
     -H "Authorization: Bearer YOUR_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"size": 1000}' | \
     jq '.response.logs | {total: length, ok: [.[] | select(.job_status=="ok")] | length, fail: [.[] | select(.job_status=="fail")] | length}'

参考信息