Created
May 28, 2022 18:27
-
-
Save fitoprincipe/09d4c24050cd971be475b41790a3f462 to your computer and use it in GitHub Desktop.
Mock Exporting an ImageCollection in GEE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Sat May 28 15:05:46 2022 | |
@author: Rodrigo E. Principe | |
""" | |
import time | |
import random | |
# params | |
tasks = list(range(1, 2940)) | |
secure = 2950 | |
check_time = 30 | |
def n_queue(): | |
""" Get the size of the task list """ | |
return len(tasks) | |
def finish_tasks(t): | |
""" remove a random number of tasks """ | |
rint = random.randint(1, 10) | |
print(f'{rint} tasks have finished!') | |
for _ in range(0, rint): | |
t.pop(0) | |
class Task: | |
def __init__(self, n): | |
self.n = n | |
def start(self): | |
tasks.append(1) | |
def export(n, total=20): | |
if n <= total-1: | |
return Task(n) | |
else: | |
return None | |
print(f'Starting the process, tasks in queue are {n_queue()} and the limit are {secure}') | |
i = n_queue() | |
n = 0 | |
while True: | |
if i < secure: # check condition in every loop | |
task = export(n) | |
if task: | |
task.start() | |
time.sleep(1) | |
n += 1 # increase in 1 to export the next one in the next loop | |
i += 1 # instead of checking n_queue, it adds 1 to the queue so in the next loop it can check for i<secure | |
print(f'adding task {task.n}, total: {i}..') | |
else: | |
break | |
else: | |
print(f'The secure limit of tasks ({secure}) has been reached. ' | |
f'Waiting {check_time} s') | |
time.sleep(check_time) | |
finish_tasks(tasks) # while waiting, some tasks can be finished | |
i = n_queue() # thus it gets n_queue again |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment