task_base_worker.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from fate_flow.entity.run_status import TaskStatus
  17. from fate_flow.scheduling_apps.client import ControllerClient
  18. from fate_flow.utils.log_utils import getLogger
  19. from fate_flow.worker.base_worker import BaseWorker
  20. LOGGER = getLogger()
  21. class ComponentInput:
  22. def __init__(
  23. self,
  24. tracker,
  25. checkpoint_manager,
  26. task_version_id,
  27. parameters,
  28. datasets,
  29. models,
  30. caches,
  31. job_parameters,
  32. roles,
  33. flow_feeded_parameters,
  34. ) -> None:
  35. self._tracker = tracker
  36. self._checkpoint_manager = checkpoint_manager
  37. self._task_version_id = task_version_id
  38. self._parameters = parameters
  39. self._datasets = datasets
  40. self._models = models
  41. self._caches = caches
  42. self._job_parameters = job_parameters
  43. self._roles = roles
  44. self._flow_feeded_parameters = flow_feeded_parameters
  45. @property
  46. def tracker(self):
  47. return self._tracker
  48. @property
  49. def task_version_id(self):
  50. return self._task_version_id
  51. @property
  52. def checkpoint_manager(self):
  53. return self._checkpoint_manager
  54. @property
  55. def parameters(self):
  56. return self._parameters
  57. @property
  58. def flow_feeded_parameters(self):
  59. return self._flow_feeded_parameters
  60. @property
  61. def roles(self):
  62. return self._roles
  63. @property
  64. def job_parameters(self):
  65. return self._job_parameters
  66. @property
  67. def datasets(self):
  68. return self._datasets
  69. @property
  70. def models(self):
  71. return {k: v for k, v in self._models.items() if v is not None}
  72. @property
  73. def caches(self):
  74. return self._caches
  75. class BaseTaskWorker(BaseWorker):
  76. def _run(self):
  77. self.report_info.update({
  78. "job_id": self.args.job_id,
  79. "component_name": self.args.component_name,
  80. "task_id": self.args.task_id,
  81. "task_version": self.args.task_version,
  82. "role": self.args.role,
  83. "party_id": self.args.party_id,
  84. "run_ip": self.args.run_ip,
  85. "run_pid": self.run_pid
  86. })
  87. self._run_()
  88. def _run_(self):
  89. pass
  90. def _handle_exception(self):
  91. self.report_info["party_status"] = TaskStatus.FAILED
  92. self.report_task_info_to_driver()
  93. def report_task_info_to_driver(self):
  94. LOGGER.info("report {} {} {} {} {} to driver:\n{}".format(
  95. self.__class__.__name__,
  96. self.report_info["task_id"],
  97. self.report_info["task_version"],
  98. self.report_info["role"],
  99. self.report_info["party_id"],
  100. self.report_info
  101. ))
  102. ControllerClient.report_task(self.report_info)