Repository navigation
Extend repeat schedule functionality #676 - #677
Conversation
…f the repetable task should end
|
Hi @UrekD sorry for a late response. Unfortunately I'm a bit busy this week, so don't have time to review. Will try to check the pull request within the next several days. |
| self._execution_service.add_finish_listener(cleanup, execution_id) | ||
|
|
||
| if job.schedule.endOption == 'after': | ||
| job.schedule.endArg -= 1 |
There was a problem hiding this comment.
What do you think about not overriding the config file on every execution, but rather count how many executions could fit between now and start_datetime?
e.g. if start_datetime=19:30, max_count=5, now=22:12. Then until now there were 6 executions (19:30, 20:00, 20:30, 21:00, 21:30, 22:00) and there is no need to execute anymore? For this, we could reuse scheduling.schedule_config.ScheduleConfig.get_next_time
There was a problem hiding this comment.
Sorry, I'm not really understanding what you mean here as start is in the past? I think executions shouldn't be tied to exact next execute time as this makes this option obsolete in my opinion as this can be achieve with end time. This option would be more of a guarantee execution of the job x times so even downtime wouldn't effect the job, which requires constant change on execution even in the file.
There was a problem hiding this comment.
Alright, makes sense. Another proposal: may be instead of overriding the maxCount, we could save one more parameter: executionsCount (i.e. how many times the script was executed). So that we will keep the original maxCount value as a source of truth
There was a problem hiding this comment.
Great idea, how about including executionsCount on all repeatable tasks to offer some statistic about how many times the job ran in general.
|
|
||
| end_option = incoming_schedule_config.get('end_option') | ||
| prepared_schedule_config.end_option = end_option | ||
| if end_option == 'on': |
There was a problem hiding this comment.
Should we call the options max_executions and end_datetime? For me on and after are a bit confusing
| def _read_datetime(incoming_schedule_config, key): | ||
| datetime_value = model_helper.read_datetime_from_config(key, incoming_schedule_config) | ||
| if datetime_value is None: | ||
| raise InvalidScheduleException('%1 is required', key) |
There was a problem hiding this comment.
Should it be '%1 is required' % key? Or f'{key} is required'
There was a problem hiding this comment.
Indeed should have been f'..., fixed!
| if end_option == 'on': | ||
| prepared_schedule_config.end_arg = _read_datetime(incoming_schedule_config, 'end_arg') | ||
| elif end_option == 'after': | ||
| prepared_schedule_config.end_arg = model_helper.read_int_from_config('end_arg', incoming_schedule_config) |
There was a problem hiding this comment.
Please verify that the value is not None
There was a problem hiding this comment.
Seen the error in my ways, I have re done it to be more in line with the previous. I think when checking for execution count it doesn't make sense to error if it's not available but just to set it to 0.
| next_datetime = schedule.get_next_time() | ||
|
|
||
| if schedule.end_option == 'on': | ||
| if date_utils.is_past(schedule.end_arg) or next_datetime > schedule.end_arg: |
There was a problem hiding this comment.
I think date_utils.is_past(schedule.end_arg) is redundant
There was a problem hiding this comment.
Yep checked and removed.
| endTime: endDay.toTimeString().substr(0, 5), | ||
| id: null, | ||
| repeatPeriod: 1, | ||
| executeCount: 1, |
…_arg, increment executions and check for max_exec
|
|
||
|
|
||
| def _read_executions_count(incoming_schedule_config): | ||
| executions_count = model_helper.read_int_from_config('executions_count', incoming_schedule_config) |
There was a problem hiding this comment.
You could pass default parameter to read_int_from_config
| if job.schedule.repeatable: | ||
| job.schedule.executions_count += 1 | ||
|
|
||
| file_utils.write_file( |
| if end_option is None: | ||
| raise InvalidScheduleException('end_option is required for repeatable schedule') |
There was a problem hiding this comment.
I think None end_option should be allowed:
- existing configurations don't have it
- we should make manual configuration (via json) more user-friendly, i.e. don't require unnecessary configurations
| elif self.end_option == 'never': | ||
| result['end_option'] = 'never' |
There was a problem hiding this comment.
Should we just skip it? As in a comment above, I would suggest to completely omit end_... configuration if it's not needed.
Hey @bugy, how so? I'm guessing maybe from an administrative standpoint? As the functionality shouldn't in no way hinder the functionality as it was before, if you don't select anything else. I see the point about not requiring a value for never ending schedules that was oversight on my end, which actually thought about not implementing in a current way but not for that reason :D I'll address the new stuff tomorrow, thanks! |
bugy
left a comment
There was a problem hiding this comment.
Sorry for delay and lots of previous comments
Looks good to me now, thanks a lot for the contribution! 👍 🎉
No worries, thank you! |
|
Can we avoid overwriting the configuration file ? Because I am using an Infra-as-code approach and everything is generated by some kind of code and set to read-only afterward. So this failed on my server. script-server/src/scheduling/schedule_service.py Lines 155 to 158 in 7ea0180 Maybe add a |
Yeah that sounds good maybe better calling it |
|
I think I only need it not to touch the config files that are persistent, i.e files with no expiration regardless time or execution count. The file with expiration can still be overwritten because usually these files are generated dynamically while the former can be generated and managed with Infra-as-code. So we can check if the file will expire and overwrite it or just leave it there. The execution count will still be kept track inside the original file. |
Implement functionality discussed in #676: