public static IServiceCollection AddMusicLibraryTasks(this IServiceCollection services, IConfiguration configuration) { var so = new SchedulerOptions(); configuration.GetSection("SchedulerOptions").Bind(so); services.AddScheduler(configuration); services.AddSingleton <FileSystemMonitorFactory>(); services.AddSingleton <Messenger>(); services.AddService <MusicFolderChangeMonitor>(); services.AddService <TaskRunner>(); services.AddService <TaskPublisher>(); services.AddService <PlayManager>(); services.AddService <Resampler>(); if (!so.SuspendScheduling) { foreach (var s in so.Schedules) { if (s.Enabled) { switch (s.Name) { case "MusicScanner": // temp:: services.AddSingleton<ScheduledTask, MusicScanner>(); break; } } } } return(services); }
public IScheduler <T> GetScheduler <T>(IServiceProvider serviceProvider, SchedulerOptions options) { var schedulerStore = ActivatorUtilities.CreateInstance <MongoDbSchedulerStore <T> >(serviceProvider, options); var scheduler = ActivatorUtilities.CreateInstance <MongoDbScheduler <T> >(serviceProvider, options, schedulerStore); return(scheduler); }
static void Main(string[] args) { var options = new SchedulerOptions { LoggingFolder = ConfigurationManager.AppSettings["LoggingFolder"], }; var container = AutofacContainer.Configure(options.LoggingFolder); var _logger = container.Resolve <Interfaces.ILogger>(); GlobalConfiguration.Configuration.UseAutofacActivator(container); HostFactory.Run(c => { c.UseAutofacContainer(container); c.Service <MailingService>(callback: s => { s.ConstructUsingAutofacContainer(); s.WhenStarted((service, control) => { _logger.Information("Service started..."); return(service.Start()); }); s.WhenStopped((service, control) => service.Stop()); }); c.SetDisplayName("MailReceiverService"); c.SetDescription("dupa123"); c.StartAutomatically(); c.RunAsLocalService(); }); }
public TestJob( SchedulerOptions options, ILogger <TestJob> logger) { _options = options; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public TimerScheduling(ISchedulerStore <T> schedulerStore, SchedulerOptions schedulerOptions, ILogger <TimerScheduling <T> > log, IClock clock) { this.schedulerStore = schedulerStore; this.schedulerOptions = schedulerOptions; this.clock = clock; this.log = log; }
public VippsPollingService(PollingEntityDbContext pollingEntityContext, IVippsService vippsService, IVippsOrderProcessor vippsOrderCreator, SchedulerOptions schedulerOptions) { _pollingEntityContext = pollingEntityContext; _vippsService = vippsService; _vippsOrderCreator = vippsOrderCreator; _schedulerOptions = schedulerOptions; }
public CleanCacheJobsService( IDataBaseFactory dbFactory, SpamProtectionCache spamProtectionCache, IOptions <SchedulerOptions> schedulerOptions, JwtBlackListService jwtBlackListService) { this.dbFactory = dbFactory; this.spamProtectionCache = spamProtectionCache; this.jwtBlackListService = jwtBlackListService; this.schedulerOptions = schedulerOptions.Value; }
public IMessaging <T> GetMessaging <T>(IServiceProvider serviceProvider, string channelName) { var schedulingProvider = serviceProvider.GetRequiredService <ISchedulingProvider>(); var options = new SchedulerOptions { QueueName = $"Messaging_{channelName}", ExecutionRetries = Array.Empty <int>(), ExecuteInline = false }; var scheduling = schedulingProvider.GetScheduling <Envelope <T> >(serviceProvider, options); return(ActivatorUtilities.CreateInstance <SchedulingMessaging <T> >(serviceProvider, scheduling)); }
private bool AddJob(string name, IScheduledJob job, SchedulerOptions options) { _jobs.AddOrUpdate(name, job, (n, j) => job); var wrapped = Create(name, job, options); if (wrapped != null) { _wrappedJobs.AddOrUpdate(name, wrapped, (n, v) => wrapped); return(true); } return(false); }
public CleanCacheJobsService( IDataBaseFactory dbFactory, SpamProtectionCache spamProtectionCache, IOptions <SchedulerOptions> schedulerOptions, IMaterialsVisitsCounterCache materialsVisitsCounterCache, IProfilesVisitsCounterService profilesVisitsCounterService, JweBlackListService jweBlackListService) { this.dbFactory = dbFactory; this.spamProtectionCache = spamProtectionCache; this.jweBlackListService = jweBlackListService; this.materialsVisitsCounterCache = materialsVisitsCounterCache; this.profilesVisitsCounterService = profilesVisitsCounterService; this.schedulerOptions = schedulerOptions.Value; }
public TimerScheduler(ISchedulerStore <T> schedulerStore, SchedulerOptions schedulerOptions, IClock clock, ISemanticLog log) { this.schedulerStore = schedulerStore; this.schedulerOptions = schedulerOptions; actionBlock = new ActionBlock <SchedulerBatch <T> >(HandleAsync, new ExecutionDataflowBlockOptions { BoundedCapacity = schedulerOptions.MaxParallelism * 4, MaxDegreeOfParallelism = schedulerOptions.MaxParallelism, MaxMessagesPerTask = 1 }); this.clock = clock; this.log = log; }
private SchedulerTaskWrapper?Create(string jobName, IScheduledJob job, SchedulerOptions options) { var currentTimeUtc = DateTimeOffset.UtcNow; var timeZone = TimeZoneInfo.Local; if (string.IsNullOrEmpty(options.CronSchedule)) { _logger.MissingCron(jobName, options.CronSchedule); return(null); } if (!string.IsNullOrEmpty(options.CronTimeZone)) { try { timeZone = TimeZoneInfo.FindSystemTimeZoneById(options.CronTimeZone); } catch (Exception ex) { _logger.TimeZoneParseFailure(jobName, options.CronTimeZone, ex); timeZone = TimeZoneInfo.Local; } } _logger.TimeZone(jobName, timeZone.Id); CronExpression crontabSchedule; if (options.CronSchedule.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Length == 6) { crontabSchedule = CronExpression.Parse(options.CronSchedule, CronFormat.IncludeSeconds); } else { crontabSchedule = CronExpression.Parse(options.CronSchedule, CronFormat.Standard); } var nextRunTime = options.RunImmediately ? currentTimeUtc : crontabSchedule.GetNextOccurrence(currentTimeUtc, timeZone) !.Value; return(new SchedulerTaskWrapper(crontabSchedule, job, nextRunTime, timeZone)); }
private IScheduler <T> GetScheduler <T>(IServiceProvider serviceProvider, string channelName) { if (instances.TryGetValue(typeof(T), out var value)) { return((IScheduler <T>)value); } var schedulerProvider = serviceProvider.GetRequiredService <ISchedulerProvider>(); var options = new SchedulerOptions { QueueName = $"Messaging_{channelName}", ExecutionRetries = Array.Empty <int>(), ExecuteInline = false }; var scheduler = schedulerProvider.GetScheduler <T>(serviceProvider, options); instances[typeof(T)] = scheduler; return(scheduler); }
public TimerConsumer(ISchedulerStore <T> schedulerStore, SchedulerOptions schedulerOptions, ScheduleSuccessCallback <T> onSuccess, ScheduleErrorCallback <T> onError, ILogger log, IClock clock) { this.schedulerStore = schedulerStore; this.schedulerOptions = schedulerOptions; this.onSuccess = onSuccess; this.onError = onError; activity = $"Scheduler.Query({schedulerOptions.QueueName})"; actionBlock = new ActionBlock <SchedulerBatch <T> >(async batch => { using (Telemetry.Activities.StartActivity(activity)) { try { await HandleAsync(batch); } catch (OperationCanceledException ex) { throw new AggregateException(ex); } } }, new ExecutionDataflowBlockOptions { BoundedCapacity = schedulerOptions.MaxParallelism * 4, MaxDegreeOfParallelism = schedulerOptions.MaxParallelism, MaxMessagesPerTask = 1 }); this.clock = clock; this.log = log; }
public IActionResult Index() { var jobOptions = new SchedulerOptions { CronSchedule = "0/1 * * * * *", RunImmediately = true }; _schedulerRegistration.AddOrUpdate(new TestJob(jobOptions, _loggerFactory.CreateLogger <TestJob>()), jobOptions); if (_torahVerses.Current != null) { var text = _torahVerses.Current.Select(x => x.Text).Aggregate((i, j) => i + Environment.NewLine + j); var bookName = _torahVerses.Current.Select(x => x.Bookname).Distinct().FirstOrDefault(); var chapter = _torahVerses.Current.Select(x => x.Chapter).Distinct().FirstOrDefault(); var versesArray = _torahVerses.Current.Select(x => x.Verse).Aggregate((i, j) => $"{i};{j}").Split(';'); var verses = string.Empty; if (versesArray.Length > 1) { verses = $"{versesArray.FirstOrDefault()}-{versesArray.Reverse().FirstOrDefault()}"; } else { verses = versesArray.FirstOrDefault(); } ViewBag.Text = text; ViewBag.BookName = bookName; ViewBag.Chapter = chapter; ViewBag.Verses = verses; ViewBag.Url = $"https://studybible.info/KJV_Strongs/{Uri.EscapeDataString($"{bookName} {chapter}:{verses}")}"; } return(View()); }
public MongoDbSchedulerStore(IMongoDatabase database, SchedulerOptions options) : base(database) { this.options = options; }
public Scheduler(IOptions <SchedulerOptions> options, IHttpClientFactory httpClientFactory) { _httpClientFactory = httpClientFactory; _options = options.Value; }
public bool AddOrUpdate(IScheduledJob job, SchedulerOptions options) { return(AddOrUpdate(job.Name, job, options)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { #if !NETCOREAPP2_0 && !NETCOREAPP2_1 services.AddControllers(); #endif//!NETCOREAPP2_0 && !NETCOREAPP2_1 DatabaseOptions db = Configuration.GetSection("Database").Get <DatabaseOptions>(); string settings = db.Settings; string type = db.Type; bool disabled = db.Disabled; if (disabled) { Console.WriteLine("Database service is disabled."); } else { Console.WriteLine("Database type: " + type); Console.WriteLine("Connecting: " + settings); } DbConnection connection; if (disabled || string.IsNullOrEmpty(type)) { //Gurux.DLMS.AMI DB is defined elsewhere. connection = null; } else if (string.Compare(type, "Oracle", true) == 0) { connection = new OracleConnection(settings); } else if (string.Compare(type, "MSSQL", true) == 0) { connection = new SqlConnection(settings); } else if (string.Compare(type, "MySQL", true) == 0) { connection = new MySql.Data.MySqlClient.MySqlConnection(settings); } else if (string.Compare(type, "SQLite", true) == 0) { connection = new SQLiteConnection(settings); } else { throw new Exception("Invalid connection type. " + type); } if (connection != null) { connection.Open(); GXHost h = new GXHost() { Connection = new GXDbConnection(connection, null) }; h.Connection.OnSqlExecuted += Connection_OnSqlExecuted; if (!h.Connection.TableExist <GXDevice>()) { Console.WriteLine("Creating tables."); h.Connection.CreateTable <GXSystemError>(false, false); h.Connection.CreateTable <GXDeviceTemplate>(false, false); h.Connection.CreateTable <GXDevice>(false, false); h.Connection.CreateTable <GXObjectTemplate>(false, false); h.Connection.CreateTable <GXAttributeTemplate>(false, false); h.Connection.CreateTable <GXObject>(false, false); h.Connection.CreateTable <GXAttribute>(false, false); h.Connection.CreateTable <GXValue>(false, false); h.Connection.CreateTable <GXTask>(false, false); h.Connection.CreateTable <GXError>(false, false); h.Connection.CreateTable <GXSchedule>(false, false); h.Connection.CreateTable <GXScheduleToAttribute>(false, false); h.Connection.CreateTable <GXSchedulerInfo>(false, false); h.Connection.CreateTable <GXReaderInfo>(false, false); h.Connection.CreateTable <GXDeviceToReader>(false, false); h.Connection.CreateTable <GXDeviceLog>(false, false); AddSchedule(h.Connection); } else { h.Connection.UpdateTable <GXSystemError>(); h.Connection.UpdateTable <GXError>(); h.Connection.UpdateTable <GXReaderInfo>(); h.Connection.UpdateTable <GXObjectTemplate>(); h.Connection.UpdateTable <GXAttributeTemplate>(); h.Connection.UpdateTable <GXDeviceTemplate>(); h.Connection.UpdateTable <GXObject>(); h.Connection.UpdateTable <GXAttribute>(); h.Connection.UpdateTable <GXDevice>(); if (!h.Connection.TableExist <GXDeviceLog>()) { h.Connection.CreateTable <GXDeviceLog>(false, false); } else { h.Connection.UpdateTable <GXDeviceLog>(); } } h.Connection.Insert(GXInsertArgs.Insert(new GXSystemError() { Generation = DateTime.Now, Error = "Service started: " + ServerAddress }));; Console.WriteLine("Service started: " + ServerAddress); services.AddScoped <GXHost>(q => { return(h); }); } services.Configure <ListenerOptions>(Configuration.GetSection("Listener")); ListenerOptions listener = Configuration.GetSection("Listener").Get <ListenerOptions>(); if (!listener.Disabled) { services.AddHostedService <GXListenerService>(); } else { Console.WriteLine("Listener service is disabled."); } services.Configure <NotifyOptions>(Configuration.GetSection("Notify")); NotifyOptions n = Configuration.GetSection("Notify").Get <NotifyOptions>(); if (!n.Disabled && n.Port != 0) { services.AddHostedService <GXNotifyService>(); } else { Console.WriteLine("Notify service is disabled."); } services.Configure <SchedulerOptions>(Configuration.GetSection("Scheduler")); SchedulerOptions s = Configuration.GetSection("Scheduler").Get <SchedulerOptions>(); if (!s.Disabled) { services.AddHostedService <GXSchedulerService>(); } else { Console.WriteLine("Scheduler service is disabled."); } services.Configure <ReaderOptions>(Configuration.GetSection("Reader")); ReaderOptions r = Configuration.GetSection("Reader").Get <ReaderOptions>(); Console.WriteLine("Reader trace level is " + r.TraceLevel); Console.WriteLine("Listener trace level is " + listener.TraceLevel); if (r.Threads != 0 && !r.Disabled) { services.AddHostedService <ReaderService>(); } else { Console.WriteLine("Reader '" + r.Name + "' ID: " + r.Id); } #if NETCOREAPP2_0 || NETCOREAPP2_1 services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1); #endif //NETCOREAPP2_0 || NETCOREAPP2_1 }
public TestJobDup(SchedulerOptions options, ILogger <TestJobDup> logger) { _logger = logger; Name = options.JobName; }
public bool AddOrUpdate(string jobName, IScheduledJob job, SchedulerOptions options) { return(AddJob(jobName, job, options)); }
public static void AddScheduler <T>(this IServiceCollection services, SchedulerOptions options) { services.AddSingletonAs(c => c.GetRequiredService <ISchedulerProvider>().GetScheduler <T>(c, options)) .As <IScheduler <T> >(); }