0

我正在尝试使用下面的脚本获取简单的计费信息。脚本因超时错误而失败。有人可以帮我解决问题吗?

require 'rubygems'
require 'softlayer_api'
require 'pp'

billing = SoftLayer::Service.new("SoftLayer_Account",:username => "USER", :api_key => "KEY", :timeout => 99999)
object_mask = "mask[orderItem[order[userRecord[username]]], invoiceItem[totalRecurringAmount]]"
user_bill= billing.object_mask(object_mask).getNextInvoiceTopLevelBillingItems

pp user_bill
4

2 回答 2

1

如果 API 对其他调用正常响应,这很可能是由请求的数据量引起的。当请求的信息超出其处理能力时,SLAPI 通常会超时。

您可以通过使用结果限制或仅指定所需的特定属性来避免这种情况。

默认情况下,当您引用关系属性时,会返回整个本地属性集。即使通过一个属性到另一个属性。上面的调用将返回整套计费项目及其相关的本地属性、订单的所有本地属性(对于每个订单项目都被冗余地拉入),以及带有 totalRecurringAmount 的整个发票项目。

通过id在每个级别指定,您可以减少返回的数据量:

mask[
  orderItem[
    id,
    order[
      id,
      userRecord[username]
    ]
  ], 
  invoiceItem[
    id,
    totalRecurringAmount
  ]
]

但是,在某些数量的设备/产品上,调用将再次开始变得过载,并且有必要对结果进行分页并批量处理它们。

http://sldn.softlayer.com/blog/phil/How-Solve-Error-fetching-http-headers

于 2015-12-07T23:46:35.240 回答
0

可能您的帐户有许多计费项目并导致异常,请查看以下文章:

http://sldn.softlayer.com/blog/phil/How-Solve-Error-fetching-http-headers

我可以推荐使用 resultLimits,为了避免异常,看看下面的 Ruby 脚本:

# Get Next Invoice Top Level Billing Items
#
# This script retrieves the billing items that will be on an account's next invoice
#
# Important manual pages:
# http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNextInvoiceTopLevelBillingItems
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Billing_Item
#
# @license <http://sldn.softlayer.com/article/License>
# @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
require 'rubygems' 
require 'softlayer_api' 
require 'pp'

# Helper function to fetch through all results from SoftLayer api
# using small page sizes and sleeping before every new page fetch.
def fetch_all(service, method)
  records = []; offset = 0; limit = 1000
  loop do
    results = service.result_limit(offset, limit).send(method)
    records += results
    break if results.size < limit
    offset += limit
    sleep 3
  end
  records
end

# Creating the account service.
billing = SoftLayer::Service.new("SoftLayer_Account", :username => "set me", :api_key => "set me", :timeout => 200)
# object mask 
object_mask = "mask[orderItem[order[userRecord[username]]], invoiceItem[totalRecurringAmount]]"
begin
  # Calling helper function to get all the result for getNextInvoiceTopLevelBillingItems method
  user_bill = fetch_all(billing.object_mask(object_mask), :getNextInvoiceTopLevelBillingItems) 
  # Print
  pp user_bill
  rescue StandardError => exception
    puts "Error: #{exception}"
end

我希望它有帮助

于 2015-12-08T00:17:21.270 回答