What is a Trigger
?!¶
A Trigger
is an independant object able of acting on its owner when it detects a particular event. This property is used in CoSApp for different uses, such as launching computation on a System
.
Introduction¶
Create a Trigger
¶
You can pick an existing Trigger
in the CoSApp core package, in a third-party library, or even define your own!
[1]:
import logging
logging.getLogger().setLevel(logging.INFO)
FileCreationHandler
triggers an action when a file is created in a monitored folder
FileModificationHandler
triggers an action when a file is modified in a monitored folder
[2]:
from cosapp.base import System
from cosapp.tools.trigger import FileCreationHandler, FileModificationHandler
from pathlib import Path
s = System('mysystem')
trigger = FileCreationHandler(owner=s, folder=str(Path.home()), timeout=0.2)
Launch a Trigger
¶
Just call the start
method of your Trigger
to launch it!
The Trigger
will stop automatically after a specified duration called timeout
. Most triggers have a timeout
optional argument to set this property.
[3]:
trigger.start()