Skip to content

Schedule Mixin

ScheduleMixin

The ScheduleMixin class provides a plugin with the ability to call functions at regular intervals.

  • Functions are registered with the InvenTree worker which runs as a background process.
  • Scheduled functions do not accept any arguments
  • Plugin member functions can be called
  • Global functions can be specified using dotted notation

Enable Schedule Integration

The Enable Schedule Integration option but be enabled, for scheduled plugin events to be activated.

Enable schedule integration Enable schedule integration

SamplePlugin

An example of a plugin which supports scheduled tasks:

A sample plugin which provides support for scheduled tasks.

Source code in src/backend/InvenTree/plugin/samples/integration/scheduled_task.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class ScheduledTaskPlugin(ScheduleMixin, SettingsMixin, InvenTreePlugin):
    """A sample plugin which provides support for scheduled tasks."""

    NAME = 'ScheduledTasksPlugin'
    SLUG = 'schedule'
    TITLE = 'Scheduled Tasks'
    VERSION = '0.2.0'

    SCHEDULED_TASKS = {
        'member': {'func': 'member_func', 'schedule': 'I', 'minutes': 30},
        'hello': {
            'func': 'plugin.samples.integration.scheduled_task.print_hello',
            'schedule': 'I',
            'minutes': 45,
        },
        'world': {
            'func': 'plugin.samples.integration.scheduled_task.print_world',
            'schedule': 'H',
        },
    }

    SETTINGS = {
        'T_OR_F': {
            'name': 'True or False',
            'description': 'Print true or false when running the periodic task',
            'validator': bool,
            'default': False,
        }
    }

    def member_func(self, *args, **kwargs):
        """A simple member function to demonstrate functionality."""
        t_or_f = self.get_setting('T_OR_F')

        print(f'Called member_func - value is {t_or_f}')
        return t_or_f