Reputation: 3109
When I comment out the thread related code below, the submission to the slack API works as expected. However, when I attempt to process the submission within a thread command, the submission never goes through.
Am I doing something wrong? Running in Railo 4
// push to slack!
public function push(options = {}) {
var http = new http();
var data = {
"text": "Default message",
"channel": "activity"
};
structAppend(data, options);
// thread
// action="run" {
sleep(5000);
http.setMethod("post");
http.setUrl(variables.slackWebhookUrl);
http.addParam(
type = "formField",
name = "payload",
value = serializeJson(data)
);
http.send();
// }
}
Upvotes: 3
Views: 148
Reputation: 3109
Credit goes to Adam Cameron for pointing me in the right direction. As it turns out, scoping is quite tricky with cfthreads.
For the sake of brevity, I will just say that I will follow these rules when using threads in the future:
This is working code:
// push to slack!
public function push(options = {}) {
var data = {
"text": "Default message",
"channel": "activity"
};
structAppend(data, options);
thread
action="run"
data="#data#"
slackUrl="#variables.slackWebhookUrl#" {
var http = new http();
http.setMethod("post");
http.setUrl(attributes.slackUrl);
http.addParam(
type = "formField",
name = "payload",
value = serializeJson(attributes.data)
);
http.send();
}
}
Upvotes: 2