Skip to content

Extend repeat schedule functionality #676 - #677

Merged
bugy merged 31 commits into
bugy:masterfrom
UrekD:master
Jul 10, 2023
Merged

bugy merged 31 commits into
bugy:masterfrom
UrekD:master

Conversation

@UrekD

@UrekD UrekD commented Jun 14, 2023

Copy link
Copy Markdown
Contributor

Implement functionality discussed in #676:

  • Option to define when task should end
  • Implemented new logic to handle the ending (arg passing, json writing, schedule handling)
  • Implemented new UI elements to select the end type

@bugy

bugy commented Jun 16, 2023

Copy link
Copy Markdown
Owner

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.
And thanks a lot for the pull request!

Comment thread src/model/external_model.py Resolved
Comment thread src/scheduling/schedule_config.py Resolved
Comment thread src/scheduling/schedule_config.py Resolved
Comment thread src/scheduling/schedule_service.py Resolved
Comment thread src/scheduling/schedule_service.py Outdated
self._execution_service.add_finish_listener(cleanup, execution_id)

if job.schedule.endOption == 'after':
job.schedule.endArg -= 1

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@UrekD UrekD Jun 26, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, how about including executionsCount on all repeatable tasks to offer some statistic about how many times the job ran in general.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented.

Comment thread src/scheduling/schedule_config.py Resolved
Comment thread src/scheduling/schedule_config.py Outdated

end_option = incoming_schedule_config.get('end_option')
prepared_schedule_config.end_option = end_option
if end_option == 'on':

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call the options max_executions and end_datetime? For me on and after are a bit confusing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, renamed em.

Comment thread src/scheduling/schedule_config.py Outdated
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)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be '%1 is required' % key? Or f'{key} is required'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed should have been f'..., fixed!

Comment thread src/scheduling/schedule_config.py Outdated
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)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify that the value is not None

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/scheduling/schedule_service.py Outdated
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:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think date_utils.is_past(schedule.end_arg) is redundant

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep checked and removed.

endTime: endDay.toTimeString().substr(0, 5),
id: null,
repeatPeriod: 1,
executeCount: 1,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call it maxExecuteCount?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed

@bugy bugy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @UrekD I think we are almost there :) I have only one big concern, about making this new feature optional

Comment thread src/scheduling/schedule_config.py Outdated


def _read_executions_count(incoming_schedule_config):
executions_count = model_helper.read_int_from_config('executions_count', incoming_schedule_config)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could pass default parameter to read_int_from_config

Comment thread src/scheduling/schedule_service.py Outdated
if job.schedule.repeatable:
job.schedule.executions_count += 1

file_utils.write_file(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call save_job ?

Comment thread src/scheduling/schedule_config.py Outdated
Comment on lines +53 to +54
if end_option is None:
raise InvalidScheduleException('end_option is required for repeatable schedule')

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/scheduling/schedule_config.py Outdated
Comment on lines +127 to +128
elif self.end_option == 'never':
result['end_option'] = 'never'

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just skip it? As in a comment above, I would suggest to completely omit end_... configuration if it's not needed.

@UrekD

UrekD commented Jul 3, 2023

Copy link
Copy Markdown
Contributor Author

Hi @UrekD I think we are almost there :) I have only one big concern, about making this new feature optional

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 bugy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for delay and lots of previous comments
Looks good to me now, thanks a lot for the contribution! 👍 🎉

@bugy
bugy merged commit 1940e9e into bugy:master Jul 10, 2023
@UrekD

UrekD commented Jul 10, 2023

Copy link
Copy Markdown
Contributor Author

Sorry for delay and lots of previous comments Looks good to me now, thanks a lot for the contribution! 👍 🎉

No worries, thank you!

@vnghia

vnghia commented Dec 29, 2023 •

Copy link
Copy Markdown
Collaborator

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.

if job.schedule.repeatable:
job.schedule.executions_count += 1
self.save_job(job)

Maybe add a is_forever attribute to the schedule_config and we won't touch the file again if it has is_forever. I can send a PR for that.

@UrekD

UrekD commented Dec 29, 2023

Copy link
Copy Markdown
Contributor Author

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.

if job.schedule.repeatable:
job.schedule.executions_count += 1
self.save_job(job)

Maybe add a is_forever attribute to the schedule_config and we won't touch the file again if it has is_forever. I can send a PR for that.

Yeah that sounds good maybe better calling it allow_write. Personally I'd use a modified image for deployment, as with the new var implementation you will also need to handle a schedule that is set to count for it to not fire forever if it can't keep track of the count, not sure if it's worth the hassle.

@vnghia

vnghia commented Dec 29, 2023

Copy link
Copy Markdown
Collaborator

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.

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

Successfully merging this pull request may close these issues.

3 participants