ReCodEx - Task Broker
ReCodEx is complex programmer testing solution, primary targeted to technical universities. It's highly customizable and based on modern technologies.
status_notifier_handler.cpp
1 #include <map>
2 #include <sstream>
3 
4 #include "../helpers/curl.h"
5 #include "status_notifier_handler.h"
6 
7 const std::string status_notifier_handler::TYPE_ERROR = "error";
8 const std::string status_notifier_handler::TYPE_JOB_STATUS = "job-status";
9 
10 status_notifier_handler::status_notifier_handler(const notifier_config &config, std::shared_ptr<spdlog::logger> logger)
11  : config_(config), logger_(logger)
12 {
13 }
14 
16 {
17  std::string type = "";
18  std::string id = "";
19  helpers::curl_params params;
20 
21  auto it = std::begin(message.data);
22 
23  while (it != std::end(message.data)) {
24  const std::string &key = *it;
25  const std::string &value = *(it + 1);
26 
27  if (key == "type") {
28  type = value;
29  } else if (key == "id") {
30  id = value;
31  } else {
32  params[key] = value;
33  }
34 
35  it += 2;
36  }
37 
38  std::stringstream ss;
39  ss << config_.address;
40 
41  if (type != "") {
42  ss << "/" << type;
43  }
44 
45  if (id != "") {
46  ss << "/" << id;
47  }
48 
49  try {
50  helpers::curl_post(ss.str(), config_.port, params, config_.username, config_.password);
51  } catch (helpers::curl_exception &exception) {
52  logger_->emerg() << "curl failed: " << exception.what();
53  }
54 }
std::function< void(const message_container &)> response_cb
std::string username
std::string address
void on_request(const message_container &message, response_cb respond)
virtual const char * what() const noexcept
Definition: curl.h:88
static const std::string TYPE_ERROR
static const std::string TYPE_JOB_STATUS
status_notifier_handler(const notifier_config &config, std::shared_ptr< spdlog::logger > logger)
std::vector< std::string > data
std::string password