Tell me, when executing the construction with case...
# ask-community
s
Tell me, when executing the construction with case(list_check(new_events), True): ... with case(list_check(new_events), False): .... My task returns False, but for some reason everything that is in the case is not executed,writes skipped
a
@Sergey I think you would need to call the task before the
with case
context manager. So instead of `with case(list_check(new_events), False)`: it would be:
Copy code
condition = list_check(new_events)
with case(condition, False):
    some_task_on_false()
To explain the difference: •
with case(list_check(new_events), False)
- this passes a task to the case() •
with case(condition, False)
- this passes data that is a result of the list_check task
s
Copy code
#Если списко не пустой
            tf = list_check(new_events)
            with case(tf, False):

                range_date = pd.date_range(start='2021-08-01', end=datetime.today(), freq='MS') #получаем диапазон месяцкв, с которых необходимо выгрзуить данные
                for date in range_date:
                    
                    new_events_in_app = extract_clickhouse(track_id, events, date, 'event', new_events)
                    tf2 = list_check(new_events)
                    with case(tf2, False):

                        next
                    tf2 = list_check(new_events)
                    with case(tf2, True):

                        merge_data = merge(new_events_in_app, ab_users)
                        load_data(merge_data)

                events_in_app = filter_df(events_in_app, new_events)
                merge_data = merge(events_in_app, ab_users)
                load_data(merge_data)

            tf = list_check(new_events)
            with case(tf, True):
                #Если список пустой, то загружаем суточные данные
                logs(events_in_app)
                merge_data = merge(events_in_app, ab_users)
                load_data(merge_data)
@Anna Geller that doesn't work either
Copy code
@task(name='list_check')      
def list_check(new_event_list):
    tf = len(new_event_list) == 0
    return tf
@Anna Geller moreover, before this I have the condition
Copy code
with case (date_check (end_date), True):
with case (date_check (end_date), False):
And it successfully fulfills
a
What do you see when you run flow.visualize()? Does the flow structure look as you would expect?
k
I think this is because
case
will raise a
SKIP
flag when the condition is not met. SKIP will propagate to downstream tasks. If you need something to run, you can use the
always_run
trigger.
upvote 1