使用Zapier,我从客户端发送了一个JSON对象,其中包含以下数据:
fields = {
“data":[
{
"duration":4231,
“description”:”text text text "
},
{
"duration":283671,
“description”:”text text text "
},
{
"duration":233671,
“description”:”text text text "
},
{
"duration":293671,
“description”:”text text text "
}
]
}
当我发送一个类似这样的JSON对象时,它可能会接收一个包含100+个元素的数组。在服务器端,我需要它接收这些数据并遍历对象数组,并将计时器设置为与“duration”属性具有相同的持续时间。我有一个Python示例脚本来说明我的意思。你知道吗
Server Side:
import requests
import json
import time
class Person(object):
def __init__(self, url=None, duration=None):
self.url = url
self.duration = duration
string = input['data2']
output = [{'id': 123, 'hello': 'world'}]
print(input['data2'])
print(len(string))
holder = string.splitlines()
print(holder)
tempd = ""
insert = 0
for x in holder:
if len(x) > 0:
if(x.find("duration") != -1):
tempA = x.split(":")#its techincally reading the property as a string so its whatever I split it and get the number out
timer = (float(tempA[1])/1000)#converting the miliseconds to seconds
print(timer)
print "Start : %s" % time.ctime()
#time.sleep(timer)#based on the duration determines how long my timer will sleep for
print "End : %s" % time.ctime()
当我执行这个脚本时,我会遇到超时问题,但是我需要服务器做的只是发送一个响应,表明它已经收到请求,并且正在使用所需的JSON对象执行脚本?我需要一整天都这样,我只是说,这个数组可以包含100个元素,每个元素之间至少有2分钟的延迟。Heroku会支持这种需求还是我应该在Azure上构建一个服务器?你知道吗
Heroku终止请求after 30 seconds。但是您可以运行后台任务来更新数据存储,然后在页面加载时检查数据存储。 下面是一个使用threading、dataset和sqlite进行本地测试的最小示例。在heroku上,您必须用类似于postgres服务的云数据存储来替换sqlite引用。直接向上SQLAlchemy通常比数据集更受欢迎。你知道吗
访问127.0.0.1:5000/tom,当
thread
运行时,您会得到:在
thread
完成后重新加载,您会看到:相关问题 更多 >
编程相关推荐