Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy global dynamic variable #1240

Open
lockieluke opened this issue Jun 26, 2023 · 1 comment
Open

Lazy global dynamic variable #1240

lockieluke opened this issue Jun 26, 2023 · 1 comment
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@lockieluke
Copy link

Only load global variables with SH when the task needs it:

version: '3'
vars:
  MESSAGE:
    sh: sleep 5 && echo "WORLD"

tasks:
  print:
    cmds:
      - echo "HELLO {{.MESSAGE}}"

  print-no-wait:
    cmds:
      - echo "PRINT THIS INSTANTLY"

Other tasks that don't need the variable should not have it loaded

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Jun 26, 2023
@vctls
Copy link

vctls commented Oct 24, 2023

Just noticed that global dynamic variables are evaluated each time a task is run.
This can indeed become a performance problem. It could at least be documented.

I don't see many workarounds in the meantime.
Commands that take time should not be used in global dynamic variables but rather sub-commands or task dependencies.
Or, you could add conditions in the expression itself. Local variables aren't available, but, for example, the TASK variable is:

vars:
  FOO:
    sh: |-
      {{ if .TASK | contains "bar" }}sleep 2 && echo baz{{end}}

This is kind of ugly and cumbersome, but can be used with task namespaces in order to confine the problem to the tasks that actually need that variable.
I suppose long running command results could also be cached, when possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs triage Waiting to be triaged by a maintainer.
Projects
None yet
Development

No branches or pull requests

3 participants