/// <summary> /// Runs the jobs. /// </summary> /// <param name="host">The host whose jobs should be run.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> to use that will cancel the running jobs.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public static async Task RunAsync(this IJobHost host, CancellationToken cancellationToken = default(CancellationToken)) { if (cancellationToken.CanBeCanceled) { using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken)) { await host.RunImplAsync(cts); } } else { var done = new ManualResetEventSlim(false); using (var cts = new CancellationTokenSource()) { AttachCtrlcSigtermShutdown(cts, done); Console.WriteLine("Application started. Press Ctrl+C to shut down."); try { await host.RunImplAsync(cts); } catch (Exception ex) { await Task.FromException(ex); } finally { done.Set(); } } } }
public static async Task RefreshStatus(this IJobHost jobs, string instanceId) { await jobs.CallAsync(nameof(GetStatusFunction), new Dictionary <string, object> { ["instanceId"] = instanceId }); }
public static async Task <IJobHost> Ready(this IJobHost jobs, TimeSpan?timeout = null) { await jobs.CallAsync(nameof(ReadyFunction), new Dictionary <string, object> { ["timeout"] = timeout }); return(jobs); }
public static async Task <IJobHost> Start(this IJobHost jobs, OrchestrationStarterInfo starterInfo) { await jobs.CallAsync(starterInfo.StarterName, starterInfo.StarterArgs); await jobs.WaitFor(starterInfo.OrchestrationName, starterInfo.Timeout, starterInfo.ExpectedCustomStatus).ThrowIfFailed(); return(jobs); }
/// <summary> /// REMARK: This method does NOT throw when orchestrations have failed. /// Please, chain the <see cref="ThrowIfFailed" /> and <see cref="Purge"/> to this method for that behavior. /// </summary> public static async Task <IJobHost> WaitFor(this IJobHost jobs, string orchestration, TimeSpan?timeout = null) { await jobs.CallAsync(nameof(WaitForFunction), new Dictionary <string, object> { ["timeout"] = timeout, ["name"] = orchestration }); return(jobs); }
public Worker( ILogger <Worker> logger, IJobHost jobHost, CloudQueueClientProvider cloudQueueClientProvider, IConfiguration configuration) { _logger = logger; _jobHost = jobHost; _cloudQueueClientProvider = cloudQueueClientProvider; _configuration = configuration; }
private static async Task RunImplAsync(this IJobHost host, CancellationTokenSource cts) { using (host) { foreach (var job in host.Jobs) { Console.WriteLine($"Running job - {job.GetName()}"); } await host.StartAsync(cts); } }
/// <summary> /// Create orchestrator host /// </summary> /// <param name="graph">graph to be executed</param> /// <param name="jobHost">job host to use</param> /// <param name="maxParallel">max number of parallel task, if null or 0, there is no limit</param> public OrchestratorHost(GraphMap <TKey, TNode, TEdge> graph, IJobHost jobHost, int?maxParallel = null) { graph.Verify(nameof(graph)).IsNotNull(); jobHost.Verify(nameof(jobHost)).IsNotNull(); maxParallel.Verify(nameof(maxParallel)).Assert(x => x == null || x >= 0, "value must be greater then or equal to zero"); _graph = graph; _jobHost = jobHost; _runningKeys = new HashSet <TKey>(_graph.KeyCompare); _maxParallel = maxParallel; _semaphore = maxParallel > 0 ? _semaphore = new SemaphoreSlim((int)maxParallel, (int)maxParallel) : null; }
public JobManager(IEnumerable<IJob> jobs, IJobHost host, IJobCoordinator coordinator) { if (jobs == null) { throw new ArgumentNullException("jobs"); } if (host == null) { throw new ArgumentNullException("host"); } if (coordinator == null) { throw new ArgumentNullException("coordinator"); } _jobs = jobs; _scheduler = new Scheduler(jobs); _host = host; _coordinator = coordinator; _timer = new Timer(OnTimerElapsed); }
public JobManager(IEnumerable <IJob> jobs, IJobHost host, IJobCoordinator coordinator) { if (jobs == null) { throw new ArgumentNullException("jobs"); } if (host == null) { throw new ArgumentNullException("host"); } if (coordinator == null) { throw new ArgumentNullException("coordinator"); } _jobs = jobs; _scheduler = new Scheduler(jobs); _host = host; _coordinator = coordinator; _timer = new Timer(OnTimerElapsed); }
public CustomerJobManager(IList <IJob> jobs, IJobHost host, IJobCoordinator coordinator, TimeSpan startTimeSpan) { if (jobs == null) { throw new ArgumentNullException("jobs"); } if (host == null) { throw new ArgumentNullException("host"); } if (coordinator == null) { throw new ArgumentNullException("coordinator"); } _jobs = jobs; _scheduler = new Scheduler(jobs); _host = host; _coordinator = coordinator; _timer = new Timer(OnTimerElapsed); _starTimeSpan = startTimeSpan; }
public JobManager(IEnumerable<IJob> jobs, IJobHost host, IJobCoordinator coordinator, Action<string> logAction = null) { if (jobs == null) { throw new ArgumentNullException(nameof(jobs)); } if (host == null) { throw new ArgumentNullException(nameof(host)); } if (coordinator == null) { throw new ArgumentNullException(nameof(coordinator)); } _jobs = jobs; _scheduler = new Scheduler(jobs); _host = host; _coordinator = coordinator; _timer = new Timer(OnTimerElapsed); _logAction = logAction; }
public JobManager(IEnumerable <IJob> jobs, IJobHost host, IJobCoordinator coordinator, Action <string> logAction = null) { if (jobs == null) { throw new ArgumentNullException(nameof(jobs)); } if (host == null) { throw new ArgumentNullException(nameof(host)); } if (coordinator == null) { throw new ArgumentNullException(nameof(coordinator)); } _jobs = jobs; _scheduler = new Scheduler(jobs); _host = host; _coordinator = coordinator; _timer = new Timer(OnTimerElapsed); _logAction = logAction; }
public JobManager(IEnumerable<IJob> jobs, IJobHost host) : this(jobs, host, new SingleServerJobCoordinator()) { }
internal Task CallFunctionAsync(string name, IDictionary <string, object?>?args = null) { IJobHost jobHost = this.functionsHost.Services.GetService <IJobHost>(); return(jobHost.CallAsync(name, args)); }
public CustomerJobManager(IList <IJob> jobs, IJobHost host, TimeSpan startTimeSpan) : this(jobs, host, new SingleServerJobCoordinator(), startTimeSpan) { }
public JobService(IAuthorizationAdapter authService, IJobHost host) { this.authService = authService; this.host = host; }
public JobManager(IEnumerable <IJob> jobs, IJobHost host) : this(jobs, host, new SingleServerJobCoordinator()) { }
public PurgeBackgroundJob(IJobHost jobHost) { _jobHost = jobHost; }
public static async Task <IJobHost> Terminate(this IJobHost jobs) { await jobs.CallAsync(nameof(TerminateFunction)); return(jobs); }
public static async Task <IJobHost> Purge(this IJobHost jobs) { await jobs.CallAsync(nameof(PurgeFunction)); return(jobs); }
public static async Task <IJobHost> Start(this IJobHost jobs, EndpointInfo endpointInfo) { await jobs.CallAsync(endpointInfo.StarterName, endpointInfo.StarterArgs); return(jobs); }
/// <summary> /// Runs the jobs. /// </summary> /// <param name="host">The host whose jobs should be run.</param> public static void Run(this IJobHost host) { host.RunAsync().GetAwaiter().GetResult(); }
public OrchestratorHost <TKey, TNode, TEdge> Build(IJobHost jobHost = null, int?maxJobParallel = null) { jobHost = jobHost ?? new JobHost(); return(new OrchestratorHost <TKey, TNode, TEdge>(Graph, jobHost, maxJobParallel)); }
public JobHostService(IJobHost jobhost, ILogger <JobHostService> logger) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _jobHost = jobhost; }