public override bool OnStart() { ServicePointManager.DefaultConnectionLimit = 12; bool result = base.OnStart(); try { var storageAccount = CloudStorageAccount.DevelopmentStorageAccount; var schedulerName = "testscenarios"; if (result) { var settings = new WorkerSettings(TimeSpan.FromSeconds(10), 2, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(1)); worker = Worker.Create(storageAccount, schedulerName, settings); Trace.TraceInformation("FairShareScheduler.Mockup.Worker has been started"); } } catch (Exception ex) { Trace.TraceError("Exception during OnStart: {0}", ex); result = false; } return(result); }
public WorkerSettingsBridge(IOptionsMonitor <WorkerSettings> workerSettings) { _workerSettings = workerSettings.CurrentValue ?? throw new ArgumentNullException(nameof(workerSettings)); // 當設定組態改變時觸發 workerSettings.OnChange(OnSettingsChanged); }
public Worker( WorkerSettings settings, RpcClientFactory rpcClientFactory, IMapping <TKey, TValueIn> mappingPhase, IReducing <TKey, TValueIn, TValueOut> reducingPhase, IPartitioning <TKey, TValueIn> partitioningPhase) { _settings = settings; _mappingPhase = mappingPhase; _reducingPhase = reducingPhase; _partitioningPhase = partitioningPhase; _workerInfoDto = new() { WorkerUuid = settings.WorkerUuid }; _channel = rpcClientFactory.CreateRpcChannel(); _heartBeatTicker = new() { Interval = TimeSpan.FromSeconds(4).TotalMilliseconds }; StartHeartbeat(); } public void Dispose() { _heartBeatTicker.Dispose(); _channel.Dispose(); }
/// <summary> /// Read object from file and deserialize JSON and map to object /// </summary> /// <returns></returns> public WorkerSettings ReadJsonFromFile() { string filePath = Path.Combine(FileConstants.ConfigFilePath(), FileNameConstants.WorkerSettingsFileName); WorkerSettings workerSettings = new WorkerSettings(); try { if (File.Exists(filePath)) { // deserialize JSON directly from a file using (StreamReader file = File.OpenText(filePath)) { JsonSerializer serializer = new JsonSerializer(); workerSettings = (WorkerSettings)serializer.Deserialize(file, typeof(WorkerSettings)); } } else { workerSettings = InitEmptyWorkerSettings(workerSettings); } return(workerSettings); } catch (Exception e) { workerSettings = InitEmptyWorkerSettings(workerSettings); NLogProcessing.LogError(e, "Worker settings could not be loaded. Using default values."); // Return defaults return(workerSettings); } }
protected override void InitializeWorkerMain() { if (!WorkerSettings.TryGetValue("OutputFolder", out OutputFolder)) { throw new ArgumentException("Missing argument 'OutputFolder'"); } if (!WorkerSettings.TryGetValue("ConfigFileName", out string configFileName)) { throw new ArgumentException("Missing argument 'ConfigFileName'"); } if (!WorkerSettings.TryGetValue("PluginId", out string pluginId)) { throw new ArgumentException("Missing argument 'PluginId'"); } this.Fields = FieldUtils.GetFieldsFromXml(configFileName, pluginId).ToList(); if (!Directory.Exists(OutputFolder)) { Directory.CreateDirectory(OutputFolder); } this.GlobalStorage = this.Runtime.GetWorkspaceDocsStorage(this.Runtime.CurrentWorkspace.ID); }
public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // For information on handling configuration changes // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. bool result = base.OnStart(); var storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString")); var schedulerName = "ltlpolarity"; // todo: can differ for different controllers; use setter injection with name? try { if (result) { var settings = new WorkerSettings(TimeSpan.FromHours(1), 3, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(1)); worker = Worker.Create(storageAccount, schedulerName, settings); Trace.TraceInformation("LTLCheckRole has been started"); } } catch (Exception ex) { Trace.TraceError("Exception during OnStart: {0}", ex); result = false; } return(result); }
private bool ValidateWorkerSettings(WorkerSettings workerSettingsValidate) { bool isValid = true; // Validate that Workername is set if (workerSettingsValidate.WorkerName == null || workerSettingsValidate.WorkerName == "") { ShowError("Worker name must be set"); isValid = false; } // Validate that Workername is not WORKER if (workerSettingsValidate.WorkerName == "Worker") { ShowError("Please use another name other than WORKER"); isValid = false; } // Validate that region is set if (workerSettingsValidate.Region == Enums.Region.UNDEFINED) { ShowError("Please select a region"); isValid = false; } // Validate that currency is set if (workerSettingsValidate.Currency == Enums.CurrencyList.UNDEFINED) { ShowError("Please select a currency"); isValid = false; } return(isValid); }
protected override void InitializeWorkerMain() { base.InitializeWorkerMain(); // Custom if (WorkerSettings.TryGetValue("MinConfidence", out string minConfidenceString)) { if (!int.TryParse(minConfidenceString, out MinConfidence)) { throw new ArgumentException($"Invalid argument 'MinConfidence'. Value: '{minConfidenceString}'."); } } if (WorkerSettings.TryGetValue("ConfidencePropertyName", out ConfidencePropertyName)) { } if (WorkerSettings.TryGetValue("ConfidenceEnabled", out string confidenceEnabledString)) { if (!bool.TryParse(confidenceEnabledString, out ConfidenceEnabled)) { throw new ArgumentException($"Invalid argument 'ConfidenceEnabled'. Value: '{confidenceEnabledString}'."); } } }
public ExternalTaskWorker( CamundaClient camundaClient, ExternalTaskWorkerInfo externalTaskWorkerInfo, WorkerSettings workerSettings) { _camundaClient = camundaClient; _externalTaskWorkerInfo = externalTaskWorkerInfo; _pollingInterval = workerSettings.ExternalTaskSettings.PollingInterval; var lockDuration = workerSettings.ExternalTaskSettings.LockDuration; _maxDegreeOfParallelism = workerSettings.ExternalTaskSettings.MaxDegreeOfParallelism; var maxTasksToFetchAtOnce = workerSettings.ExternalTaskSettings.MaxTasksToFetchAtOnce; var topic = new FetchExternalTaskTopic(_externalTaskWorkerInfo.TopicName, lockDuration) { Variables = _externalTaskWorkerInfo.VariablesToFetch }; _fetching = new FetchExternalTasks() { WorkerId = _workerId, MaxTasks = maxTasksToFetchAtOnce, UsePriority = true, Topics = new List <FetchExternalTaskTopic>() { topic } }; }
public ShitcoinsRatesAdapter(IHttpClientFactory httpClientFactory, IOptions <WorkerSettings> workerSettings, IDateTimeService dateTimeService) { this.dateTimeService = dateTimeService; this.workerSettings = workerSettings.Value; httpClient = httpClientFactory.CreateGenericClient(); httpClient.BaseAddress = new Uri(ServiceUrl); }
public KafkaCommandPublisher(IDispatchCommandBus dispatchCommandBus, WorkerSettings workerSettings, ILogger <KafkaCommandPublisher> logger) { _dispatchCommandBus = dispatchCommandBus ?? throw new ArgumentNullException(nameof(dispatchCommandBus)); _workerSettings = workerSettings ?? throw new ArgumentNullException(nameof(workerSettings)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public WorkerService(ILogger <WorkerService> logger, IOptions <WorkerSettings> settings, IStatsDPublisher stats) { _logger = logger; _stats = stats; _settings = settings.Value; ThreadPool.GetMaxThreads(out var maxParallelization, out _); _semaphoreSlim = new SemaphoreSlim(_settings.Parallelization == 0 ? maxParallelization : _settings.Parallelization); }
/// <summary> /// /// </summary> /// <param name="oSettings">the WorkerSettings to check for</param> /// <returns>true if a blocked job is running, false if not</returns> public bool IsRunningBlockedJob(WorkerSettings oSettings) { if ((status != JobWorkerStatus.Running && status != JobWorkerStatus.Stopping) || currentJob == null) { return(false); } return(oSettings.IsBlockedJob(currentJob.Job)); }
public Reducer( IReducing <TKey, TValueIn, TValueOut> reducingPhase, RpcMapReduceService.RpcMapReduceServiceClient rpcClient, WorkerSettings settings) { _reducingPhase = reducingPhase; _rpcClient = rpcClient; _settings = settings; }
public Mapper( IMapping <TKey, TValue> mappingPhase, IPartitioning <TKey, TValue> partitioningPhase, RpcMapReduceService.RpcMapReduceServiceClient rpcClient, WorkerSettings settings) { _mappingPhase = mappingPhase; _partitioningPhase = partitioningPhase; _settings = settings; _rpcClient = rpcClient; }
public Worker ( ILogger <Worker> logger, ITrade trade, IConfiguration configuration ) { _logger = logger; _trade = trade; _workerSettings = configuration .GetSection(typeof(WorkerSettings).Name).Get <WorkerSettings>(); }
/// <summary> /// Initializes a new WorkerSettings object (only called when one doesn't exist or cannot be read. /// </summary> /// <param name="workerSettings"></param> /// <returns></returns> private WorkerSettings InitEmptyWorkerSettings(WorkerSettings workerSettings) { // Set default values workerSettings.WorkerName = "Worker"; workerSettings.AutoStartMining = false; workerSettings.Region = Enums.Region.USEAST; workerSettings.Currency = Enums.CurrencyList.USD; // Write defaults to disk WriteJsonToFile(workerSettings); return(workerSettings); }
/// <summary> /// Serialize object to JSON and write/overwrite file /// </summary> /// <param name="workerSettings"></param> public void WriteJsonToFile(WorkerSettings workerSettings) { string filePath = Path.Combine(FileConstants.ConfigFilePath(), FileNameConstants.WorkerSettingsFileName); try { // serialize JSON directly to a file using (StreamWriter file = File.CreateText(filePath)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, workerSettings); } } catch (Exception e) { throw new ApplicationException(string.Format("Error writing file {0}", filePath), e); } }
protected override void InitializeWorkerMain() { if (!WorkerSettings.TryGetValue("OutputFolder", out OutputFolder)) { throw new ArgumentException("Missing argument 'OutputFolder'"); } if (!WorkerSettings.TryGetValue("OutputFileName", out OutputFileName)) { throw new ArgumentException("Missing argument 'OutputFileName'"); } if (!WorkerSettings.TryGetValue("GeneratePdf", out string GeneratePdf)) { throw new ArgumentException("Missing argument 'GeneratePdf'"); } this.GeneratePdf = bool.TrueString.Equals(GeneratePdf, StringComparison.InvariantCultureIgnoreCase); if (!WorkerSettings.TryGetValue("ConfigFileName", out string configFileName)) { throw new ArgumentException("Missing argument 'ConfigFileName'"); } if (!WorkerSettings.TryGetValue("PluginId", out string pluginId)) { throw new ArgumentException("Missing argument 'PluginId'"); } this.Fields = FieldUtils.GetFieldsFromXml(configFileName, pluginId).ToList(); if (!Directory.Exists(OutputFolder)) { Directory.CreateDirectory(OutputFolder); } this.GlobalStorage = this.Runtime.GetWorkspaceDocsStorage(this.Runtime.CurrentWorkspace.ID); }
public CorePlatformSettings() { Urls = new URLSettings(); Environment = new EnvironmentSettings(); Account = new AccountSettings(); Registration = new RegsitrationSettings(); Custodian = new CustodianSettings(); Worker = new WorkerSettings(); Redis = new RedisConfigurations(); SendGrid = new SendGridCredentials(); Storage = new StorageCredentials(); DocumentDB = new DocumentDBCredentials(); //<-- ReadOnly credentials for clients //Search = new SearchCredentials(); //<-- Client Query key for clients (Removed in favor of new partitioning srategy) }
public static IHostBuilder CreateHostBuilder(string[] args) { return(Host.CreateDefaultBuilder(args) .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .UseWindowsService() .ConfigureServices((hostContext, services) => { IConfiguration configuration = hostContext.Configuration; services.AddHostedService <Worker>(); SeriLogSettings seriLogSettings = new SeriLogSettings(); configuration.Bind("SeriLog", seriLogSettings); services.AddSingleton(seriLogSettings); WorkerSettings workerSettings = new WorkerSettings(); configuration.Bind("WorkerSettings", workerSettings); services.AddSingleton(workerSettings); SMTPServerSettings smtpServerSettings = new SMTPServerSettings(); configuration.Bind("SMTPServerSettings", smtpServerSettings); services.AddSingleton(smtpServerSettings); MailAppSettings mailAppSettings = new MailAppSettings(); configuration.Bind("MailAppSettings", mailAppSettings); services.AddSingleton(mailAppSettings); services.AddDbContext <AppDbContext>(cnf => cnf.UseSqlServer(configuration.GetConnectionString("DBConString"))); }) .ConfigureContainer <ContainerBuilder>((hostContext, builder) => { IConfiguration configuration = hostContext.Configuration; builder.RegisterModule(new SharedKernelModule(configuration)); builder.RegisterModule(new CoreModule(configuration)); builder.RegisterModule(new InfrastructureModule(configuration)); })); }
public void InstructionHelper_TimeToAssemble_TwoWorkersSolvesTwoBlockedSteps(string line, int duration, StepSettings stepSettings, WorkerSettings workerSettings) { stepSettings.DurationOffset = 0; workerSettings.WorkerCount = 2; var lines = new List <string> { line }; var steps = new StepFactory(stepSettings).Create(lines); var instructionHelper = new InstructionHelper(); var result = instructionHelper.TimeToAssemble(steps, workerSettings.WorkerCount); Assert.Equal(duration, result); }
public void InstructionHelper_TimeToAssemble_TwoWorkersSolvesThreeSteps(StepSettings stepSettings, WorkerSettings workerSettings) { stepSettings.DurationOffset = 0; workerSettings.WorkerCount = 2; var lines = new List <string> { "Step C must be finished before step B can begin.", "Step C must be finished before step F can begin.", }; var steps = new StepFactory(stepSettings).Create(lines); var instructionHelper = new InstructionHelper(); var result = instructionHelper.TimeToAssemble(steps, workerSettings.WorkerCount); Assert.Equal(9, result); }
/// <summary> /// MailWorkerService constructor used to resolve the needed objects by DI. /// </summary> /// <param name="services">Background serivce provider.</param> public Worker(WorkerSettings settings, IServiceProvider services) { this.Services = services; this.Setting = settings; }
/// <summary> /// 當設定組態改變時要做的事情 /// </summary> /// <param name="workerSettings"></param> private void OnSettingsChanged(WorkerSettings workerSettings) { _workerSettings = workerSettings; }
// IWorkerSettings IWorkerController.WorkerSettings => throw new NotImplementedException(); public TerminalController(WorkerSettings workerSettings) { WorkerSettings = workerSettings; }