示例#1
0
        protected override async Task Work()
        {
            var logger = RcManager.Logger;

            logger.Verbose("Worker started");

            object    result           = null;
            Exception exception_result = null;

            logger.Verbose("Worker starts executing summary {0}", RcSummary);

            // Execute the computation
            try
            {
                RcSummary.ResetDependencies();
                result = await RcSummary.Execute();
            }
            catch (Exception e)
            {
                exception_result = e;
            }
            try
            {
                RcSummary.CleanupInvalidDependencies();
            }
            catch (Exception e)
            {
                logger.Verbose(e.ToString());
            }

            logger.Verbose("Worker finished executing summary {0}, result={1}, exc={2}", RcSummary, result, exception_result);

            // Set the result/exception in the summary and notify dependents
            await RcSummary.UpdateResult(result, exception_result);

            logger.Verbose("Worker {0} done", GrainId);
        }
示例#2
0
        protected override async Task Work()
        {
            var logger            = RcManager.Logger;
            var notificationtasks = new List <Task>();

            if (Current != null)
            {
                throw new Runtime.OrleansException("illegal state");
            }

            Dictionary <RcSummaryBase, bool> work;

            logger.Verbose("Worker {0} started", GrainId);

            lock (this)
            {
                // take all work out of the queue for processing
                work       = queuedwork;
                queuedwork = new Dictionary <RcSummaryBase, bool>();
            }


            foreach (var workitem in work)
            {
                var summary = workitem.Key;

                logger.Verbose("Worker {0} is scheduling summary {1}", GrainId, summary);

                //var context = RuntimeContext.CurrentActivationContext.CreateReactiveContext();

                object    result           = null;
                Exception exception_result = null;


                logger.Verbose("Worker {0} starts executing summary {1}", GrainId, summary);

                Current = summary;

                // Execute the computation
                try
                {
                    Current.ResetDependencies();
                    result = await Current.Execute();
                }
                catch (Exception e)
                {
                    exception_result = e;
                }
                logger.Verbose("Worker {0} starts removing dependencies", GrainId);
                Current.CleanupInvalidDependencies();
                Current = null;

                logger.Verbose("Worker {0} finished executing summary {1}, result={2}, exc={3}", GrainId, summary, result, exception_result);

                // Set the result/exception in the summary and notify dependents
                notificationtasks.Add(summary.UpdateResult(result, exception_result));
            }

            logger.Verbose("Worker {0} waiting for {1} notification tasks", GrainId, notificationtasks.Count);

            // TODO: we could batch notifications to same silo here
            await Task.WhenAll(notificationtasks);

            logger.Verbose("Worker {0} done", GrainId);
        }