Custom Trigger Monthly Open Days

Sylvie
Sylvie Registered Posts: 4

Hello,

I'm trying to launch scenario with custom trigger the first open day of each month. Did someone could help me on that ?

Thanks

Best Answer

  • Sylvie
    Sylvie Registered Posts: 4
    Answer ✓

    I finallly found the solution :


    from dataiku.scenario import Trigger
    import pandas as pd
    from datetime import date , datetime
    import pytz


    t = Trigger()

    liste= pd.date_range('1/1/2023',periods=100, freq='BMS')


    tz = pytz.timezone('Europe/Paris')


    hour = datetime.now(tz = tz).hour


    if date.today() in liste and hour>9 :
    t.fire()

Answers

  • Ioannis
    Ioannis Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 28 ✭✭✭✭✭

    You can use this library. You can see some examples here as well.

    import dataikuapi
    import dataiku
    from dataiku.scenario import Trigger
    import datetime


    # 1st approach
    client = dataiku.api_client()
    project = client.get_project("your_project")

    scenario = project.get_scenario("myscenario")
    trigger_fire = scenario.run()

    if today ==1:
    scenario_run = trigger_fire.wait_for_scenario_run()


    # 2nd approach
    t = Trigger()
    today = datetime.datetime.today().day
    if today == 1:
    t.fire()
  • Sylvie
    Sylvie Registered Posts: 4

    Thanks for your help, but my problem is to run the scenario the first OPEN day of the month. So if the first is a sunday, the scenario should run the 2nd, monday.

  • Miguel Angel
    Miguel Angel Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 118 Dataiker
    edited July 17

    Hi,

    I suspect that by open day you actually mean business day?

    If so you can take advantage of pandas date_range method. In your custom python trigger you could input.

    from dataiku.scenario import Trigger
    import pandas as pd
    from datetime import date
    t = Trigger()
    if date.today() in pd.date_range('1/1/2023', '12/1/2023', freq='BMS')
      t.fire()

Setup Info
    Tags
      Help me…