ReCodEx - Task Broker
ReCodEx is complex programmer testing solution, primary targeted to technical universities. It's highly customizable and based on modern technologies.
http_status_notifier.cpp
1 #include "http_status_notifier.h"
2 
3 http_status_notifier::http_status_notifier(const notifier_config &config, std::shared_ptr<spdlog::logger> logger)
4  : config_(config), logger_(logger)
5 {
6  if (logger_ == nullptr) {
7  logger_ = helpers::create_null_logger();
8  }
9 }
10 
11 void http_status_notifier::send(std::string route, helpers::curl_params params)
12 {
13  std::string addr = config_.address + route;
14  try {
15  helpers::curl_post(addr, config_.port, params, config_.username, config_.password);
16  } catch (helpers::curl_exception e) {
17  logger_->emerg() << e.what();
18  }
19 }
20 
21 void http_status_notifier::error(const std::string &desc)
22 {
23  send(error_route_, {{"message", desc}});
24 }
25 
26 void http_status_notifier::rejected_job(const std::string &job_id, const std::string &desc)
27 {
28  rejected_jobs({job_id}, desc);
29 }
30 
31 void http_status_notifier::rejected_jobs(std::vector<std::string> job_ids, const std::string &desc)
32 {
33  for (auto &id : job_ids) {
34  send(job_status_route_ + id, {{"status", "FAILED"}, {"message", desc}});
35  }
36 }
37 
38 void http_status_notifier::job_done(const std::string &job_id)
39 {
40  send(job_status_route_ + job_id, {{"status", "OK"}});
41 }
42 
43 void http_status_notifier::job_failed(const std::string &job_id, const std::string &desc)
44 {
45  send(job_status_route_ + job_id, {{"status", "FAILED"}, {"message", desc}});
46 }
virtual void rejected_job(const std::string &job_id, const std::string &desc="")
virtual void job_done(const std::string &job_id)
virtual void job_failed(const std::string &job_id, const std::string &desc="")
std::string username
virtual void rejected_jobs(std::vector< std::string > job_ids, const std::string &desc="")
std::string address
virtual const char * what() const noexcept
Definition: curl.h:88
virtual void error(const std::string &desc)
http_status_notifier(const notifier_config &config, std::shared_ptr< spdlog::logger > logger=nullptr)
std::string password