Scheduled Events
InsightCloudSec Bots can spawn jobs that run at specified times with specified arguments. These jobs are called scheduled events.
Database & Backend Naming Conventions
Rebranding for DivvyCloud, now InsightCloudSec is ongoing. Logos, URLs, text, and images may reference either InsightCloudSec or DivvyCloud. This obviously extends to the internal portion of our product as well.
The most important thing to note is that the product functionality has remained the same. If you have any questions or concerns reach out to us through the Customer Support Portal.
Registration
A job is registered as a scheduled event using the register
method of the ScheduledEventManager
class, which acts as a class decorator. For example, this is how the StartResourceJob
scheduled event is registered in InsightCloudSec:
python
1from DivvyWorkers.Processors.ScheduledEvents import ScheduledEventManager2@ScheduledEventManager.register('divvy.start_resource')3class StartResourceJob(MultiResourceScheduledEventJob):4...5
The scheduled event can then be referred to using the unique identifier defined in the register
decorator, in this case divvy.start_resource
.
Here is an example of how to spawn a scheduled event within a bot action:
python
1from DivvyBotfactory.scheduling import ScheduledEventTracker23@registry.action(4uid='divvy.action.start_resource_example',5bulk_action=True,6accepts_complement=True,7...8)9def start_resource_example(bot, settings, matches, non_matches):10with ScheduledEventTracker() as context:11for resource in matches:12context.schedule_bot_event(13bot=bot, resource=resource,14description='Start a resource.',15event_type='divvy.start_resource'16schedule_data=schedule.Once(when=datetime.utcnow() + timedelta(hours=12))17)18
Dynamic Loading and Unloading
When developing a plugin that InsightCloudSec dynamically loads and unloads, it is necessary to unload the plugin’s scheduled events. This can be conveniently done using the ScheduledEventRegistryWrapper
class, which requires only a minor variation upon the pattern shown above.
An example:
python
1from DivvyWorkers.Processors.ScheduledEvents import ScheduledEventRegistryWrapper23# Initialize the registry wrapper4events = ScheduledEventRegistryWrapper()56# Register a scheduled event job7events.register('divvy.start_resource')8class StartResourceJob(MultiResourceScheduledEventJob):9...1011# Handle plugin loading/unloading12def load():13events.load()14def unload():15events.unload()16
A scheduled event registered this way is created and referred to in the same way as before. The only difference is in the specific syntax of how that event is registered.