Thread
#prefect-community
    yu zeng

    yu zeng

    2 months ago
    from prefect.storage import GitHub,GitLab, S3, Webhook
    
    from prefect.backend.artifacts import create_link_artifact
    import prefect.engine.cache_validators
    
    
    @task( task_run_name="mviz_task_{md5}", max_retries=0, cache_for=datetime.timedelta(hours=1),
          )
    def test( md5,   ):
        print('do test', md5 )
        
    
    with Flow("epl" ) as flow:
        test( '123' )
        test( '123' )
    flow.run()
    hi, i try to use cache in a single flow run, but i got the belllow output which shows that cache not work. it seems that cache will not work durning same flow run or there are some mistakes in my code ?
    [2022-07-15 12:18:00+0000] INFO - prefect.FlowRunner | Beginning Flow run for 'epl'
    [2022-07-15 12:18:00+0000] INFO - prefect.TaskRunner | Task 'test': Starting task run...
    [2022-07-15 12:18:00+0000] WARNING - prefect.TaskRunner | Task 'test': Can't use cache because it is now invalid
    do test 123
    [2022-07-15 12:18:00+0000] INFO - prefect.TaskRunner | Task 'test': Finished task run for task with final state: 'Cached'
    [2022-07-15 12:18:00+0000] INFO - prefect.TaskRunner | Task 'test': Starting task run...
    [2022-07-15 12:18:00+0000] WARNING - prefect.TaskRunner | Task 'test': Can't use cache because it is now invalid
    do test 123
    [2022-07-15 12:18:00+0000] INFO - prefect.TaskRunner | Task 'test': Finished task run for task with final state: 'Cached'
    [2022-07-15 12:18:00+0000] INFO - prefect.FlowRunner | Flow run SUCCESS: all reference tasks succeeded
    Anna Geller

    Anna Geller

    2 months ago
    can you move code blocks to the thread?
    it looks like your cache did work:
    Finished task run for task with final state: 'Cached'
    the idea behind caching is well explained here

    https://www.youtube.com/watch?v=hKcOdQD9eGQ

    yu zeng

    yu zeng

    2 months ago

    it looks like your cache did work:

    thank u anna, but why the output "do test 123" show twice?

    can you move code blocks to the thread?

    i'd like to do that but i don't know how to move ( rarely to use slack )
    Anna Geller

    Anna Geller

    2 months ago
    that's fine then