client_main.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include "workflow/%sMessage.h"
  4. #include "workflow/WFTaskFactory.h"
  5. #include "workflow/WFFacilities.h"
  6. #include "config/config.h"
  7. static WFFacilities::WaitGroup wait_group(1);
  8. static srpc::RPCConfig config;
  9. void sig_handler(int signo)
  10. {
  11. wait_group.done();
  12. }
  13. void init()
  14. {
  15. if (config.load("./client.conf") == false)
  16. {
  17. perror("Load config failed");
  18. exit(1);
  19. }
  20. signal(SIGINT, sig_handler);
  21. signal(SIGTERM, sig_handler);
  22. }
  23. void callback(WF%sTask *task)
  24. {
  25. int state = task->get_state();
  26. int error = task->get_error();
  27. fprintf(stderr, "%s client state = %%d error = %%d\n", state, error);
  28. %s
  29. }
  30. int main()
  31. {
  32. init();
  33. std::string url = std::string("%s://") + %sconfig.client_host() +
  34. std::string(":") + std::to_string(config.client_port());
  35. WF%sTask *task = WFTaskFactory::create_%s_task(url,%s
  36. config.retry_max(),
  37. callback);
  38. %s
  39. task->start();
  40. wait_group.wait();
  41. return 0;
  42. }