get_setting, set_setting problem in ScheduledTsak Plugin #4313
-
Hi, class SupplierSyncPlugin(ScheduleMixin, SettingsMixin, InvenTreePlugin):
NAME = "SyncPlugin"
...
SCHEDULED_TASKS = {
'member': {
'func': 'UpdatePart',
'schedule': 'I',
'minutes': 1,
}
}
SETTINGS = {
'SUPPLIERKEY': {
'name': 'Supplier API Key',
'description': 'Place here your key for the suppliers API',
},
'AKTPK': {
'name': 'The actual component',
'description': 'The next comopnent to be updated',
},
}
...
def UpdatePart(self, *args, **kwargs):
Update = int(self.get_setting('AKTPK'))
logger.info('Running update on pk %i',Update)
...
lot of code
...
Update=Update+1
self.set_setting('AKTPK',str(Update))
Of course that is a bit simplified. I need the value of Update to be persistent from run to run. Thats why I use the settings Mixin to store the value to the database. This works somehow but not perfect. I get the following log:
I would expect the value to count just upwards. In fact it does not. Is there some kind of caching in between that need to be flushed? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
I suspect this has to do with the background workers process not always behaving as intended, see: I'm not sure what you're trying to do, but could an option be to save a flag to each part (?) using metadata, and checking this flag instead? |
Beta Was this translation helpful? Give feedback.
-
@SergeoLacruz you might be running into caching issues. The settings value might get read from cache (rather than from the database). And if different worker instances are running, as they are not using a shared cache, they might not all be operating on the correct database value. If this is indeed happening, it would lead to some very unexpected results. The series of ID values in your log would seem to point to this. Can you try setting your number of background workers to "1" (the default is "4") and restart the server? This will show us if the issue is likely to be related to caching |
Beta Was this translation helpful? Give feedback.
-
One worker does a better job :-)
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the help. I will also look into the metadata. Might be an easier solution... |
Beta Was this translation helpful? Give feedback.
One worker does a better job :-)