Forum Discussion

JamesCarr's avatar
JamesCarr
Qrew Cadet
19 hours ago

Pipeline Jinja For Duration in Seconds

I would like to have a pipeline condition where nothing happens if the current time is less than or equal to 30 seconds from the value in a given field, which is a date/time field. I have tried multiple variations of jinja code and mostly get the error message:

Validation error: Incorrect template "whatever my jinja is". ValueError: invalid literal for int() with base 10: 'my_date_time_field_name'

I have tried subtracting and converting the time.now and my field to an integer before comparing to 30 for seconds, I tried using time.delta(seconds=30) and adding it to the date field then comparing it to the current time, and some other things. I get the above error each time. I would really like to do this with Jinja, if at all possible. If anyone can help, that would be greatly appreciated. I know, worse comes to worst, I can add a helper field and just work off of that,  but I am doing this for learning purposes. 

Thank you in advance to anyone who can help. 

4 Replies

  • Mez's avatar
    Mez
    Qrew Assistant Captain

    In pipelines you're getting/viewing/working with the raw datetime value in utc time from your datetime field. You should be able to just compare your datetime field to less than 30 seconds ago in an expression, if you're using a conditional, or even a filter. 

    In this example, if the start datetime value from the record is within 30 seconds, then follow the true path. This is within a conditional step using expression - evaluates to true:

    {% if a.start_date_time >= time.now - time.delta(seconds=30) %}
    true
    {% endif %}

    Hope this helps. 

  • I tried something very similar to this. I just now tried to do precisely what you have and it is still giving me that error message. 

  • Mez's avatar
    Mez
    Qrew Assistant Captain

    Interesting. Can you share a screenshot? 

    And, I just thought of this... you could actually just perform subtraction directly against the datetime field from time.now. With this, if you extract the seconds from the datetime object from subtracting the two values and it's less than 30, true is used, otherwise, you can print the seconds property from the subtraction; which most likely will still result in true unless the pipeline triggers and the subtraction results in zero. 

    {% if (time.now - a.start_date_time).seconds <= 30 %}
    true
    {% else %}
    {{ (time.now - a.start_date_time).seconds }}
    {% endif %}

     

  • Simply just trying to populate the value in my email sent date field into this text field using an update record step generates this error:

    Validation error: Incorrect template "{{b.email_sent_date}}". ValueError: invalid literal for int() with base 10: 'email_sent_date'

    I am assuming it just has to be converted since this is a text field I am trying to update. Even with the attempt to use the condition step, I am assuming it has to be converted. I have made attempts to do that as well, with no success.