本文整理汇总了C#中JobHostConfiguration.UseTimers方法的典型用法代码示例。如果您正苦于以下问题:C# JobHostConfiguration.UseTimers方法的具体用法?C# JobHostConfiguration.UseTimers怎么用?C# JobHostConfiguration.UseTimers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JobHostConfiguration
的用法示例。
在下文中一共展示了JobHostConfiguration.UseTimers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
static void Main()
{
var config = new JobHostConfiguration();
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();
}
示例2: Main
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
static void Main()
{
var config = new JobHostConfiguration();
config.UseTimers();
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
示例3: Generate_EndToEnd
public async Task Generate_EndToEnd()
{
// construct our TimerTrigger attribute ([TimerTrigger("00:00:02", RunOnStartup = true)])
Collection<ParameterDescriptor> parameters = new Collection<ParameterDescriptor>();
ParameterDescriptor parameter = new ParameterDescriptor("timerInfo", typeof(TimerInfo));
ConstructorInfo ctorInfo = typeof(TimerTriggerAttribute).GetConstructor(new Type[] { typeof(string) });
PropertyInfo runOnStartupProperty = typeof(TimerTriggerAttribute).GetProperty("RunOnStartup");
CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(
ctorInfo,
new object[] { "00:00:02" },
new PropertyInfo[] { runOnStartupProperty },
new object[] { true });
parameter.CustomAttributes.Add(attributeBuilder);
parameters.Add(parameter);
// create the FunctionDefinition
FunctionMetadata metadata = new FunctionMetadata();
TestInvoker invoker = new TestInvoker();
FunctionDescriptor function = new FunctionDescriptor("TimerFunction", invoker, metadata, parameters);
Collection<FunctionDescriptor> functions = new Collection<FunctionDescriptor>();
functions.Add(function);
// Get the Type Attributes (in this case, a TimeoutAttribute)
ScriptHostConfiguration scriptConfig = new ScriptHostConfiguration();
scriptConfig.FunctionTimeout = TimeSpan.FromMinutes(5);
Collection<CustomAttributeBuilder> typeAttributes = ScriptHost.CreateTypeAttributes(scriptConfig);
// generate the Type
Type functionType = FunctionGenerator.Generate("TestScriptHost", "TestFunctions", typeAttributes, functions);
// verify the generated function
MethodInfo method = functionType.GetMethod("TimerFunction");
TimeoutAttribute timeoutAttribute = (TimeoutAttribute)functionType.GetCustomAttributes().Single();
Assert.Equal(TimeSpan.FromMinutes(5), timeoutAttribute.Timeout);
Assert.True(timeoutAttribute.ThrowOnTimeout);
Assert.True(timeoutAttribute.TimeoutWhileDebugging);
ParameterInfo triggerParameter = method.GetParameters()[0];
TimerTriggerAttribute triggerAttribute = triggerParameter.GetCustomAttribute<TimerTriggerAttribute>();
Assert.NotNull(triggerAttribute);
// start the JobHost which will start running the timer function
JobHostConfiguration config = new JobHostConfiguration()
{
TypeLocator = new TypeLocator(functionType)
};
config.UseTimers();
JobHost host = new JobHost(config);
await host.StartAsync();
await Task.Delay(3000);
await host.StopAsync();
// verify our custom invoker was called
Assert.True(invoker.InvokeCount >= 2);
}
示例4: Main
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
static void Main()
{
var config = new JobHostConfiguration();
config.UseWebHooks();
config.UseTimers();
config.UseNotificationHubs(new NotificationHubConfiguration { HubName = "pbjobs" });
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
示例5: Main
public static void Main(string[] args)
{
JobHostConfiguration config = new JobHostConfiguration();
config.Tracing.ConsoleLevel = TraceLevel.Verbose;
// Set to a short polling interval to facilitate local
// debugging. You wouldn't want to run prod this way.
config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(2);
FilesConfiguration filesConfig = new FilesConfiguration();
if (string.IsNullOrEmpty(filesConfig.RootPath))
{
// when running locally, set this to a valid directory
filesConfig.RootPath = @"c:\temp\files";
}
EnsureSampleDirectoriesExist(filesConfig.RootPath);
config.UseFiles(filesConfig);
config.UseTimers();
config.UseSample();
config.UseCore();
var sendGridConfiguration = new SendGridConfiguration()
{
ToAddress = "[email protected]",
FromAddress = new MailAddress("[email protected]", "WebJobs Extensions Samples")
};
config.UseSendGrid(sendGridConfiguration);
ConfigureTraceMonitor(config, sendGridConfiguration);
WebHooksConfiguration webHooksConfig = new WebHooksConfiguration();
webHooksConfig.UseReceiver<GitHubWebHookReceiver>();
config.UseWebHooks(webHooksConfig);
JobHost host = new JobHost(config);
host.Call(typeof(MiscellaneousSamples).GetMethod("ExecutionContext"));
host.Call(typeof(FileSamples).GetMethod("ReadWrite"));
host.Call(typeof(SampleSamples).GetMethod("Sample_BindToStream"));
host.Call(typeof(SampleSamples).GetMethod("Sample_BindToString"));
host.Call(typeof(TableSamples).GetMethod("CustomBinding"));
// When running in Azure Web Apps, a JobHost will gracefully shut itself
// down, ensuring that all listeners are stopped, etc. For this sample,
// we want to ensure that same behavior when the console app window is
// closed. This ensures that Singleton locks that are taken are released
// immediately, etc.
ShutdownHandler.Register(() => { host.Stop(); });
host.RunAndBlock();
}
示例6: Main
static void Main()
{
var config = new JobHostConfiguration();
var serviceBusConfig = new ServiceBusConfiguration()
{
ConnectionString = AmbientConnectionStringProvider
.Instance
.GetConnectionString(ConnectionStringNames.ServiceBus)
};
config.UseServiceBus(serviceBusConfig);
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();
}
示例7: Main
private static void Main()
{
var container = new StandardKernel();
var token = ConfigurationManager.AppSettings["TOKEN"];
var account = ConfigurationManager.AppSettings["ACCOUNT_EUR_USD"].SafeParseInt().GetValueOrDefault();
var adapter = new OandaAdapter("https://api-fxpractice.oanda.com/v1/",
"https://api-fxpractice.oanda.com/v1/",
"https://stream-fxpractice.oanda.com/v1/",
"https://stream-fxpractice.oanda.com/v1/",
"https://api-fxpractice.oanda.com/labs/v1/",
token);
container.Bind<Cobra>()
.ToConstant(new Cobra(new Adx(14),
new Ema(12),
new Ema(12),
new Sma(72),
new Sma(72),
new SimpleDateProvider(),
"EUR_USD",
15,
adapter,
adapter,
account))
.InSingletonScope();
container.Bind<IRateProvider>()
.ToConstant(adapter)
.InSingletonScope();
var test = container.TryGet<Cobra>();
if (test == null)
{
throw new Exception("Unable to build Forex System");
}
var config = new JobHostConfiguration
{
JobActivator = new MyActivator(container)
};
config.Tracing.ConsoleLevel = TraceLevel.Info;
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();
}
示例8: Main
private static void Main()
{
var config = new JobHostConfiguration();
config.Tracing.ConsoleLevel = TraceLevel.Info;
config.DashboardConnectionString = CloudConfigurationManager.GetSetting("AzureWebJobsDashboard");
config.StorageConnectionString = CloudConfigurationManager.GetSetting("AzureWebJobsStorage");
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();
}
示例9: Main
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
static void Main()
{
JobHostConfiguration config = new JobHostConfiguration();
config.Tracing.ConsoleLevel = System.Diagnostics.TraceLevel.Verbose;
config.UseFiles();
config.UseTimers();
WebHooksConfiguration webhooksConfiguration = new WebHooksConfiguration();
config.UseWebHooks(webhooksConfiguration);
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
示例10: Main
// Be sure to add your storage account connection strings in the App.config when running locally
// Don't check in your conection strings to Git, though
static void Main()
{
// This is the config object we pass to the JobHost
JobHostConfiguration config = new JobHostConfiguration();
// Have our Continuous Job host log all our traces up to Verbose
config.Tracing.ConsoleLevel = System.Diagnostics.TraceLevel.Verbose;
// Turn on Timer Triggers
config.UseTimers();
// Initialize host with config
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
示例11: Main
public static void Main(string[] args)
{
JobHostConfiguration config = new JobHostConfiguration();
config.Tracing.ConsoleLevel = TraceLevel.Verbose;
// Set to a short polling interval to facilitate local
// debugging. You wouldn't want to run prod this way.
config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(2);
FilesConfiguration filesConfig = new FilesConfiguration();
if (string.IsNullOrEmpty(filesConfig.RootPath))
{
// when running locally, set this to a valid directory
filesConfig.RootPath = @"c:\temp\files";
}
EnsureSampleDirectoriesExist(filesConfig.RootPath);
config.UseFiles(filesConfig);
config.UseTimers();
config.UseSample();
config.UseCore();
var sendGridConfiguration = new SendGridConfiguration()
{
ToAddress = "[email protected]",
FromAddress = new MailAddress("[email protected]", "WebJobs Extensions Samples")
};
config.UseSendGrid(sendGridConfiguration);
ConfigureTraceMonitor(config, sendGridConfiguration);
WebHooksConfiguration webHooksConfig = new WebHooksConfiguration();
webHooksConfig.UseReceiver<GitHubWebHookReceiver>();
config.UseWebHooks(webHooksConfig);
JobHost host = new JobHost(config);
host.Call(typeof(MiscellaneousSamples).GetMethod("ExecutionContext"));
host.Call(typeof(FileSamples).GetMethod("ReadWrite"));
host.Call(typeof(SampleSamples).GetMethod("Sample_BindToStream"));
host.Call(typeof(SampleSamples).GetMethod("Sample_BindToString"));
host.Call(typeof(TableSamples).GetMethod("CustomBinding"));
host.RunAndBlock();
}
示例12: RunTimerJobTest
private async Task RunTimerJobTest(Type jobClassType, Func<bool> condition)
{
ExplicitTypeLocator locator = new ExplicitTypeLocator(jobClassType);
JobHostConfiguration config = new JobHostConfiguration
{
TypeLocator = locator
};
config.UseTimers();
JobHost host = new JobHost(config);
host.Start();
await TestHelpers.Await(() =>
{
return condition();
});
host.Stop();
}
示例13: Main
public static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appSettings.json")
.AddInMemoryCollection()
.AddEnvironmentVariables();//appsettings.json will be overridden with azure web appsettings
var configuration = builder.Build();
KeyVaultHelper kv = new KeyVaultHelper(configuration);
KeyVaultHelper.GetCert(configuration);
kv.GetKeyVaultSecretsCerticate();
var azureStorageConnectionString = configuration["General:CloudStorageConnectionString"];
JobHostConfiguration config = new JobHostConfiguration(azureStorageConnectionString);
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();
}
示例14: Main
public static void Main(string[] args)
{
JobHostConfiguration config = new JobHostConfiguration();
FilesConfiguration filesConfig = new FilesConfiguration();
// See https://github.com/Azure/azure-webjobs-sdk/wiki/Running-Locally for details
// on how to set up your local environment
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
filesConfig.RootPath = @"c:\temp\files";
}
config.UseFiles(filesConfig);
config.UseTimers();
config.UseSample();
config.UseCore();
var sendGridConfiguration = new SendGridConfiguration()
{
ToAddress = "[email protected]",
FromAddress = new MailAddress("[email protected]", "WebJobs Extensions Samples")
};
config.UseSendGrid(sendGridConfiguration);
ConfigureTraceMonitor(config, sendGridConfiguration);
EnsureSampleDirectoriesExist(filesConfig.RootPath);
WebHooksConfiguration webHooksConfig = new WebHooksConfiguration();
webHooksConfig.UseReceiver<GitHubWebHookReceiver>();
config.UseWebHooks(webHooksConfig);
JobHost host = new JobHost(config);
host.Call(typeof(MiscellaneousSamples).GetMethod("ExecutionContext"));
host.Call(typeof(FileSamples).GetMethod("ReadWrite"));
host.Call(typeof(SampleSamples).GetMethod("Sample_BindToStream"));
host.Call(typeof(SampleSamples).GetMethod("Sample_BindToString"));
host.Call(typeof(TableSamples).GetMethod("CustomBinding"));
host.RunAndBlock();
}
示例15: Main
public static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
var container = new ServiceContainer();
JobHostConfiguration config = new JobHostConfiguration
{
StorageConnectionString = Configuration["AppSettings:StorageConnectionString"],
DashboardConnectionString = Configuration["AppSettings:StorageConnectionString"],
JobActivator = new JobActivator(container),
NameResolver = new NameResolver(Configuration)
};
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();
}