Custom python trigger time-conditioned won't launch Scenario

Options
onevirtual
onevirtual Registered, Dataiku Frontrunner Awards 2021 Winner, Dataiku Frontrunner Awards 2021 Finalist, Dataiku Frontrunner Awards 2021 Participant Posts: 4 ✭✭✭✭
edited July 16 in Using Dataiku

So I went to the dataiku academy and built my custom trigger with the template provided in order to run my scenario on week-days at business hours. Which resulted eventually in this code :

from dataiku.scenario import Trigger
from datetime import date
from datetime import datetime

t = Trigger()
aujourdhui = date.today()
heure = datetime.today()
heure_actuelle = heure.hour

if aujourdhui.weekday() >= 0 and aujourdhui.weekday() < 5:
    if heure_actuelle > 8 and heure_actuelle < 21:
        t.fire()

Problem is, this code won't trigger the scenario. According to the template I built this code on, there are no reasons why this trigger won't launch the scenario. For info, the scenario is within the project I 'use'/write the custom trigger. I left the 3600 seconds (run every seconds parameter) to default.

I tried to use a time based trigger which effectively launched at a certain time of the hour, but I thought it would work the same way according to the conditions in the code above.

Please, can you provide an explanation why this code won't launch my scenario every hour and see if the conditions are met ?

PS : Obvsiouly I tried it within the time span the conditions are based on.

Best Answer

  • AurelienD
    AurelienD Dataiker Posts: 3 Dataiker
    Answer ✓
    Options

    Hello,

    Did you ticked the little checkbox "Auto-triggers"?Screen Shot 2021-03-02 at 3.51.32 PM.png

    To debug your custom trigger, you can reduce the "Run Every", put some print and check in the log if you see your message.

Answers

  • onevirtual
    onevirtual Registered, Dataiku Frontrunner Awards 2021 Winner, Dataiku Frontrunner Awards 2021 Finalist, Dataiku Frontrunner Awards 2021 Participant Posts: 4 ✭✭✭✭
    Options

    Hello, thank you for the fast reply. The problem was due to my understanfing of the run every (3600 s) function, which I thought would work like that (immediatly run while active on is ticked and run every default seconds after). Instead, I understand now that the function is coded to have a starttime run with the latency of variable equals to parameter variable from actual time.

    I will mark the issue as resolved thank you (:

  • RinkaDink
    RinkaDink Registered Posts: 3 ✭✭✭
    Options

    Good Morning,

    I want the same as Onevirtual. The custom Trigger should trigger (fire) monday to friday every 3 hours between 8 am and 5 pm.

    I dient clearly understand the Response and appreciate If you can post Code and what to set in run every or Grace delay

    Thanks

  • pkansal
    pkansal Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Registered Posts: 23 ✭✭✭✭
    Options

    Hi,

    I have configured my trigger just like above. I put the run every seconds at 60. But my trigger will not trigger at all.

  • Harry
    Harry Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 9
    Options

    Hello,
    I am confronted in the same problem.

    I have create a custpm trigger:

    ```

    from dataiku.scenario import Trigger
    from datetime import datetime, date
    import dataiku

    from loguru import logger

    # Run every seconds: 10800 = 3600 x 3 = 3 hours

    t = Trigger()
    execution_date = date.today()
    logger.info(f"execution_date: {execution_date}")
    now = datetime.today()
    logger.info(f"now: {now}")
    execution_hour = now.hour
    logger.info(f"execution_hour: {execution_hour}")

    date_format = "%d-%m-%Y"

    update_date_str = dataiku.get_custom_variables().get("update_date")
    if update_date_str:
    update_date = datetime.strptime(update_date_str, date_format)
    logger.info(f"update_date: {update_date}")
    else:
    update_date = (datetime.fromtimestamp(0)).date()
    logger.info(f"update_date: {update_date}")

    delta_days = execution_date - update_date
    logger.info(f"delta_days: {delta_days}")

    # lire la date d'update stockée en tant que variable globale
    weekday_execution = execution_date.weekday()
    logger.info(f"weekday_execution: {weekday_execution}")
    if weekday_execution < 2: # lundi 0, mardi 1 value: 2
    # 5 execution par jour 8,11,14,17,20
    if execution_hour >= 8 and execution_hour =< 20:
    if delta_days > 3:
    t.fire()
    ```

    i have added a step : Build only this dataset

    first test: Run every seconds : 60, la the scenario was never launched (Auto-triggers: on and custom trigger: on)

    second test: I have added the second Time based trigger and activate it. The script launched even the condition in the custom trigger not verified.

    can someone help me ?

    Thanks

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,717 Neuron
    Options

    Please start a new thread and post your code under a code block (the </> icon on the toolbar). Without proper padding it's imposible to copy/paste your code to reproduce the issue.

Setup Info
    Tags
      Help me…