mlrun 1.7.2__py3-none-any.whl → 1.8.0rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mlrun might be problematic. Click here for more details.

Files changed (222) hide show
  1. mlrun/__init__.py +14 -12
  2. mlrun/__main__.py +3 -3
  3. mlrun/alerts/alert.py +19 -12
  4. mlrun/artifacts/__init__.py +0 -2
  5. mlrun/artifacts/base.py +34 -11
  6. mlrun/artifacts/dataset.py +16 -16
  7. mlrun/artifacts/manager.py +13 -13
  8. mlrun/artifacts/model.py +66 -53
  9. mlrun/common/constants.py +6 -0
  10. mlrun/common/formatters/__init__.py +1 -0
  11. mlrun/common/formatters/feature_set.py +1 -0
  12. mlrun/common/formatters/function.py +1 -0
  13. mlrun/common/formatters/model_endpoint.py +30 -0
  14. mlrun/common/formatters/pipeline.py +1 -2
  15. mlrun/common/model_monitoring/__init__.py +0 -3
  16. mlrun/common/model_monitoring/helpers.py +1 -1
  17. mlrun/common/runtimes/constants.py +1 -2
  18. mlrun/common/schemas/__init__.py +4 -2
  19. mlrun/common/schemas/artifact.py +0 -6
  20. mlrun/common/schemas/common.py +50 -0
  21. mlrun/common/schemas/model_monitoring/__init__.py +8 -1
  22. mlrun/common/schemas/model_monitoring/constants.py +62 -12
  23. mlrun/common/schemas/model_monitoring/model_endpoint_v2.py +149 -0
  24. mlrun/common/schemas/model_monitoring/model_endpoints.py +21 -5
  25. mlrun/common/schemas/partition.py +122 -0
  26. mlrun/config.py +43 -15
  27. mlrun/data_types/__init__.py +0 -2
  28. mlrun/data_types/data_types.py +0 -1
  29. mlrun/data_types/infer.py +3 -1
  30. mlrun/data_types/spark.py +4 -4
  31. mlrun/data_types/to_pandas.py +2 -11
  32. mlrun/datastore/__init__.py +0 -2
  33. mlrun/datastore/alibaba_oss.py +4 -1
  34. mlrun/datastore/azure_blob.py +4 -1
  35. mlrun/datastore/base.py +12 -4
  36. mlrun/datastore/datastore.py +9 -3
  37. mlrun/datastore/datastore_profile.py +1 -1
  38. mlrun/datastore/dbfs_store.py +4 -1
  39. mlrun/datastore/filestore.py +4 -1
  40. mlrun/datastore/google_cloud_storage.py +4 -1
  41. mlrun/datastore/hdfs.py +4 -1
  42. mlrun/datastore/inmem.py +4 -1
  43. mlrun/datastore/redis.py +4 -1
  44. mlrun/datastore/s3.py +4 -1
  45. mlrun/datastore/sources.py +51 -49
  46. mlrun/datastore/store_resources.py +0 -2
  47. mlrun/datastore/targets.py +22 -23
  48. mlrun/datastore/utils.py +2 -2
  49. mlrun/datastore/v3io.py +4 -1
  50. mlrun/datastore/wasbfs/fs.py +13 -12
  51. mlrun/db/base.py +126 -62
  52. mlrun/db/factory.py +3 -0
  53. mlrun/db/httpdb.py +767 -231
  54. mlrun/db/nopdb.py +126 -57
  55. mlrun/errors.py +2 -2
  56. mlrun/execution.py +55 -29
  57. mlrun/feature_store/__init__.py +0 -2
  58. mlrun/feature_store/api.py +40 -40
  59. mlrun/feature_store/common.py +9 -9
  60. mlrun/feature_store/feature_set.py +20 -18
  61. mlrun/feature_store/feature_vector.py +27 -24
  62. mlrun/feature_store/retrieval/base.py +14 -9
  63. mlrun/feature_store/retrieval/job.py +2 -1
  64. mlrun/feature_store/steps.py +2 -2
  65. mlrun/features.py +30 -13
  66. mlrun/frameworks/__init__.py +1 -2
  67. mlrun/frameworks/_common/__init__.py +1 -2
  68. mlrun/frameworks/_common/artifacts_library.py +2 -2
  69. mlrun/frameworks/_common/mlrun_interface.py +10 -6
  70. mlrun/frameworks/_common/model_handler.py +29 -27
  71. mlrun/frameworks/_common/producer.py +3 -1
  72. mlrun/frameworks/_dl_common/__init__.py +1 -2
  73. mlrun/frameworks/_dl_common/loggers/__init__.py +1 -2
  74. mlrun/frameworks/_dl_common/loggers/mlrun_logger.py +4 -4
  75. mlrun/frameworks/_dl_common/loggers/tensorboard_logger.py +3 -3
  76. mlrun/frameworks/_ml_common/__init__.py +1 -2
  77. mlrun/frameworks/_ml_common/loggers/__init__.py +1 -2
  78. mlrun/frameworks/_ml_common/model_handler.py +21 -21
  79. mlrun/frameworks/_ml_common/plans/__init__.py +1 -2
  80. mlrun/frameworks/_ml_common/plans/confusion_matrix_plan.py +3 -1
  81. mlrun/frameworks/_ml_common/plans/dataset_plan.py +3 -3
  82. mlrun/frameworks/_ml_common/plans/roc_curve_plan.py +4 -4
  83. mlrun/frameworks/auto_mlrun/__init__.py +1 -2
  84. mlrun/frameworks/auto_mlrun/auto_mlrun.py +22 -15
  85. mlrun/frameworks/huggingface/__init__.py +1 -2
  86. mlrun/frameworks/huggingface/model_server.py +9 -9
  87. mlrun/frameworks/lgbm/__init__.py +47 -44
  88. mlrun/frameworks/lgbm/callbacks/__init__.py +1 -2
  89. mlrun/frameworks/lgbm/callbacks/logging_callback.py +4 -2
  90. mlrun/frameworks/lgbm/callbacks/mlrun_logging_callback.py +4 -2
  91. mlrun/frameworks/lgbm/mlrun_interfaces/__init__.py +1 -2
  92. mlrun/frameworks/lgbm/mlrun_interfaces/mlrun_interface.py +5 -5
  93. mlrun/frameworks/lgbm/model_handler.py +15 -11
  94. mlrun/frameworks/lgbm/model_server.py +11 -7
  95. mlrun/frameworks/lgbm/utils.py +2 -2
  96. mlrun/frameworks/onnx/__init__.py +1 -2
  97. mlrun/frameworks/onnx/dataset.py +3 -3
  98. mlrun/frameworks/onnx/mlrun_interface.py +2 -2
  99. mlrun/frameworks/onnx/model_handler.py +7 -5
  100. mlrun/frameworks/onnx/model_server.py +8 -6
  101. mlrun/frameworks/parallel_coordinates.py +11 -11
  102. mlrun/frameworks/pytorch/__init__.py +22 -23
  103. mlrun/frameworks/pytorch/callbacks/__init__.py +1 -2
  104. mlrun/frameworks/pytorch/callbacks/callback.py +2 -1
  105. mlrun/frameworks/pytorch/callbacks/logging_callback.py +15 -8
  106. mlrun/frameworks/pytorch/callbacks/mlrun_logging_callback.py +19 -12
  107. mlrun/frameworks/pytorch/callbacks/tensorboard_logging_callback.py +22 -15
  108. mlrun/frameworks/pytorch/callbacks_handler.py +36 -30
  109. mlrun/frameworks/pytorch/mlrun_interface.py +17 -17
  110. mlrun/frameworks/pytorch/model_handler.py +21 -17
  111. mlrun/frameworks/pytorch/model_server.py +13 -9
  112. mlrun/frameworks/sklearn/__init__.py +19 -18
  113. mlrun/frameworks/sklearn/estimator.py +2 -2
  114. mlrun/frameworks/sklearn/metric.py +3 -3
  115. mlrun/frameworks/sklearn/metrics_library.py +8 -6
  116. mlrun/frameworks/sklearn/mlrun_interface.py +3 -2
  117. mlrun/frameworks/sklearn/model_handler.py +4 -3
  118. mlrun/frameworks/tf_keras/__init__.py +11 -12
  119. mlrun/frameworks/tf_keras/callbacks/__init__.py +1 -2
  120. mlrun/frameworks/tf_keras/callbacks/logging_callback.py +17 -14
  121. mlrun/frameworks/tf_keras/callbacks/mlrun_logging_callback.py +15 -12
  122. mlrun/frameworks/tf_keras/callbacks/tensorboard_logging_callback.py +21 -18
  123. mlrun/frameworks/tf_keras/model_handler.py +17 -13
  124. mlrun/frameworks/tf_keras/model_server.py +12 -8
  125. mlrun/frameworks/xgboost/__init__.py +19 -18
  126. mlrun/frameworks/xgboost/model_handler.py +13 -9
  127. mlrun/launcher/base.py +3 -4
  128. mlrun/launcher/local.py +1 -1
  129. mlrun/launcher/remote.py +1 -1
  130. mlrun/lists.py +4 -3
  131. mlrun/model.py +108 -44
  132. mlrun/model_monitoring/__init__.py +1 -2
  133. mlrun/model_monitoring/api.py +6 -6
  134. mlrun/model_monitoring/applications/_application_steps.py +13 -15
  135. mlrun/model_monitoring/applications/histogram_data_drift.py +41 -15
  136. mlrun/model_monitoring/applications/results.py +55 -3
  137. mlrun/model_monitoring/controller.py +185 -223
  138. mlrun/model_monitoring/db/_schedules.py +156 -0
  139. mlrun/model_monitoring/db/_stats.py +189 -0
  140. mlrun/model_monitoring/db/stores/__init__.py +1 -1
  141. mlrun/model_monitoring/db/stores/base/store.py +6 -65
  142. mlrun/model_monitoring/db/stores/sqldb/models/__init__.py +0 -25
  143. mlrun/model_monitoring/db/stores/sqldb/models/base.py +0 -97
  144. mlrun/model_monitoring/db/stores/sqldb/models/mysql.py +2 -58
  145. mlrun/model_monitoring/db/stores/sqldb/models/sqlite.py +0 -15
  146. mlrun/model_monitoring/db/stores/sqldb/sql_store.py +6 -257
  147. mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +9 -271
  148. mlrun/model_monitoring/db/tsdb/base.py +74 -22
  149. mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +66 -35
  150. mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +33 -0
  151. mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +284 -51
  152. mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +1 -0
  153. mlrun/model_monitoring/db/tsdb/v3io/v3io_connector.py +35 -17
  154. mlrun/model_monitoring/helpers.py +97 -1
  155. mlrun/model_monitoring/model_endpoint.py +4 -2
  156. mlrun/model_monitoring/stream_processing.py +2 -2
  157. mlrun/model_monitoring/tracking_policy.py +10 -3
  158. mlrun/model_monitoring/writer.py +47 -26
  159. mlrun/package/__init__.py +3 -6
  160. mlrun/package/context_handler.py +1 -1
  161. mlrun/package/packager.py +12 -9
  162. mlrun/package/packagers/__init__.py +0 -2
  163. mlrun/package/packagers/default_packager.py +14 -11
  164. mlrun/package/packagers/numpy_packagers.py +16 -7
  165. mlrun/package/packagers/pandas_packagers.py +18 -18
  166. mlrun/package/packagers/python_standard_library_packagers.py +25 -11
  167. mlrun/package/packagers_manager.py +31 -14
  168. mlrun/package/utils/__init__.py +0 -3
  169. mlrun/package/utils/_pickler.py +6 -6
  170. mlrun/platforms/__init__.py +3 -3
  171. mlrun/platforms/iguazio.py +4 -1
  172. mlrun/projects/__init__.py +1 -6
  173. mlrun/projects/operations.py +27 -27
  174. mlrun/projects/pipelines.py +85 -215
  175. mlrun/projects/project.py +444 -158
  176. mlrun/run.py +9 -9
  177. mlrun/runtimes/__init__.py +1 -3
  178. mlrun/runtimes/base.py +13 -10
  179. mlrun/runtimes/daskjob.py +9 -9
  180. mlrun/runtimes/generators.py +2 -1
  181. mlrun/runtimes/kubejob.py +4 -5
  182. mlrun/runtimes/mpijob/__init__.py +0 -2
  183. mlrun/runtimes/mpijob/abstract.py +7 -6
  184. mlrun/runtimes/nuclio/api_gateway.py +7 -7
  185. mlrun/runtimes/nuclio/application/application.py +11 -11
  186. mlrun/runtimes/nuclio/function.py +14 -14
  187. mlrun/runtimes/nuclio/serving.py +9 -9
  188. mlrun/runtimes/pod.py +74 -29
  189. mlrun/runtimes/remotesparkjob.py +3 -2
  190. mlrun/runtimes/sparkjob/__init__.py +0 -2
  191. mlrun/runtimes/sparkjob/spark3job.py +21 -11
  192. mlrun/runtimes/utils.py +6 -5
  193. mlrun/serving/merger.py +6 -4
  194. mlrun/serving/remote.py +18 -17
  195. mlrun/serving/routers.py +27 -27
  196. mlrun/serving/server.py +1 -1
  197. mlrun/serving/states.py +76 -71
  198. mlrun/serving/utils.py +13 -2
  199. mlrun/serving/v1_serving.py +3 -2
  200. mlrun/serving/v2_serving.py +4 -4
  201. mlrun/track/__init__.py +1 -1
  202. mlrun/track/tracker.py +2 -2
  203. mlrun/track/trackers/mlflow_tracker.py +6 -5
  204. mlrun/utils/async_http.py +1 -1
  205. mlrun/utils/helpers.py +72 -28
  206. mlrun/utils/logger.py +104 -2
  207. mlrun/utils/notifications/notification/base.py +23 -4
  208. mlrun/utils/notifications/notification/console.py +1 -1
  209. mlrun/utils/notifications/notification/git.py +6 -6
  210. mlrun/utils/notifications/notification/ipython.py +5 -4
  211. mlrun/utils/notifications/notification/slack.py +1 -1
  212. mlrun/utils/notifications/notification/webhook.py +13 -17
  213. mlrun/utils/notifications/notification_pusher.py +23 -19
  214. mlrun/utils/regex.py +1 -1
  215. mlrun/utils/version/version.json +2 -2
  216. {mlrun-1.7.2.dist-info → mlrun-1.8.0rc1.dist-info}/METADATA +187 -199
  217. mlrun-1.8.0rc1.dist-info/RECORD +356 -0
  218. {mlrun-1.7.2.dist-info → mlrun-1.8.0rc1.dist-info}/WHEEL +1 -1
  219. mlrun-1.7.2.dist-info/RECORD +0 -351
  220. {mlrun-1.7.2.dist-info → mlrun-1.8.0rc1.dist-info}/LICENSE +0 -0
  221. {mlrun-1.7.2.dist-info → mlrun-1.8.0rc1.dist-info}/entry_points.txt +0 -0
  222. {mlrun-1.7.2.dist-info → mlrun-1.8.0rc1.dist-info}/top_level.txt +0 -0
@@ -20,16 +20,15 @@ import tempfile
20
20
  import typing
21
21
  import uuid
22
22
 
23
- import mlrun_pipelines.common.models
24
- import mlrun_pipelines.patcher
25
- import mlrun_pipelines.utils
26
-
27
23
  import mlrun
28
24
  import mlrun.common.runtimes.constants
29
25
  import mlrun.common.schemas
30
26
  import mlrun.common.schemas.function
31
27
  import mlrun.common.schemas.workflow
32
28
  import mlrun.utils.notifications
29
+ import mlrun_pipelines.common.models
30
+ import mlrun_pipelines.patcher
31
+ import mlrun_pipelines.utils
33
32
  from mlrun.errors import err_to_str
34
33
  from mlrun.utils import (
35
34
  get_ui_url,
@@ -317,7 +316,7 @@ def get_db_function(project, key) -> mlrun.runtimes.BaseRuntime:
317
316
  def enrich_function_object(
318
317
  project: mlrun.common.schemas.Project,
319
318
  function: mlrun.runtimes.BaseRuntime,
320
- decorator: typing.Callable = None,
319
+ decorator: typing.Optional[typing.Callable] = None,
321
320
  copy_function: bool = True,
322
321
  try_auto_mount: bool = True,
323
322
  ) -> mlrun.runtimes.BaseRuntime:
@@ -380,7 +379,7 @@ class _PipelineRunStatus:
380
379
  project: "mlrun.projects.MlrunProject",
381
380
  workflow: WorkflowSpec = None,
382
381
  state: mlrun_pipelines.common.models.RunStatuses = "",
383
- exc: Exception = None,
382
+ exc: typing.Optional[Exception] = None,
384
383
  ):
385
384
  """
386
385
  :param run_id: unique id of the pipeline run
@@ -453,7 +452,7 @@ class _PipelineRunner(abc.ABC):
453
452
  artifact_path=None,
454
453
  namespace=None,
455
454
  source=None,
456
- notifications: list[mlrun.model.Notification] = None,
455
+ notifications: typing.Optional[list[mlrun.model.Notification]] = None,
457
456
  ) -> _PipelineRunStatus:
458
457
  pass
459
458
 
@@ -463,7 +462,7 @@ class _PipelineRunner(abc.ABC):
463
462
  run: "_PipelineRunStatus",
464
463
  project: typing.Optional["mlrun.projects.MlrunProject"] = None,
465
464
  timeout: typing.Optional[int] = None,
466
- expected_statuses: list[str] = None,
465
+ expected_statuses: typing.Optional[list[str]] = None,
467
466
  ):
468
467
  pass
469
468
 
@@ -577,7 +576,7 @@ class _KFPRunner(_PipelineRunner):
577
576
  artifact_path=None,
578
577
  namespace=None,
579
578
  source=None,
580
- notifications: list[mlrun.model.Notification] = None,
579
+ notifications: typing.Optional[list[mlrun.model.Notification]] = None,
581
580
  ) -> _PipelineRunStatus:
582
581
  pipeline_context.set(project, workflow_spec)
583
582
  workflow_handler = _PipelineRunner._get_handler(
@@ -641,7 +640,7 @@ class _KFPRunner(_PipelineRunner):
641
640
  run: "_PipelineRunStatus",
642
641
  project: typing.Optional["mlrun.projects.MlrunProject"] = None,
643
642
  timeout: typing.Optional[int] = None,
644
- expected_statuses: list[str] = None,
643
+ expected_statuses: typing.Optional[list[str]] = None,
645
644
  ):
646
645
  project_name = project.metadata.name if project else ""
647
646
  logger.info(
@@ -686,7 +685,7 @@ class _LocalRunner(_PipelineRunner):
686
685
  artifact_path=None,
687
686
  namespace=None,
688
687
  source=None,
689
- notifications: list[mlrun.model.Notification] = None,
688
+ notifications: typing.Optional[list[mlrun.model.Notification]] = None,
690
689
  ) -> _PipelineRunStatus:
691
690
  pipeline_context.set(project, workflow_spec)
692
691
  workflow_handler = _PipelineRunner._get_handler(
@@ -763,13 +762,13 @@ class _RemoteRunner(_PipelineRunner):
763
762
  cls,
764
763
  project: "mlrun.projects.MlrunProject",
765
764
  workflow_spec: WorkflowSpec,
766
- name: str = None,
767
- workflow_handler: typing.Union[str, typing.Callable] = None,
765
+ name: typing.Optional[str] = None,
766
+ workflow_handler: typing.Optional[typing.Union[str, typing.Callable]] = None,
768
767
  secrets: mlrun.secrets.SecretsStore = None,
769
- artifact_path: str = None,
770
- namespace: str = None,
771
- source: str = None,
772
- notifications: list[mlrun.model.Notification] = None,
768
+ artifact_path: typing.Optional[str] = None,
769
+ namespace: typing.Optional[str] = None,
770
+ source: typing.Optional[str] = None,
771
+ notifications: typing.Optional[list[mlrun.model.Notification]] = None,
773
772
  ) -> typing.Optional[_PipelineRunStatus]:
774
773
  workflow_name = normalize_workflow_name(name=name, project_name=project.name)
775
774
  workflow_id = None
@@ -890,7 +889,7 @@ class _RemoteRunner(_PipelineRunner):
890
889
  timeout=None,
891
890
  expected_statuses=None,
892
891
  notifiers: mlrun.utils.notifications.CustomNotificationPusher = None,
893
- inner_engine: type[_PipelineRunner] = None,
892
+ inner_engine: typing.Optional[type[_PipelineRunner]] = None,
894
893
  ):
895
894
  inner_engine = inner_engine or _KFPRunner
896
895
  if inner_engine.engine == _KFPRunner.engine:
@@ -984,43 +983,34 @@ def github_webhook(request):
984
983
  return {"msg": "pushed"}
985
984
 
986
985
 
987
- def load_and_run(context, *args, **kwargs):
988
- """
989
- This function serves as an alias to `load_and_run_workflow`,
990
- allowing to continue using `load_and_run` without modifying existing workflows or exported runs.
991
- This approach ensures backward compatibility,
992
- while directing all new calls to the updated `load_and_run_workflow` function.
993
- """
994
- kwargs.pop("load_only", None)
995
- kwargs.pop("save", None)
996
- load_and_run_workflow(context, *args, **kwargs)
997
-
998
-
999
- def load_and_run_workflow(
986
+ def load_and_run(
1000
987
  context: mlrun.execution.MLClientCtx,
1001
- url: str = None,
988
+ url: typing.Optional[str] = None,
1002
989
  project_name: str = "",
1003
- init_git: bool = None,
1004
- subpath: str = None,
990
+ init_git: typing.Optional[bool] = None,
991
+ subpath: typing.Optional[str] = None,
1005
992
  clone: bool = False,
1006
- workflow_name: str = None,
1007
- workflow_path: str = None,
1008
- workflow_arguments: dict[str, typing.Any] = None,
1009
- artifact_path: str = None,
1010
- workflow_handler: typing.Union[str, typing.Callable] = None,
1011
- namespace: str = None,
993
+ save: bool = True,
994
+ workflow_name: typing.Optional[str] = None,
995
+ workflow_path: typing.Optional[str] = None,
996
+ workflow_arguments: typing.Optional[dict[str, typing.Any]] = None,
997
+ artifact_path: typing.Optional[str] = None,
998
+ workflow_handler: typing.Optional[typing.Union[str, typing.Callable]] = None,
999
+ namespace: typing.Optional[str] = None,
1012
1000
  sync: bool = False,
1013
1001
  dirty: bool = False,
1014
- engine: str = None,
1015
- local: bool = None,
1002
+ engine: typing.Optional[str] = None,
1003
+ local: typing.Optional[bool] = None,
1016
1004
  schedule: typing.Union[str, mlrun.common.schemas.ScheduleCronTrigger] = None,
1017
- cleanup_ttl: int = None,
1005
+ cleanup_ttl: typing.Optional[int] = None,
1006
+ load_only: bool = False,
1018
1007
  wait_for_completion: bool = False,
1019
- project_context: str = None,
1008
+ project_context: typing.Optional[str] = None,
1020
1009
  ):
1021
1010
  """
1022
1011
  Auxiliary function that the RemoteRunner run once or run every schedule.
1023
1012
  This function loads a project from a given remote source and then runs the workflow.
1013
+
1024
1014
  :param context: mlrun context.
1025
1015
  :param url: remote url that represents the project's source.
1026
1016
  See 'mlrun.load_project()' for details
@@ -1028,6 +1018,7 @@ def load_and_run_workflow(
1028
1018
  :param init_git: if True, will git init the context dir
1029
1019
  :param subpath: project subpath (within the archive)
1030
1020
  :param clone: if True, always clone (delete any existing content)
1021
+ :param save: whether to save the created project and artifact in the DB
1031
1022
  :param workflow_name: name of the workflow
1032
1023
  :param workflow_path: url to a workflow file, if not a project workflow
1033
1024
  :param workflow_arguments: kubeflow pipelines arguments (parameters)
@@ -1043,31 +1034,48 @@ def load_and_run_workflow(
1043
1034
  :param schedule: ScheduleCronTrigger class instance or a standard crontab expression string
1044
1035
  :param cleanup_ttl: pipeline cleanup ttl in secs (time to wait after workflow completion, at which point the
1045
1036
  workflow and all its resources are deleted)
1037
+ :param load_only: for just loading the project, inner use.
1046
1038
  :param wait_for_completion: wait for workflow completion before returning
1047
1039
  :param project_context: project context path (used for loading the project)
1048
1040
  """
1049
- project_context = project_context or f"./{project_name}"
1050
-
1051
- # Load the project to fetch files which the runner needs, such as remote source files
1052
- pull_remote_project_files(
1053
- context=context,
1054
- project_context=project_context,
1055
- url=url,
1056
- project_name=project_name,
1057
- init_git=init_git,
1058
- subpath=subpath,
1059
- clone=clone,
1060
- schedule=schedule,
1061
- workflow_name=workflow_name,
1062
- )
1041
+ try:
1042
+ project = mlrun.load_project(
1043
+ context=project_context or f"./{project_name}",
1044
+ url=url,
1045
+ name=project_name,
1046
+ init_git=init_git,
1047
+ subpath=subpath,
1048
+ clone=clone,
1049
+ save=save,
1050
+ sync_functions=True,
1051
+ )
1052
+ except Exception as error:
1053
+ if schedule:
1054
+ notification_pusher = mlrun.utils.notifications.CustomNotificationPusher(
1055
+ ["slack"]
1056
+ )
1057
+ url = get_ui_url(project_name, context.uid)
1058
+ link = f"<{url}|*view workflow job details*>"
1059
+ message = (
1060
+ f":x: Failed to run scheduled workflow {workflow_name} in Project {project_name} !\n"
1061
+ f"error: ```{error}```\n{link}"
1062
+ )
1063
+ # Sending Slack Notification without losing the original error:
1064
+ try:
1065
+ notification_pusher.push(
1066
+ message=message,
1067
+ severity=mlrun.common.schemas.NotificationSeverity.ERROR,
1068
+ )
1063
1069
 
1064
- # Retrieve the project object:
1065
- # - If the project exists in the MLRun database, it will be loaded from there.
1066
- # - If it doesn't exist in the database, it will be created from the previously loaded local directory.
1067
- project = mlrun.get_or_create_project(
1068
- context=project_context or f"./{project_name}",
1069
- name=project_name,
1070
- )
1070
+ except Exception as exc:
1071
+ logger.error("Failed to send slack notification", exc=err_to_str(exc))
1072
+
1073
+ raise error
1074
+
1075
+ context.logger.info(f"Loaded project {project.name} successfully")
1076
+
1077
+ if load_only:
1078
+ return
1071
1079
 
1072
1080
  # extract "start" notification if exists
1073
1081
  start_notifications = [
@@ -1100,156 +1108,18 @@ def load_and_run_workflow(
1100
1108
  raise RuntimeError(f"Workflow {workflow_log_message} failed") from run.exc
1101
1109
 
1102
1110
  if wait_for_completion:
1103
- handle_workflow_completion(
1104
- run=run,
1105
- project=project,
1106
- context=context,
1107
- workflow_log_message=workflow_log_message,
1108
- )
1109
-
1110
-
1111
- def pull_remote_project_files(
1112
- context: mlrun.execution.MLClientCtx,
1113
- project_context: str,
1114
- url: str,
1115
- project_name: str,
1116
- init_git: typing.Optional[bool],
1117
- subpath: typing.Optional[str],
1118
- clone: bool,
1119
- schedule: typing.Optional[
1120
- typing.Union[str, mlrun.common.schemas.ScheduleCronTrigger]
1121
- ],
1122
- workflow_name: typing.Optional[str],
1123
- ) -> None:
1124
- """
1125
- Load the project to clone remote files if they exist.
1126
- If an exception occurs during project loading, send a notification if the workflow is scheduled.
1127
-
1128
- :param context: MLRun execution context.
1129
- :param project_context: Path to the project context.
1130
- :param url: URL of the project repository.
1131
- :param project_name: Name of the project.
1132
- :param init_git: Initialize a git repository.
1133
- :param subpath: Project subpath within the repository.
1134
- :param clone: Whether to clone the repository.
1135
- :param schedule: Schedule for running the workflow.
1136
- :param workflow_name: Name of the workflow to run.
1137
- """
1138
- try:
1139
- # Load the project to clone remote files if they exist.
1140
- # Using save=False to avoid overriding changes from the database if it already exists.
1141
- mlrun.load_project(
1142
- context=project_context,
1143
- url=url,
1144
- name=project_name,
1145
- init_git=init_git,
1146
- subpath=subpath,
1147
- clone=clone,
1148
- save=False,
1149
- )
1150
- except Exception as error:
1151
- notify_scheduled_workflow_failure(
1152
- schedule=schedule,
1153
- project_name=project_name,
1154
- workflow_name=workflow_name,
1155
- error=error,
1156
- context_uid=context.uid,
1157
- )
1158
- raise error
1159
-
1160
-
1161
- def notify_scheduled_workflow_failure(
1162
- schedule,
1163
- project_name: str,
1164
- workflow_name: str,
1165
- error: Exception,
1166
- context_uid: str,
1167
- ) -> None:
1168
- if schedule:
1169
- notification_pusher = mlrun.utils.notifications.CustomNotificationPusher(
1170
- ["slack"]
1171
- )
1172
- url = get_ui_url(project_name, context_uid)
1173
- link = f"<{url}|*view workflow job details*>"
1174
- message = (
1175
- f":x: Failed to run scheduled workflow {workflow_name} "
1176
- f"in Project {project_name}!\n"
1177
- f"Error: ```{err_to_str(error)}```\n{link}"
1178
- )
1179
- # Sending Slack Notification without losing the original error:
1180
1111
  try:
1181
- notification_pusher.push(
1182
- message=message,
1183
- severity=mlrun.common.schemas.NotificationSeverity.ERROR,
1184
- )
1185
-
1112
+ run.wait_for_completion()
1186
1113
  except Exception as exc:
1187
- logger.error("Failed to send slack notification", exc=err_to_str(exc))
1188
-
1189
-
1190
- def handle_workflow_completion(
1191
- run: _PipelineRunStatus,
1192
- project,
1193
- context: mlrun.execution.MLClientCtx,
1194
- workflow_log_message: str,
1195
- ) -> None:
1196
- """
1197
- Handle workflow completion by waiting for it to finish and logging the final state.
1198
-
1199
- :param run: Run object containing workflow execution details.
1200
- :param project: MLRun project object.
1201
- :param context: MLRun execution context.
1202
- :param workflow_log_message: Message used for logging.
1203
- """
1204
- try:
1205
- run.wait_for_completion()
1206
- except Exception as exc:
1207
- mlrun.utils.logger.error(
1208
- "Failed waiting for workflow completion",
1209
- workflow=workflow_log_message,
1210
- exc=err_to_str(exc),
1211
- )
1212
-
1213
- pipeline_state, _, _ = project.get_run_status(run)
1214
- context.log_result(key="workflow_state", value=pipeline_state, commit=True)
1215
- if pipeline_state != mlrun_pipelines.common.models.RunStatuses.succeeded:
1216
- raise RuntimeError(
1217
- f"Workflow {workflow_log_message} failed, state={pipeline_state}"
1218
- )
1219
-
1220
-
1221
- def import_remote_project(
1222
- context: mlrun.execution.MLClientCtx,
1223
- url: str = None,
1224
- project_name: str = "",
1225
- init_git: bool = None,
1226
- subpath: str = None,
1227
- clone: bool = False,
1228
- save: bool = True,
1229
- project_context: str = None,
1230
- ):
1231
- """
1232
- This function loads a project from a given remote source.
1233
-
1234
- :param context: mlrun context.
1235
- :param url: remote url that represents the project's source.
1236
- See 'mlrun.load_project()' for details
1237
- :param project_name: project name
1238
- :param init_git: if True, will git init the context dir
1239
- :param subpath: project subpath (within the archive)
1240
- :param clone: if True, always clone (delete any existing content)
1241
- :param save: whether to save the created project and artifact in the DB
1242
- :param project_context: project context path (used for loading the project)
1243
- """
1244
- project = mlrun.load_project(
1245
- context=project_context or f"./{project_name}",
1246
- url=url,
1247
- name=project_name,
1248
- init_git=init_git,
1249
- subpath=subpath,
1250
- clone=clone,
1251
- save=save,
1252
- sync_functions=True,
1253
- )
1114
+ logger.error(
1115
+ "Failed waiting for workflow completion",
1116
+ workflow=workflow_log_message,
1117
+ exc=err_to_str(exc),
1118
+ )
1254
1119
 
1255
- context.logger.info(f"Loaded project {project.name} successfully")
1120
+ pipeline_state, _, _ = project.get_run_status(run)
1121
+ context.log_result(key="workflow_state", value=pipeline_state, commit=True)
1122
+ if pipeline_state != mlrun_pipelines.common.models.RunStatuses.succeeded:
1123
+ raise RuntimeError(
1124
+ f"Workflow {workflow_log_message} failed, state={pipeline_state}"
1125
+ )