Skip To Content

更新实时流量数据

从配置了实时流量的网络数据集发布路径服务后,必须确保这些服务所使用的实时流量数据定期更新。 这可以通过遵循下面概述的工作流来实现:

您需要使用 crontab 配置 Python 脚本,使其每两分钟运行一次。 此内置命令行实用程序允许用户计划任务以指定的时间间隔自动运行。 配置为通过 crontab 运行的 Python 脚本需要以下先决条件:

  • 您应该为指定为 ArcGIS Server 账户的操作系统用户配置 crontab
  • Python 脚本需要 Python 3.9 版本或更高版本。 使用 ArcGIS Server 中未包含的 Python 版本非常重要;相反,您应该使用操作系统上原生提供的 Python 版本。
  • Python 环境应安装 requests 模块。

通过 crontab 运行 Python 脚本,每两分钟更新一次实时流量数据。 示例假设 ArcGIS Server 安装位置为 /arcgis/server

(crontab -l; echo "*/2 * * * * /usr/bin/python3 /arcgis/server/framework/runtime/ArcGIS/Resources/ArcToolBox/Services/routingservices/update_traffic_cache_scheduler.py >/dev/null 2>&1") | crontab -
注:

必须在多机 ArcGIS Server 站点中的每台计算机上执行上述步骤。

Python 脚本生成一个名为 update_traffic_cache_scheduler.log 的日志文件,该文件存储在 ArcGIS Server 写入其日志的默认文件夹中,如 <ArcGIS Server installation directory>/arcgis/server/usr/logs 您可以检查此日志文件来确定脚本执行过程中是否发生任何错误。

检查实时流量数据状态

设置实时流量数据定期更新后,您可以通过运行 NetworkAnalysisUtilities 地理处理服务中的 GetLiveTrafficStatus 工具来验证流量数据是否更新成功。 此服务位于发布其他路径服务的同一文件夹中。 例如,如果路径服务发布到名为 Routing 的服务文件夹,则 GetLiveTrafficStatus 工具的 URL 将为 https://machine.example.com/webadaptorname/rest/services/Routing/NetworkAnalysisUtilities/GPServer/GetLiveTrafficStatusGetLiveTrafficStatus 的输出可用于检查流量数据是否成功更新。

GetLiveTrafficStatus 工具的示例输出显示,由于 isLastUpdateSuccessfultrue,因此上次更新成功。 如果上次更新期间出现错误,则 isLastUpdateSuccessful 设置为 false,并且失败的原因将作为 lastUpdatedMessages 属性的一部分返回。

{
 "results": [
  {
   "paramName": "status",
   "dataType": "GPString",
   "value": {
    "cachePath":  "C:\\NA\\RoutingServices\\traffic-cache\\openlr.3a795f46cf77473fb1dc606ef73a2cb5",
     "isLastUpdateSuccessful":  true,
     "isUpdateInProgress":  false,
     "roadClosuresDataAvailable":  true,
     "roadClosuresDataSize":  64427318,
     "speedDataAvailable":  true,
     "speedsDataSize":  3977019303,
     "tempDataSize":  365970076,
     "trafficCacheStatus":  {
     "endTimeWindow":  1744065360000,
      "lastCreatedFileNames":  [
      "speeds.20250407132800.1.ff.dat",
       "speeds.20250407213200.1.nff.dat",
       "road_closures.20250407213200.1.dat",
       "speeds.20250407213200.info.dat",
       "speeds.20250407213600.info.dat"
     ],
      "lastDecodingElapsedTime":  0,
      "lastRemovedFileNames":  [
      "speeds.20250407173200.info.dat",
       "road_closures.20250407173200.1.dat"
     ],
      "lastUpdatedElapsedTime":  11582,
      "lastUpdatedMessages":  [
      
     ],
      "lastUpdatedTime":  1744062137882,
      "remainingSpeedLocationsToMatch":  0,
      "roadClosureLocationsCount":  23153,
      "selectedTrafficDataRegions":  [
      "CAN",
       "MEX",
       "USA_N",
       "USA_SW",
       "USA_SE",
       "USA_M"
     ],
      "speedLocationsCount":  1468719,
      "startTimeWindow":  1744047330000
    }
   }
  }
 ],
 "messages": [
  
 ]
}