mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
46 lines
1.0 KiB
Python
46 lines
1.0 KiB
Python
"""
|
|
Sample plugin which supports task scheduling
|
|
"""
|
|
|
|
from plugin import IntegrationPluginBase
|
|
from plugin.mixins import ScheduleMixin
|
|
|
|
|
|
# Define some simple tasks to perform
|
|
def print_hello():
|
|
print("Hello")
|
|
|
|
|
|
def print_world():
|
|
print("World")
|
|
|
|
|
|
def fail_task():
|
|
raise ValueError("This task should fail!")
|
|
|
|
|
|
class ScheduledTaskPlugin(ScheduleMixin, IntegrationPluginBase):
|
|
"""
|
|
A sample plugin which provides support for scheduled tasks
|
|
"""
|
|
|
|
PLUGIN_NAME = "ScheduledTasksPlugin"
|
|
PLUGIN_SLUG = "schedule"
|
|
PLUGIN_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_hello',
|
|
'schedule': 'H',
|
|
},
|
|
'failure': {
|
|
'func': 'plugin.samples.integration.scheduled_task.fail_task',
|
|
'schedule': 'D',
|
|
},
|
|
}
|