Пример #1
0
        /// <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);
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
 public Worker(
     ILogger <Worker> logger,
     IJobHost jobHost,
     CloudQueueClientProvider cloudQueueClientProvider,
     IConfiguration configuration)
 {
     _logger  = logger;
     _jobHost = jobHost;
     _cloudQueueClientProvider = cloudQueueClientProvider;
     _configuration            = configuration;
 }
Пример #7
0
        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);
            }
        }
Пример #8
0
        /// <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;
        }
Пример #9
0
        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);
        }
Пример #10
0
        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;
        }
Пример #12
0
        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;
        }
Пример #13
0
        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;
        }
Пример #14
0
 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)
 {
 }
Пример #17
0
 public JobService(IAuthorizationAdapter authService, IJobHost host)
 {
     this.authService = authService;
     this.host        = host;
 }
Пример #18
0
 public JobManager(IEnumerable <IJob> jobs, IJobHost host) : this(jobs, host, new SingleServerJobCoordinator())
 {
 }
Пример #19
0
 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);
        }
Пример #23
0
 /// <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));
 }
Пример #25
0
 public JobHostService(IJobHost jobhost, ILogger <JobHostService> logger)
 {
     _logger  = logger ?? throw new ArgumentNullException(nameof(logger));
     _jobHost = jobhost;
 }