The scheduling time of a task is not updated after change in the source code.
I enabled the scheduled tasks plugin from samples
I did some slight modification to the code:
def print_hello():
now = datetime.now()
print(now, ": Hello") # pragma: no cover
def print_world():
now = datetime.now()
print(now,": World") # pragma: no cover
class ScheduledTaskPlugin(ScheduleMixin, SettingsMixin, InvenTreePlugin):
NAME = "ScheduledTasksPlugin"
SLUG = "schedule"
TITLE = "Scheduled Tasks"
SCHEDULED_TASKS = {
'hello': {
'func': 'plugin.samples.integration.scheduled_task.print_hello',
'schedule': 'I',
'minutes': 5,
},
'world': {
'func': 'plugin.samples.integration.scheduled_task.print_world',
'schedule': 'H',
},
}
Here is what I get from the log after sorting a bit.
2023-01-20 22:50 : World
2023-01-20 23:51 : World
2023-01-21 00:50 : World
2023-01-21 01:50 : World
2023-01-21 02:50 : World
2023-01-21 04:51 : World
2023-01-21 05:50 : World
2023-01-21 06:51 : World
2023-01-20 22:50 : Hello
2023-01-20 23:36 : Hello
2023-01-21 00:20 : Hello
2023-01-21 01:05 : Hello
2023-01-21 01:50 : Hello
2023-01-21 02:36 : Hello
2023-01-21 03:20 : Hello
So Hello is executed every 45 minutes instead of five. I took a look at the database and found the 45:
The problem seems to be in ../plugin/base/integration/mixins.py
def register_tasks(self):
"""Register the tasks with the database."""
try:
from django_q.models import Schedule
for key, task in self.scheduled_tasks.items():
task_name = self.get_task_name(key)
if Schedule.objects.filter(name=task_name).exists():
# Scheduled task already exists - continue!
continue # pragma: no cover
logger.info(f"Adding scheduled task '{task_name}'")
func_name = task['func'].strip()
As I do not see the log message I think create is not executed because it already exists. Or do I miss something?
Michael
I would expect the scheduling times to change when I edit the source of the plugin.
InvenTree Version 0.10.0 dev
Development Version
Commit Hash 4bfc1f7
Commit Date 2023-01-11
please see above
Thanks for the report @SergeoLacruz
@SergeoLacruz how is your plugin integrated? package or just a file in /plugins . And have you reloaded the server after changing the number?
There is a WIP branch that should work, would be great if you can test if that fixes it for you: #4243
Owner Name | inventree |
Repo Name | InvenTree |
Full Name | inventree/InvenTree |
Language | Python |
Created Date | 2017-03-23 |
Updated Date | 2023-03-31 |
Star Count | 2586 |
Watcher Count | 61 |
Fork Count | 411 |
Issue Count | 141 |
Issue Title | Created Date | Updated Date |
---|