kestra-io / kestra

:zap: Workflow Automation Platform. Orchestrate & Schedule code in any language, run anywhere, 500+ plugins. Alternative to Zapier, Rundeck, Camunda, Airflow...
https://kestra.io
Apache License 2.0
11.98k stars 1.01k forks source link

Trigger toggle doesn't work if the trigger interval is small #3705

Open johnkm516 opened 5 months ago

johnkm516 commented 5 months ago

Describe the issue

My flow is an SQL Server trigger which queries the DB for certain rows. The trigger is set to 3 seconds, as the flow won't trigger if there are no rows in the output of the select query.

If the flow is continuously being triggered at an interval of 3 seconds, and I use the Kestra UI to disable the trigger (toggle off), it does not save properly. Despite me toggling off the trigger multiple times.

Per my tests, this happens if a triggered flow is still currently running. If a triggered flow is still running, the Kestra UI refuses to disable the trigger. You have to wait until all flows with the trigger finishes, which is impossible if the trigger is continuously triggering new flows. To fix it, I have to edit the flow to make the trigger interval > the time it would take to complete all the flows that has been triggered, wait until the flows are complete, then toggle off the trigger.

Minimal reproducible example :

id: triggertest
namespace: dev

labels:
  env: dev

tasks:

  - id: wait
    type: io.kestra.plugin.scripts.shell.Commands
    commands:
      - sleep 10
    runner: PROCESS
  - id: print_status
    type: io.kestra.core.tasks.log.Log
    message: hello

triggers:
  - id: query
    type: io.kestra.plugin.jdbc.sqlserver.Trigger
    fetch: true
    fetchSize: 30
    interval: PT3S
    password: <password?
    sql: "SELECT TOP(30) * FROM TEST_TABLE\r\n"
    stopAfter:
      - FAILED
      - WARNING
    url: jdbc:sqlserver://<uri>
    username: <username>

Environment

johnkm516 commented 3 months ago

I believe this is a UI issue. When the trigger is small, the trigger lock button in many cases does not appear beside the trigger toggle. The user can toggle the trigger off in the UI, but the change does not save properly.

Ben8t commented 1 month ago

@MilosPaunovic here is a reproducer with no external service (I'm using docker-compose here, so maybe you want to change the postgres information connection in the trigger)

id: triggertest
namespace: dev

labels:
  env: dev

tasks:

  - id: wait
    type: io.kestra.plugin.scripts.shell.Commands
    commands:
      - sleep 10
  - id: print_status
    type: io.kestra.plugin.core.log.Log
    message: hello

triggers:
  - id: query
    type: io.kestra.plugin.jdbc.postgresql.Trigger
    fetch: true
    fetchSize: 30
    interval: PT3S
    password: k3str4
    sql: "select *from pg_namespace"
    stopAfter:
      - FAILED
      - WARNING
    url: jdbc:postgresql://postgres:5432/kestra
    username: kestra

As @johnkm516 mentioned, when the flow is triggered, if you switch the trigger toggle off, new executions are still triggered

MilosPaunovic commented 1 month ago

This seems like it is not handled as expected on the BE side. I use the flow Ben provided:

id: triggertest
namespace: github

labels:
  env: dev

tasks:
  - id: wait
    type: io.kestra.plugin.scripts.shell.Commands
    commands:
      - sleep 10
  - id: print_status
    type: io.kestra.plugin.core.log.Log
    message: hello

triggers:
  - id: query
    type: io.kestra.plugin.jdbc.postgresql.Trigger
    fetch: true
    fetchSize: 30
    interval: PT3S
    password: k3str4
    sql: "select * from pg_namespace"
    stopAfter:
      - FAILED
      - WARNING
    url: jdbc:postgresql://localhost:5432/kestra_unit
    username: kestra

And on triggers tab request is sent to disable it, in response there is disabled: true property, but it seems like it is ignored for some reason, as when I switch tabs back to Executions, new ones are being triggered, and when I get back to Triggers, it shows it as enabled.

Skraye commented 1 month ago

I can not reproduce on 0.18.7, with PostgresSQL @MilosPaunovic what was your backend when testing ?

MilosPaunovic commented 1 month ago

@Skraye PostgresSQL running on Docker and regular Java app running from IntelliJ.

Skraye commented 1 month ago

@Ben8t @johnkm516 Are you still able to reproduce it ?

Ben8t commented 4 weeks ago

@Skraye the reproducer I've provided doesn't trigger anything anymore 🤔 (0.19.1) Got this from trigger logs

image

btw, this task return results:

  - id: query
    type: io.kestra.plugin.jdbc.postgresql.Query
    password: k3str4
    sql: "select *from pg_namespace"
    url: jdbc:postgresql://postgres:5432/kestra
    username: kestra
    store: true

Don't see any issue open related to this, do you think something wrong's going on here ?