我有一个webhook,它将消息发布到Slack通道.有没有办法确保消息中提到的时间显示在用户的本地时区?
我有一个函数,它为令牌发出HTTP请求,该请求将在未来的请求中使用.此令牌在未指定的时间内有效,可能需要几个小时左右.
(defn request-app-token
"Request an app token from FB. Useful for app-global actions, such as creating test users."
[client-credentials]
(-> {"client_id" (:client-id client-credentials)
"client_secret" (:client-secret client-credentials)
"grant_type" "client_credentials"}
(form-encode)
((partial str fb-graph-api "/oauth/access_token?"))
(client/get {:throw-entire-message? true})
:body
(json/read-str)
(get "access_token")))
Run Code Online (Sandbox Code Playgroud)
对我而言,这看起来像是memoize的工作:保留令牌的副本并重复使用它,而不是每次需要时都请求新的令牌.
(def get-app-token (memoize request-app-token)) ; So beautiful :D
Run Code Online (Sandbox Code Playgroud)
我只需要处理令牌过期的情况.为此,我将反转控制; 获取需要令牌的函数,尝试使用memoized令牌运行它,如果失败,则使用新令牌再次尝试.
(defn with-app-token [client-credentials f]
(try (f (get-app-token client-credentials))
(catch Exception e ; I know I should be more specific here, I only want to catch HTTP 400 responses
(f …Run Code Online (Sandbox Code Playgroud) 我只是尝试创建或替换文档,但是API文档尚不清楚如何执行此操作。
所述UPSERT示例示出了一个文件都与创建counter的值1:
client.update({
index: 'myindex',
type: 'mytype',
id: '777',
body: {
script: 'ctx._source.counter += 1',
upsert: {
counter: 1
}
}
}, function(error, response) {
// ...
})
Run Code Online (Sandbox Code Playgroud)
我不需要增量脚本,因此我尝试自己发送一个upsert,但是得到400 Validation Failed: 1: script or doc is missing:
client.update({
index: "testindex",
type: "testType",
id: 1234,
body: {
upsert: {
itworks: true,
ok: "oh yeah"
}
}
})
Run Code Online (Sandbox Code Playgroud)
好吧,让我们尝试一些愚蠢的事情,并将文档添加两次;在之下doc,可能会替换现有文档(如果有的话);在之下upsert,则会用于创建新文档,否则:
client.update({
index: "testindex",
type: "testType",
id: 1234,
body: {
upsert: {
itworks: …Run Code Online (Sandbox Code Playgroud) (constantly (throw (Exception. "Don't call me")))基于Clojure 文档,我希望如何做到这一点constantly:
(constantly x)返回一个函数,它接受任意数量的参数并返回x.
但是当我尝试不断创建一个总是抛出的模拟函数时,会立即抛出异常,我试图定义函数.是constantly应该评估它的机身向右走,并缓存结果呢?我是否遇到了相当于C的可怕的未定义行为(在这种情况下,"一旦你依赖副作用,所有的赌注都会被取消")?
user=> (constantly (throw (Exception. "but not right now")))
Exception but not right now user/eval8734 (form-init1747541642059004341.clj:1)
user=> (repeatedly (throw (Exception. "but not right now")))
Exception but not right now user/eval8736 (form-init1747541642059004341.clj:1)
Run Code Online (Sandbox Code Playgroud)
在测试中创建模拟回调函数的惯用方法是什么,以便在调用时抛出错误?
有许多不同的AWS服务可以启动EC2实例:Elastic Beanstalk,ECS服务/任务,EC2自动调度组,Ops Works脚本,Cloud Formation模板,以及我尚未发现的其他模板.今天我经过一系列实验和演示后正在清理.当我尝试停止某些EC2实例时,其中一些会被某些东西重新启动.是否有某种方法可以确定EC2实例的启动原因,而无需在每个AWS产品中寻找特定机器的参考?