diff --git a/sen2chain/jobs.py b/sen2chain/jobs.py index f88c6c9e06294cfe7a3ace3245f5542202de0e15..3c2151f9fb6a6acd6c989a18824ec52f2740f034 100644 --- a/sen2chain/jobs.py +++ b/sen2chain/jobs.py @@ -37,7 +37,7 @@ logger = logging.getLogger(__name__) class Jobs: """ - Class to manage created jobs + Class to manage jobs routines """ def __init__(self): @@ -106,7 +106,16 @@ class Jobs: class Job: """ - Class to manage job + Class to create, edit or delete a job routine. A job consist of a group of tasks. A task is a succession of sen2chain main Tile processings : + - Download L1C + - Process L2A + - Process cloudmask (only 1 per task) + - Process Indices (Any, using previously produced cloudmask) + Both L1C and L2A can be removed once the task is performed. + + Job editing can be done manually in sen2chain_data/config/jobs/yourjobname.cfg + + A job can be launched immediately or scheduled with the cron command line. """ # logger.propagate = False @@ -148,6 +157,12 @@ class Job: self.tasks = pd.DataFrame(first_row) def task_add(self, row: dict = None): + """ + Add a task to the job. If row : dict = None, default settings are used + + :param row: Dictionnary of task attributes. + :type row: dict + """ if not row: logger.info("No row provided, using default") row = pd.DataFrame( @@ -172,6 +187,12 @@ class Job: logger.info("\n{}".format(self.tasks)) def task_edit(self, task_id: int = None, **kwargs): + """ + Edit existing task from job routine. Any task attribute can be provided. + + :param task_id: Task number ID. Default to none + :type task_id: int + """ if task_id is None: logger.info( "Please provide task_number to edit, if no task in job, create_task first" @@ -194,6 +215,12 @@ class Job: logger.info("Task_number not found") def task_remove(self, task_id: int = None): + """ + Remove task from job. + + :param task_id: Tas number ID + :type task_id: int + """ if task_id is None: logger.info("Please provide task_number to remove") else: @@ -205,6 +232,9 @@ class Job: logger.info("Task_number not found") def save(self): + """ + Save all task edits to job. Job file located in sen2chain_data/config/jobs/yourjob.cfg + """ # save task to disk with open(str(self._config_path), "w") as ict: comments_header ="\n".join( @@ -242,6 +272,9 @@ class Job: self.tasks.to_csv(ict, index=False, sep=";") def get_cron_status(self): + """ + Return cron status of selected job : enabled, disabled or absent from cron. + """ iter = list(self._cron.find_comment("sen2chain_job_" + self.jid)) if iter: for job in iter: @@ -276,6 +309,9 @@ class Job: def cron_enable( self, ): + """ + Enable job in cron. + """ # enable job in cron self.save() self.create_python_script() @@ -304,6 +340,9 @@ class Job: self.get_cron_status() def cron_disable(self): + """ + Disable job from cron. + """ # disable / commenting job in cron iter = list(self._cron.find_comment("sen2chain_job_" + self.jid)) if iter: @@ -314,6 +353,9 @@ class Job: self.get_cron_status() def cron_remove(self): + """ + Remove job from cron. + """ # remove job from cron iter = list(self._cron.find_comment("sen2chain_job_" + self.jid)) if iter: @@ -446,6 +488,9 @@ class Job: clean_before: bool = False, clean_after: bool = False, ): + """ + Run job. Tasks are executed on + """ if self.logs: self._log_folder_path.mkdir(exist_ok=True)