Slack API:延迟响应,如何抑制超时到达错误?

时间:2018-08-14 02:27:18

标签: slack slack-api serverless-framework openfaas

我的懈怠命令出现Timeout was reached错误,因为它无法在3秒的超时时间内完成整个过程。

我正在使用Openfaas(类似于amazon lambda),并且我尝试了以下信息: avoid timeout error,但仍然无法避免错误,这是我的代码:

def send(response_url, channel_id, graph_details):
    sc = SlackClient(grafana_bot_token)
    payload = {"text":"Serverless App status"}
    r = requests.post(response_url,data=json.dumps(payload), headers={'Content-Type': 'application/json'})
    sc.api_call("chat.postMessage", channel=channel_id, text='Image Preview', as_user=False, unfurl_links=True, unfurl_media=True, attachments=attachments)
    # either request.post or chat.postMsg works fine!

def backgroundworker(req):
    print(json.dumps({'text': 'ok'}))          
    send(response_url=response_url, channel_id=channel_id, graph_details=[graph,collection,sub])

#entry point for serverless functions
def handle(req):
    thread = Thread(target=backgroundworker, args=[req])
    thread.start()
    return json.dumps({'text': 'ok'})

我不确定如何首先返回200 OK响应并继续在后台运行所有其余任务-backgroundworkers()的第一行将在slack命令中打印,并且我无法执行return json.dumps({'text': 'ok'})导致整个功能刚刚结束。

真的很感谢您的帮助!

0 个答案:

没有答案