Skip to content

Commit

Permalink
use should_execute instead of skip_execution
Browse files Browse the repository at this point in the history
  • Loading branch information
goFrendiAsgard committed Oct 19, 2023
1 parent b8fffd9 commit f14d629
Show file tree
Hide file tree
Showing 32 changed files with 96 additions and 102 deletions.
8 changes: 4 additions & 4 deletions docs/concepts/tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -398,7 +398,7 @@ Deep copy current task

## `set_color`

## `set_skip_execution`
## `set_should_execute`

## `set_retry`

Expand Down
3 changes: 0 additions & 3 deletions project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
8 changes: 4 additions & 4 deletions src/zrb/builtin/generator/app_generator/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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'),
Expand All @@ -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
Expand All @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'


###############################################################################
Expand All @@ -45,45 +45,45 @@ 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(
name='check-redpanda-console',
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(
Expand All @@ -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
)

###############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)


###############################################################################
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'


###############################################################################
Expand All @@ -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
],
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)],
Expand All @@ -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
)
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
4 changes: 2 additions & 2 deletions src/zrb/task/any_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit f14d629

Please sign in to comment.