From f14d629a1230c33f6959c7fde890ff440d3845ac Mon Sep 17 00:00:00 2001 From: goFrendiAsgard Date: Thu, 19 Oct 2023 18:25:15 +0700 Subject: [PATCH] use should_execute instead of skip_execution --- docs/concepts/tasks/README.md | 8 +++---- project.sh | 3 --- .../builtin/generator/app_generator/add.py | 8 +++---- .../_automate/snake_zrb_app_name/container.py | 4 ++-- .../_automate/snake_zrb_app_name/container.py | 4 ++-- .../_automate/snake_zrb_app_name/image.py | 2 +- .../_automate/snake_zrb_app_name/local.py | 2 +- .../_automate/snake_zrb_app_name/local.py | 2 +- .../_automate/snake_zrb_app_name/_common.py | 22 +++++++++---------- .../_automate/snake_zrb_app_name/container.py | 8 +++---- .../_automate/snake_zrb_app_name/image.py | 2 +- .../_automate/snake_zrb_app_name/local.py | 20 ++++++++--------- .../snake_zrb_app_name/local_microservices.py | 6 ++--- .../_automate/snake_zrb_app_name/container.py | 4 ++-- .../_automate/snake_zrb_app_name/image.py | 2 +- .../_automate/snake_zrb_app_name/local.py | 2 +- src/zrb/task/any_task.py | 4 ++-- src/zrb/task/base_remote_cmd_task.py | 8 +++---- src/zrb/task/base_task.py | 22 +++++++++---------- src/zrb/task/base_task_composite.py | 15 ++++++------- src/zrb/task/cmd_task.py | 4 ++-- src/zrb/task/decorator.py | 4 ++-- src/zrb/task/docker_compose_task.py | 4 ++-- src/zrb/task/flow_task.py | 4 ++-- src/zrb/task/http_checker.py | 4 ++-- src/zrb/task/path_checker.py | 4 ++-- src/zrb/task/port_checker.py | 4 ++-- src/zrb/task/remote_cmd_task.py | 4 ++-- src/zrb/task/resource_maker.py | 4 ++-- src/zrb/task/rsync_task.py | 4 ++-- test/task/test_task.py | 4 ++-- zrb_init.py | 6 ++--- 32 files changed, 96 insertions(+), 102 deletions(-) diff --git a/docs/concepts/tasks/README.md b/docs/concepts/tasks/README.md index 60c95506..8c4800dd 100644 --- a/docs/concepts/tasks/README.md +++ b/docs/concepts/tasks/README.md @@ -355,15 +355,15 @@ Just like in our previous example `start_jupyterlab` will not started before `sh - __Possible values:__ List of `Task` object - __Default value:__ `[]` -## `skip_execution` +## `should_execute` Boolean, a function returning a boolean, or Jinja syntax that rendered to boolean. -If `skip_execution` is evaluated to `True`, then the task will be considered as completed without being started. +If `should_execute` is evaluated to `True`, then the task will be executed. - __Required:__ False - __Possible values:__ Boolean, a function returning a boolean, or Jinja syntax that rendered to boolean. -- __Default value:__ `False` +- __Default value:__ `True` ## `return_upstream_result` @@ -398,7 +398,7 @@ Deep copy current task ## `set_color` -## `set_skip_execution` +## `set_should_execute` ## `set_retry` diff --git a/project.sh b/project.sh index a4ec90e5..afdd29a6 100755 --- a/project.sh +++ b/project.sh @@ -12,9 +12,6 @@ fi echo '🤖 Activate virtual environment' source "${PROJECT_DIR}/.venv/bin/activate" -mkdir -p .docker-dir -cp -R docker-template/* .docker-dir - reload() { if [ ! -f "${PROJECT_DIR}/.env" ] diff --git a/src/zrb/builtin/generator/app_generator/add.py b/src/zrb/builtin/generator/app_generator/add.py index b1d218ec..45218771 100644 --- a/src/zrb/builtin/generator/app_generator/add.py +++ b/src/zrb/builtin/generator/app_generator/add.py @@ -132,7 +132,7 @@ async def validate(*args: Any, **kwargs: Any): copy_http_port_resource = ResourceMaker( name='copy-http-port-resource', inputs=inputs, - skip_execution='{{ not input.is_http_port }}', + should_execute='{{ input.is_http_port }}', upstreams=[copy_base_resource], replacements=replacements, template_path=os.path.join(CURRENT_DIR, 'template', 'http-port'), @@ -143,7 +143,7 @@ async def validate(*args: Any, **kwargs: Any): copy_custom_image_resource = ResourceMaker( name='copy-custom-image-resource', inputs=inputs, - skip_execution='{{ not input.build_custom_image }}', + should_execute='{{ input.build_custom_image }}', upstreams=[copy_http_port_resource], replacements=replacements, template_path=os.path.join(CURRENT_DIR, 'template', 'build-custom-image'), @@ -154,7 +154,7 @@ async def validate(*args: Any, **kwargs: Any): copy_http_port_custom_image_resource = ResourceMaker( name='copy-http-port-custom-image-resource', inputs=inputs, - skip_execution='{{ not input.is_http_port or not input.build_custom_image }}', # noqa + should_execute='{{ input.is_http_port or not input.build_custom_image }}', upstreams=[copy_custom_image_resource], replacements=replacements, template_path=os.path.join(CURRENT_DIR, 'template', 'http-port-build-custom-image'), # noqa @@ -165,7 +165,7 @@ async def validate(*args: Any, **kwargs: Any): copy_helm_resource = ResourceMaker( name='copy-helm-resource', inputs=inputs, - skip_execution='{{ not input.use_helm }}', + should_execute='{{ input.use_helm }}', upstreams=[copy_http_port_custom_image_resource], replacements=replacements, template_path=os.path.join(CURRENT_DIR, 'template', 'use-helm'), diff --git a/src/zrb/builtin/generator/app_generator/template/base/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/container.py b/src/zrb/builtin/generator/app_generator/template/base/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/container.py index 23882f8f..c735124c 100644 --- a/src/zrb/builtin/generator/app_generator/template/base/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/container.py +++ b/src/zrb/builtin/generator/app_generator/template/base/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/container.py @@ -67,7 +67,7 @@ local_input, host_input, ], - skip_execution='{{not input.local_snake_zrb_app_name}}', + should_execute='{{input.local_snake_zrb_app_name}}', upstreams=[ remove_snake_zrb_app_name_container, ], @@ -91,7 +91,7 @@ local_input, host_input, ], - skip_execution='{{not input.local_snake_zrb_app_name}}', + should_execute='{{input.local_snake_zrb_app_name}}', upstreams=[init_snake_zrb_app_name_container], cwd=RESOURCE_DIR, compose_cmd='logs', diff --git a/src/zrb/builtin/generator/app_generator/template/build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/container.py b/src/zrb/builtin/generator/app_generator/template/build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/container.py index ea32fbf3..05fadf0c 100644 --- a/src/zrb/builtin/generator/app_generator/template/build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/container.py +++ b/src/zrb/builtin/generator/app_generator/template/build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/container.py @@ -90,7 +90,7 @@ host_input, image_input, ], - skip_execution='{{not input.local_snake_zrb_app_name}}', + should_execute='{{input.local_snake_zrb_app_name}}', upstreams=[ remove_snake_zrb_app_name_container, build_snake_zrb_app_name_image, @@ -119,7 +119,7 @@ host_input, image_input, ], - skip_execution='{{not input.local_snake_zrb_app_name}}', + should_execute='{{input.local_snake_zrb_app_name}}', upstreams=[init_snake_zrb_app_name_container], cwd=RESOURCE_DIR, compose_cmd='logs', diff --git a/src/zrb/builtin/generator/app_generator/template/build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/image.py b/src/zrb/builtin/generator/app_generator/template/build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/image.py index 937a415a..5e13d373 100644 --- a/src/zrb/builtin/generator/app_generator/template/build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/image.py +++ b/src/zrb/builtin/generator/app_generator/template/build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/image.py @@ -40,7 +40,7 @@ image_input, ], envs=[image_env], - skip_execution='{{not input.local_snake_zrb_app_name}}', + should_execute='{{input.local_snake_zrb_app_name}}', cwd=RESOURCE_DIR, compose_cmd='build', compose_flags=[ diff --git a/src/zrb/builtin/generator/app_generator/template/build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/local.py b/src/zrb/builtin/generator/app_generator/template/build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/local.py index 1b4679b8..1e0cc9d2 100644 --- a/src/zrb/builtin/generator/app_generator/template/build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/local.py +++ b/src/zrb/builtin/generator/app_generator/template/build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/local.py @@ -27,7 +27,7 @@ local_input, host_input, ], - skip_execution='{{not input.local_snake_zrb_app_name}}', + should_execute='{{input.local_snake_zrb_app_name}}', cwd=APP_DIR, env_files=[app_env_file], envs=[ diff --git a/src/zrb/builtin/generator/app_generator/template/http-port-build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/local.py b/src/zrb/builtin/generator/app_generator/template/http-port-build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/local.py index 32921c08..2c4c9408 100644 --- a/src/zrb/builtin/generator/app_generator/template/http-port-build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/local.py +++ b/src/zrb/builtin/generator/app_generator/template/http-port-build-custom-image/_automate/generate_snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/local.py @@ -29,7 +29,7 @@ host_input, https_input, ], - skip_execution='{{not input.local_snake_zrb_app_name}}', + should_execute='{{ input.local_snake_zrb_app_name}}', cwd=APP_DIR, env_files=[app_env_file], envs=[ diff --git a/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/_common.py b/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/_common.py index 10d427c4..586532ff 100644 --- a/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/_common.py +++ b/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/_common.py @@ -30,11 +30,11 @@ ############################################################################### -def skip_local_microservices_execution(*args: Any, **kwargs: Any) -> bool: - if not kwargs.get('local_snake_zrb_app_name', True): +def should_start_local_microservices(*args: Any, **kwargs: Any) -> bool: + if kwargs.get('local_snake_zrb_app_name', True): return True run_mode = kwargs.get('snake_zrb_app_name_run_mode', 'monolith') - return run_mode != 'microservices' + return run_mode == 'microservices' ############################################################################### @@ -45,13 +45,13 @@ def skip_local_microservices_execution(*args: Any, **kwargs: Any) -> bool: name='check-rabbitmq-management', port='{{env.get("RABBITMQ_MANAGEMENT_HOST_PORT", "15672")}}', is_https='{{input.snake_zrb_app_name_https}}', - skip_execution='{{env.get("APP_BROKER_TYPE", "rabbitmq") != "rabbitmq"}}' + should_execute='{{env.get("APP_BROKER_TYPE", "rabbitmq") == "rabbitmq"}}' ) rabbitmq_checker = PortChecker( name='check-rabbitmq', port='{{env.get("RABBITMQ_HOST_PORT", "5672")}}', - skip_execution='{{env.get("APP_BROKER_TYPE", "rabbitmq") != "rabbitmq"}}' + should_execute='{{env.get("APP_BROKER_TYPE", "rabbitmq") == "rabbitmq"}}' ) redpanda_console_checker = HTTPChecker( @@ -59,31 +59,31 @@ def skip_local_microservices_execution(*args: Any, **kwargs: Any) -> bool: method='GET', port='{{env.get("REDPANDA_CONSOLE_HOST_PORT", "9000")}}', is_https='{{input.snake_zrb_app_name_https}}', - skip_execution='{{env.get("APP_BROKER_TYPE", "rabbitmq") != "kafka"}}' + should_execute='{{env.get("APP_BROKER_TYPE", "rabbitmq") == "kafka"}}' ) kafka_plaintext_checker = PortChecker( name='check-kafka-plaintext', port='{{env.get("KAFKA_INTERNAL_HOST_PORT", "29092")}}', - skip_execution='{{env.get("APP_BROKER_TYPE", "rabbitmq") != "kafka"}}' + should_execute='{{env.get("APP_BROKER_TYPE", "rabbitmq") == "kafka"}}' ) kafka_outside_checker = PortChecker( name='check-kafka-outside', port='{{env.get("KAFKA_EXTERNAL_HOST_PORT", "9092")}}', - skip_execution='{{env.get("APP_BROKER_TYPE", "rabbitmq") != "kafka"}}' + should_execute='{{env.get("APP_BROKER_TYPE", "rabbitmq") == "kafka"}}' ) pandaproxy_plaintext_checker = PortChecker( name='check-pandaproxy-plaintext', port='{{env.get("PANDAPROXY_INTERNAL_HOST_PORT", "29092")}}', - skip_execution='{{env.get("APP_BROKER_TYPE", "rabbitmq") != "kafka"}}' + should_execute='{{env.get("APP_BROKER_TYPE", "rabbitmq") == "kafka"}}' ) pandaproxy_outside_checker = PortChecker( name='check-pandaproxy-outside', port='{{env.get("PANDAPROXY_EXTERNAL_HOST_PORT", "9092")}}', - skip_execution='{{env.get("APP_BROKER_TYPE", "rabbitmq") != "kafka"}}' + should_execute='{{env.get("APP_BROKER_TYPE", "rabbitmq") == "kafka"}}' ) app_container_checker = HTTPChecker( @@ -100,7 +100,7 @@ def skip_local_microservices_execution(*args: Any, **kwargs: Any) -> bool: url='/readiness', port='{{env.APP_PORT}}', is_https='{{input.snake_zrb_app_name_https}}', - skip_execution=skip_local_microservices_execution + should_execute=should_start_local_microservices ) ############################################################################### diff --git a/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/container.py b/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/container.py index 87dfcfba..3bae0542 100644 --- a/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/container.py +++ b/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/container.py @@ -48,8 +48,8 @@ def setup_all_compose_profile(*args: Any, **kwargs: Any) -> str: return f'export COMPOSE_PROFILES={compose_profile_str}' -def skip_execution(*args: Any, **kwargs: Any) -> bool: - return not kwargs.get('local_snake_zrb_app_name', True) +def should_execute(*args: Any, **kwargs: Any) -> bool: + return kwargs.get('local_snake_zrb_app_name', True) ############################################################################### @@ -120,7 +120,7 @@ def skip_execution(*args: Any, **kwargs: Any) -> bool: host_input, image_input, ], - skip_execution=skip_execution, + should_execute=should_execute, upstreams=[ build_snake_zrb_app_name_image, remove_snake_zrb_app_name_container @@ -150,7 +150,7 @@ def skip_execution(*args: Any, **kwargs: Any) -> bool: https_input, image_input, ], - skip_execution=skip_execution, + should_execute=should_execute, upstreams=[init_snake_zrb_app_name_container], cwd=RESOURCE_DIR, setup_cmd=setup_runtime_compose_profile, diff --git a/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/image.py b/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/image.py index 7dd1587d..8d35eea3 100644 --- a/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/image.py +++ b/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/image.py @@ -37,7 +37,7 @@ image_input, ], envs=[image_env], - skip_execution='{{not input.local_snake_zrb_app_name}}', + should_execute='{{ input.local_snake_zrb_app_name}}', cwd=RESOURCE_DIR, compose_cmd='build', compose_args=[ diff --git a/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/local.py b/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/local.py index 2afa99f7..7ea6aafb 100644 --- a/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/local.py +++ b/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/local.py @@ -3,7 +3,7 @@ from zrb.builtin.group import project_group from ._common import ( CURRENT_DIR, APP_DIR, APP_TEMPLATE_ENV_FILE_NAME, RESOURCE_DIR, - skip_local_microservices_execution, rabbitmq_checker, + should_start_local_microservices, rabbitmq_checker, rabbitmq_management_checker, redpanda_console_checker, kafka_outside_checker, kafka_plaintext_checker, pandaproxy_outside_checker, pandaproxy_plaintext_checker, app_local_checker, local_input, https_input, @@ -33,14 +33,14 @@ def setup_support_compose_profile(*args: Any, **kwargs: Any) -> str: return f'export COMPOSE_PROFILES={compose_profile_str}' -def skip_support_container_execution(*args: Any, **kwargs: Any) -> bool: - return not kwargs.get('local_snake_zrb_app_name', True) +def should_start_support_container(*args: Any, **kwargs: Any) -> bool: + return kwargs.get('local_snake_zrb_app_name', True) -def skip_local_monolith_execution(*args: Any, **kwargs: Any) -> bool: - if not kwargs.get('local_snake_zrb_app_name', True): +def should_start_local_monolith(*args: Any, **kwargs: Any) -> bool: + if kwargs.get('local_snake_zrb_app_name', True): return True - return kwargs.get('snake_zrb_app_name_run_mode', 'monolith') != 'monolith' + return kwargs.get('snake_zrb_app_name_run_mode', 'monolith') == 'monolith' ############################################################################### @@ -63,7 +63,7 @@ def skip_local_monolith_execution(*args: Any, **kwargs: Any) -> bool: host_input, image_input, ], - skip_execution=skip_support_container_execution, + should_execute=should_start_support_container, upstreams=[ remove_snake_zrb_app_name_container ], @@ -86,7 +86,7 @@ def skip_local_monolith_execution(*args: Any, **kwargs: Any) -> bool: https_input, image_input, ], - skip_execution=skip_support_container_execution, + should_execute=should_start_support_container, upstreams=[init_snake_zrb_app_name_support_container], cwd=RESOURCE_DIR, setup_cmd=setup_support_compose_profile, @@ -128,7 +128,7 @@ def skip_local_monolith_execution(*args: Any, **kwargs: Any) -> bool: host_input, https_input ], - skip_execution=skip_local_monolith_execution, + should_execute=should_start_local_monolith, upstreams=[ start_snake_zrb_app_name_support_container, build_snake_zrb_app_name_frontend, @@ -156,7 +156,7 @@ def skip_local_monolith_execution(*args: Any, **kwargs: Any) -> bool: host_input, https_input ], - skip_execution=skip_local_microservices_execution, + should_execute=should_start_local_microservices, upstreams=[ start_snake_zrb_app_name_support_container, build_snake_zrb_app_name_frontend, diff --git a/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/local_microservices.py b/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/local_microservices.py index 5a0e4cfa..f2555da9 100644 --- a/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/local_microservices.py +++ b/src/zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/local_microservices.py @@ -2,7 +2,7 @@ from zrb import CmdTask, Env, HTTPChecker, Task, EnvFile from zrb.helper.util import to_snake_case, to_kebab_case from ._common import ( - CURRENT_DIR, APP_DIR, skip_local_microservices_execution, + CURRENT_DIR, APP_DIR, should_start_local_microservices, APP_TEMPLATE_ENV_FILE_NAME, MODULES, local_input, run_mode_input, host_input, https_input, enable_monitoring_input, app_enable_otel_env @@ -25,7 +25,7 @@ def get_start_microservices(upstreams: List[Task]) -> List[Task]: https_input, enable_monitoring_input, ], - skip_execution=skip_local_microservices_execution, + should_execute=should_start_local_microservices, upstreams=upstreams, cwd=APP_DIR, env_files=[_get_service_env_file(module_name)], @@ -43,7 +43,7 @@ def get_start_microservices(upstreams: List[Task]) -> List[Task]: url='/readiness', port='{{env.APP_PORT}}', is_https='{{input.snake_zrb_app_name_https}}', - skip_execution=skip_local_microservices_execution + should_execute=should_start_local_microservices ) ] ) diff --git a/src/zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/container.py b/src/zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/container.py index 7c0f3981..8a5e3377 100644 --- a/src/zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/container.py +++ b/src/zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/container.py @@ -92,7 +92,7 @@ host_input, image_input, ], - skip_execution='{{not input.local_snake_zrb_app_name}}', + should_execute='{{ input.local_snake_zrb_app_name}}', upstreams=[ build_snake_zrb_app_name_image, remove_snake_zrb_app_name_container @@ -122,7 +122,7 @@ https_input, image_input, ], - skip_execution='{{not input.local_snake_zrb_app_name}}', + should_execute='{{ input.local_snake_zrb_app_name}}', upstreams=[init_snake_zrb_app_name_container], cwd=RESOURCE_DIR, compose_cmd='logs', diff --git a/src/zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/image.py b/src/zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/image.py index 937a415a..d22a7f77 100644 --- a/src/zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/image.py +++ b/src/zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/image.py @@ -40,7 +40,7 @@ image_input, ], envs=[image_env], - skip_execution='{{not input.local_snake_zrb_app_name}}', + should_execute='{{ input.local_snake_zrb_app_name}}', cwd=RESOURCE_DIR, compose_cmd='build', compose_flags=[ diff --git a/src/zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/local.py b/src/zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/local.py index c973cebd..4124aa52 100644 --- a/src/zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/local.py +++ b/src/zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/local.py @@ -26,7 +26,7 @@ host_input, https_input ], - skip_execution='{{not input.local_snake_zrb_app_name}}', + should_execute='{{ input.local_snake_zrb_app_name}}', cwd=APP_DIR, env_files=[app_env_file], envs=[ diff --git a/src/zrb/task/any_task.py b/src/zrb/task/any_task.py index 0d3fbe2a..e093a16b 100644 --- a/src/zrb/task/any_task.py +++ b/src/zrb/task/any_task.py @@ -69,8 +69,8 @@ def set_color(self, new_color: str): pass @abstractmethod - def set_skip_execution( - self, skip_execution: Union[bool, str, Callable[..., bool]] + def set_should_execute( + self, should_execute: Union[bool, str, Callable[..., bool]] ): pass diff --git a/src/zrb/task/base_remote_cmd_task.py b/src/zrb/task/base_remote_cmd_task.py index a3a66f90..618c736a 100644 --- a/src/zrb/task/base_remote_cmd_task.py +++ b/src/zrb/task/base_remote_cmd_task.py @@ -69,7 +69,7 @@ def __init__( max_output_line: int = 1000, max_error_line: int = 1000, preexec_fn: Optional[Callable[[], Any]] = os.setsid, - skip_execution: Union[bool, str, Callable[..., bool]] = False, + should_execute: Union[bool, str, Callable[..., bool]] = True, return_upstream_result: bool = False ): CmdTask.__init__( @@ -94,7 +94,7 @@ def __init__( max_output_line=max_output_line, max_error_line=max_error_line, preexec_fn=preexec_fn, - skip_execution=skip_execution, + should_execute=should_execute, return_upstream_result=return_upstream_result ) self._pre_cmd = pre_cmd @@ -163,7 +163,7 @@ def __init__( max_output_line: int = 1000, max_error_line: int = 1000, preexec_fn: Optional[Callable[[], Any]] = os.setsid, - skip_execution: Union[bool, str, Callable[..., bool]] = False, + should_execute: Union[bool, str, Callable[..., bool]] = True, return_upstream_result: bool = False ): sub_tasks = [ @@ -190,7 +190,7 @@ def __init__( max_output_line=max_output_line, max_error_line=max_error_line, preexec_fn=preexec_fn, - skip_execution=skip_execution, + should_execute=should_execute, return_upstream_result=return_upstream_result ) for remote_config in list(remote_configs) diff --git a/src/zrb/task/base_task.py b/src/zrb/task/base_task.py index 6ca5c015..d0f12dd0 100644 --- a/src/zrb/task/base_task.py +++ b/src/zrb/task/base_task.py @@ -51,7 +51,7 @@ def __init__( checkers: Iterable[AnyTask] = [], checking_interval: Union[float, int] = 0, run: Optional[Callable[..., Any]] = None, - skip_execution: Union[bool, str, Callable[..., bool]] = False, + should_execute: Union[bool, str, Callable[..., bool]] = True, return_upstream_result: bool = False ): # init properties @@ -78,7 +78,7 @@ def __init__( checkers=checkers, checking_interval=checking_interval, run=run, - skip_execution=skip_execution, + should_execute=should_execute, ) self._return_upstream_result = return_upstream_result # init private properties @@ -406,10 +406,8 @@ async def _cached_run(self, *args: Any, **kwargs: Any) -> Any: self._is_execution_started = True local_kwargs = dict(kwargs) local_kwargs['_task'] = self - if await self._check_skip_execution(*args, **local_kwargs): - self.log_info( - f'Skip execution because config: {self._skip_execution}' - ) + if not await self._check_should_execute(*args, **local_kwargs): + self.log_info('Skip execution') self.log_info('State: stopped') await self._mark_done() return None @@ -436,12 +434,12 @@ async def _cached_run(self, *args: Any, **kwargs: Any) -> Any: self.log_info('State: stopped') return result - async def _check_skip_execution(self, *args: Any, **kwargs: Any) -> bool: - if callable(self._skip_execution): - if inspect.iscoroutinefunction(self._skip_execution): - return await self._skip_execution(*args, **kwargs) - return self._skip_execution(*args, **kwargs) - return self.render_bool(self._skip_execution) + async def _check_should_execute(self, *args: Any, **kwargs: Any) -> bool: + if callable(self._should_execute): + if inspect.iscoroutinefunction(self._should_execute): + return await self._should_execute(*args, **kwargs) + return self._should_execute(*args, **kwargs) + return self.render_bool(self._should_execute) async def _set_keyval(self, kwargs: Mapping[str, Any], env_prefix: str): # if input is not in input_map, add default values diff --git a/src/zrb/task/base_task_composite.py b/src/zrb/task/base_task_composite.py index 1210f7a8..7a5ac076 100644 --- a/src/zrb/task/base_task_composite.py +++ b/src/zrb/task/base_task_composite.py @@ -44,7 +44,7 @@ def __init__( checkers: Iterable[AnyTask] = [], checking_interval: Union[float, int] = 0, run: Optional[Callable[..., Any]] = None, - skip_execution: Union[bool, str, Callable[..., bool]] = False + should_execute: Union[bool, str, Callable[..., bool]] = True ): self._name = name self._group = group @@ -62,7 +62,7 @@ def __init__( self._checkers = checkers self._checking_interval = checking_interval self._run_function: Optional[Callable[..., Any]] = run - self._skip_execution = skip_execution + self._should_execute = should_execute self._allow_add_envs = True self._allow_add_env_files = True self._allow_add_inputs = True @@ -84,10 +84,10 @@ def set_color(self, new_color: str): def set_retry(self, new_retry: int): self._retry = new_retry - def set_skip_execution( - self, skip_execution: Union[bool, str, Callable[..., bool]] + def set_should_execute( + self, should_execute: Union[bool, str, Callable[..., bool]] ): - self._skip_execution = skip_execution + self._should_execute = should_execute def set_retry_interval(self, new_retry_interval: Union[float, int]): self._retry_interval = new_retry_interval @@ -352,8 +352,7 @@ def __init__( checkers: Iterable[AnyTask] = [], checking_interval: Union[int, float] = 0, run: Optional[Callable[..., Any]] = None, - skip_execution: Union[bool, str, Callable[..., bool]] = False - + should_execute: Union[bool, str, Callable[..., bool]] = True ): self._filled_complete_name: Optional[str] = None self._has_cli_interface = False @@ -374,7 +373,7 @@ def __init__( checkers=checkers, checking_interval=checking_interval, run=run, - skip_execution=skip_execution, + should_execute=should_execute, ) PidModel.__init__(self) TimeTracker.__init__(self) diff --git a/src/zrb/task/cmd_task.py b/src/zrb/task/cmd_task.py index 4327e6c5..562da681 100644 --- a/src/zrb/task/cmd_task.py +++ b/src/zrb/task/cmd_task.py @@ -108,7 +108,7 @@ def __init__( max_output_line: int = 1000, max_error_line: int = 1000, preexec_fn: Optional[Callable[[], Any]] = os.setsid, - skip_execution: Union[bool, str, Callable[..., bool]] = False, + should_execute: Union[bool, str, Callable[..., bool]] = True, return_upstream_result: bool = False ): BaseTask.__init__( @@ -126,7 +126,7 @@ def __init__( checking_interval=checking_interval, retry=retry, retry_interval=retry_interval, - skip_execution=skip_execution, + should_execute=should_execute, return_upstream_result=return_upstream_result ) max_output_line = max_output_line if max_output_line > 0 else 1 diff --git a/src/zrb/task/decorator.py b/src/zrb/task/decorator.py index d6f5fbae..4677ce5d 100644 --- a/src/zrb/task/decorator.py +++ b/src/zrb/task/decorator.py @@ -26,7 +26,7 @@ def python_task( checking_interval: float = 0.1, retry: int = 2, retry_interval: float = 1, - skip_execution: Union[bool, str, Callable[..., bool]] = False, + should_execute: Union[bool, str, Callable[..., bool]] = True, return_upstream_result: bool = False, runner: Optional[Runner] = None ) -> Callable[[Callable[..., Any]], Task]: @@ -46,7 +46,7 @@ def _create_task(fn: Callable[..., Any]) -> Task: retry=retry, retry_interval=retry_interval, run=fn, - skip_execution=skip_execution, + should_execute=should_execute, return_upstream_result=return_upstream_result ) if runner is not None: diff --git a/src/zrb/task/docker_compose_task.py b/src/zrb/task/docker_compose_task.py index 9ead401a..eac83d5b 100644 --- a/src/zrb/task/docker_compose_task.py +++ b/src/zrb/task/docker_compose_task.py @@ -79,7 +79,7 @@ def __init__( max_output_line: int = 1000, max_error_line: int = 1000, preexec_fn: Optional[Callable[[], Any]] = os.setsid, - skip_execution: Union[bool, str, Callable[..., bool]] = False, + should_execute: Union[bool, str, Callable[..., bool]] = True, return_upstream_result: bool = False ): combined_env_files = list(env_files) @@ -103,7 +103,7 @@ def __init__( max_output_line=max_output_line, max_error_line=max_error_line, preexec_fn=preexec_fn, - skip_execution=skip_execution, + should_execute=should_execute, return_upstream_result=return_upstream_result ) self._setup_cmd = setup_cmd diff --git a/src/zrb/task/flow_task.py b/src/zrb/task/flow_task.py index b53d69e5..f45f6583 100644 --- a/src/zrb/task/flow_task.py +++ b/src/zrb/task/flow_task.py @@ -32,7 +32,7 @@ def __init__( retry: int = 2, retry_interval: float = 1, steps: List[Union[AnyTask, List[AnyTask]]] = [], - skip_execution: Union[bool, str, Callable[..., bool]] = False, + should_execute: Union[bool, str, Callable[..., bool]] = True, return_upstream_result: bool = False ): final_upstreams: List[AnyTask] = list(upstreams) @@ -64,7 +64,7 @@ def __init__( checking_interval=checking_interval, retry=retry, retry_interval=retry_interval, - skip_execution=skip_execution, + should_execute=should_execute, return_upstream_result=return_upstream_result, run=lambda *args, **kwargs: kwargs.get('_task').print_out('🆗') ) diff --git a/src/zrb/task/http_checker.py b/src/zrb/task/http_checker.py index 8ef12389..45f946aa 100644 --- a/src/zrb/task/http_checker.py +++ b/src/zrb/task/http_checker.py @@ -35,7 +35,7 @@ def __init__( upstreams: Iterable[AnyTask] = [], checking_interval: float = 0.1, show_error_interval: float = 5, - skip_execution: Union[bool, str, Callable[..., bool]] = False + should_execute: Union[bool, str, Callable[..., bool]] = True ): BaseTask.__init__( self, @@ -52,7 +52,7 @@ def __init__( checking_interval=checking_interval, retry=0, retry_interval=0, - skip_execution=skip_execution + should_execute=should_execute ) self._host = host self._port = port diff --git a/src/zrb/task/path_checker.py b/src/zrb/task/path_checker.py index 1096798a..8395b987 100644 --- a/src/zrb/task/path_checker.py +++ b/src/zrb/task/path_checker.py @@ -30,7 +30,7 @@ def __init__( upstreams: Iterable[AnyTask] = [], checking_interval: float = 0.1, show_error_interval: float = 5, - skip_execution: Union[bool, str, Callable[..., bool]] = False + should_execute: Union[bool, str, Callable[..., bool]] = True ): BaseTask.__init__( self, @@ -47,7 +47,7 @@ def __init__( checking_interval=checking_interval, retry=0, retry_interval=0, - skip_execution=skip_execution, + should_execute=should_execute, ) self._path = path self._show_error_interval = show_error_interval diff --git a/src/zrb/task/port_checker.py b/src/zrb/task/port_checker.py index 8fa07bc4..85812ba8 100644 --- a/src/zrb/task/port_checker.py +++ b/src/zrb/task/port_checker.py @@ -32,7 +32,7 @@ def __init__( upstreams: Iterable[AnyTask] = [], checking_interval: float = 0.1, show_error_interval: float = 5, - skip_execution: Union[bool, str, Callable[..., bool]] = False + should_execute: Union[bool, str, Callable[..., bool]] = True ): BaseTask.__init__( self, @@ -49,7 +49,7 @@ def __init__( checking_interval=checking_interval, retry=0, retry_interval=0, - skip_execution=skip_execution, + should_execute=should_execute, ) self._host = host self._port = port diff --git a/src/zrb/task/remote_cmd_task.py b/src/zrb/task/remote_cmd_task.py index 65e36643..7c564af3 100644 --- a/src/zrb/task/remote_cmd_task.py +++ b/src/zrb/task/remote_cmd_task.py @@ -52,7 +52,7 @@ def __init__( max_output_line: int = 1000, max_error_line: int = 1000, preexec_fn: Optional[Callable[[], Any]] = os.setsid, - skip_execution: Union[bool, str, Callable[..., bool]] = False + should_execute: Union[bool, str, Callable[..., bool]] = True ): pre_cmd = '\n'.join([ SSH_UTIL_SCRIPT, @@ -88,7 +88,7 @@ def __init__( max_output_line=max_output_line, max_error_line=max_error_line, preexec_fn=preexec_fn, - skip_execution=skip_execution + should_execute=should_execute ) def __repr__(self) -> str: diff --git a/src/zrb/task/resource_maker.py b/src/zrb/task/resource_maker.py index 71902786..2b3e0ae5 100644 --- a/src/zrb/task/resource_maker.py +++ b/src/zrb/task/resource_maker.py @@ -41,7 +41,7 @@ def __init__( color: Optional[str] = None, description: str = '', upstreams: Iterable[AnyTask] = [], - skip_execution: Union[bool, str, Callable[..., bool]] = False, + should_execute: Union[bool, str, Callable[..., bool]] = True, skip_parsing: Optional[Iterable[str]] = None ): BaseTask.__init__( @@ -59,7 +59,7 @@ def __init__( checking_interval=0.1, retry=0, retry_interval=0, - skip_execution=skip_execution + should_execute=should_execute ) self._template_path = template_path self._destination_path = destination_path diff --git a/src/zrb/task/rsync_task.py b/src/zrb/task/rsync_task.py index 2ce2d547..8539e00b 100644 --- a/src/zrb/task/rsync_task.py +++ b/src/zrb/task/rsync_task.py @@ -55,7 +55,7 @@ def __init__( max_output_line: int = 1000, max_error_line: int = 1000, preexec_fn: Optional[Callable[[], Any]] = os.setsid, - skip_execution: Union[bool, str, Callable[..., bool]] = False + should_execute: Union[bool, str, Callable[..., bool]] = True ): parsed_src = self._get_parsed_path(is_remote_src, src) parsed_dst = self._get_parsed_path(is_remote_dst, dst) @@ -83,7 +83,7 @@ def __init__( max_output_line=max_output_line, max_error_line=max_error_line, preexec_fn=preexec_fn, - skip_execution=skip_execution + should_execute=should_execute ) def _get_parsed_path(self, is_remote: bool, path: str) -> str: diff --git a/test/task/test_task.py b/test/task/test_task.py index fce366d8..15050da3 100644 --- a/test/task/test_task.py +++ b/test/task/test_task.py @@ -28,14 +28,14 @@ def _run(*args, **kwargs) -> str: assert result == 'hello' -def test_task_with_skip_execution(): +def test_task_with_should_execute_equal_to_false(): def _run(*args, **kwargs) -> str: return 'hello' task = Task( name='hello', run=_run, retry=0, - skip_execution=True + should_execute=False ) function = task.to_function() result = function() diff --git a/zrb_init.py b/zrb_init.py index 2fb8331c..0c7d5b28 100644 --- a/zrb_init.py +++ b/zrb_init.py @@ -100,7 +100,7 @@ ) skippable_build: CmdTask = build.copy() skippable_build.add_inputs(build_zrb_input) -skippable_build.set_skip_execution('{{ not input.build_zrb}}') +skippable_build.set_should_execute('{{ input.build_zrb}}') runner.register(build) publish_pip = CmdTask( @@ -277,7 +277,7 @@ build_zrb_input, install_symlink_input ) -skippable_install_symlink.set_skip_execution('{{ not input.install_symlink}}') +skippable_install_symlink.set_should_execute('{{ input.install_symlink}}') runner.register(install_symlink) test = CmdTask( @@ -347,7 +347,7 @@ install_symlink_input, create_playground_input ) -skippable_create_playground.set_skip_execution('{{ not input.create_playground}}') # noqa +skippable_create_playground.set_should_execute('{{ input.create_playground}}') runner.register(create_playground) test_fastapp_playground = CmdTask(