Skip to content

Scheduling

These plugins can be used to schedule tasks to run at specific times or intervals.

SimpleTimer

This plugin allows you to implement simple timers in your CoreConnect application (ideally in the Functions service), either directly on your service or via a custom plugin.

Name CoreConnect.SimpleTimer
Choice true
Configuration

There is no specific configuration for this plugin

Technical details

To make use of this plugin, you can register a timer in your custom plugin (see Custom Plugins) via the RegisterTimers method. The timer will then be executed at the specified interval. For example:

using System.Diagnostics;
using CoreConnect.Plugins;
public class MyCustomPlugin : CoreConnectPlugin
{
public override string Name => "MyCustomPlugin";
public override string ConfigurationName => "MyCustomPluginSettings";
public override string Description => "Custom plugin for CoreConnect";
...
public override void RegisterTimers(ILogger logger, ITimerRegistration registration)
{
registration.RegisterTimer<RefreshProductTimer>("RefreshAllProducts", "5 4 * * *");
}
}
public class RefreshProductTimer : ITimerCallback
{
private readonly ILogger<RefreshProductTimer> _logger;
private readonly Stopwatch _stopwatch = new Stopwatch();
public RefreshProductTimer(ILogger<RefreshProductTimer> logger, ...)
{
this._logger = logger;
}
public Task Callback(DateTime triggerTime)
{
_logger.LogInformation("Refreshing products triggered");
try
{
_stopwatch.Restart();
Task.Run(async () =>
{
...
});
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
}
finally
{
_logger.LogDebug("RefreshProducts trigger took {TimeElapsed}", _stopwatch.Elapsed);
}
return Task.CompletedTask;
}
}