Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the number of task in the queue #64

Open
enzezhang opened this issue May 25, 2021 · 20 comments
Open

Check the number of task in the queue #64

enzezhang opened this issue May 25, 2021 · 20 comments

Comments

@enzezhang
Copy link

I am a user of gee_tools. I usually export image collection to google drive. However, when the number of the task in the queue is large than 3000, the program will be halted. I wonder if there is any way to check the number of the task in the queue and pause the program when the number is large?

Thanks for your kind help and looking forward to your reply.

Best,
Enze

@fitoprincipe
Copy link
Member

Hi @enzezhang ! Yes, that is a limit imposed by GEE. I think it's a good idea, I'd need to think how to implement it. Thanks =)

@enzezhang
Copy link
Author

Hi @fitoprincipe, I have made some changes to imagecollection.py. The mean purpose is to check the status of the last task every 10 seconds (it could be longer) after a series of tasks were submitted. When the last task becomes "COMPLETED", the program will keep moving.

after line 79, I add:
if n%20==0 and n>19:
while True:
ID=tasklist[n-2].id
status=ee.data.getTaskStatus(ID)
state=status[0].get('state')
if state=="COMPLETED":
break
else:
print("waiting, check on %s"%time.ctime())
time.sleep(10)

@enzezhang
Copy link
Author

Hope my changes would be useful to you and others.

@aadityaverma
Copy link

Hi @fitoprincipe, I have made some changes to imagecollection.py. The mean purpose is to check the status of the last task every 10 seconds (it could be longer) after a series of tasks were submitted. When the last task becomes "COMPLETED", the program will keep moving.

after line 79, I add: if n%20==0 and n>19: while True: ID=tasklist[n-2].id status=ee.data.getTaskStatus(ID) state=status[0].get('state') if state=="COMPLETED": break else: print("waiting, check on %s"%time.ctime()) time.sleep(10)

whats the corrent indentation for the above code snippet and what is the assigned value for variable 'n ' ?

@enzezhang
Copy link
Author

enzezhang commented May 27, 2022 via email

@fitoprincipe
Copy link
Member

Hi @fitoprincipe, I have made some changes to imagecollection.py. The mean purpose is to check the status of the last task every 10 seconds (it could be longer) after a series of tasks were submitted. When the last task becomes "COMPLETED", the program will keep moving.

after line 79, I add: if n%20==0 and n>19: while True: ID=tasklist[n-2].id status=ee.data.getTaskStatus(ID) state=status[0].get('state') if state=="COMPLETED": break else: print("waiting, check on %s"%time.ctime()) time.sleep(10)

Hi @enzezhang , is this in a pull requests??

@enzezhang
Copy link
Author

enzezhang commented May 27, 2022 via email

@fitoprincipe
Copy link
Member

what if there are other tasks running??? I think the code should cover that...

@enzezhang
Copy link
Author

There will be a lot of tasks running at the same time, but the number of tasks that are running cannot be too large. Therefore, I set a while loop to check the states the last task that is running currently. If that task is finished, the code will move on to the rest of the list. Otherwise, the code will be stopped until that task is finished. The code will not touch any job that is running, it will only check the status of the task and tell the code to wait. The break is only for the while loop that checks the job status, it will not stop the entire code.

@enzezhang
Copy link
Author

I've used this code for a while and it works fine.

@enzezhang
Copy link
Author

Also, the number 20 can be changed to any number as long as the number is not close to 3000.

@enzezhang
Copy link
Author

“Otherwise, the code will be stopped until that task is finished.” By "stopped", I mean waiting.

@fitoprincipe
Copy link
Member

This would be my approach: 3d67fb5. I tested it and works fine

@enzezhang
Copy link
Author

enzezhang commented May 27, 2022 via email

@fitoprincipe
Copy link
Member

fitoprincipe commented May 27, 2022

You can test it and see if it works as expected.. if it does I can populate the code to the other functions and finally merge and release..

@enzezhang
Copy link
Author

enzezhang commented May 27, 2022 via email

@fitoprincipe
Copy link
Member

You are right @enzezhang. I've already modified it, you can check it now. I have migrated the functions to utils so I can use them in the other functions. Thanks =)

@enzezhang
Copy link
Author

enzezhang commented May 28, 2022 via email

@fitoprincipe
Copy link
Member

fitoprincipe commented May 28, 2022

🤔 I've created a mock for testing: https://gist.github.com/fitoprincipe/09d4c24050cd971be475b41790a3f462
Have a look and let me know. I've added some comments to understand the flow. I think it works as expected.
You can also test it here: https://replit.com/@RodrigoPrincipe/exportimagecollectionmock#main.py

@enzezhang
Copy link
Author

enzezhang commented May 29, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants