Exemple #1
0
        private void Receives()
        {
            Receive <AttemptCrawl>(attempt =>
            {
                if (Uri.IsWellFormedUriString(attempt.RawStr, UriKind.Absolute))
                {
                    var startJob = new StartJob(new CrawlJob(new Uri(attempt.RawStr, UriKind.Absolute), true), Sender);
                    CommandRouter.Tell(startJob);
                    CommandRouter.Ask <Routees>(new GetRoutees()).ContinueWith(tr =>
                    {
                        var grrr =
                            new SignalRActor.DebugCluster(string.Format("{0} has {1} routees: {2}", CommandRouter,
                                                                        tr.Result.Members.Count(),
                                                                        string.Join(",",
                                                                                    tr.Result.Members.Select(
                                                                                        y => y.ToString()))));

                        return(grrr);
                    }).PipeTo(Sender);
                    Sender.Tell(startJob);
                }
                else
                {
                    Sender.Tell(new BadCrawlAttempt(attempt.RawStr, "Not an absolute URI"));
                }
            });
        }
        private void Receives()
        {
            Receive <AttemptCrawl>(attempt =>
            {
                if (Uri.IsWellFormedUriString(attempt.RawStr, UriKind.Absolute))
                {
                    var startJob = new StartJob(new CrawlJob(new Uri(attempt.RawStr, UriKind.Absolute), true), Sender);
                    CommandRouter.Tell(startJob);
                    var sender = Sender; // need to close over `Sender` when using `PipeTo`
                    CommandRouter.Ask <Routees>(new GetRoutees()).ContinueWith(tr =>
                    {
                        var grrr =
                            new SignalRActor.DebugCluster(
                                $"{CommandRouter} has {tr.Result.Members.Count()} routees: {string.Join(",", tr.Result.Members.Select(y => y.ToString()))}");

                        return(grrr);
                    }).PipeTo(sender);
                    Sender.Tell(startJob);
                }
                else
                {
                    Sender.Tell(new BadCrawlAttempt(attempt.RawStr, "Not an absolute URI"));
                }
            });
        }
Exemple #3
0
        /// <summary>
        /// Returns the job from the message
        /// </summary>
        /// <typeparam name="TJob"></typeparam>
        /// <param name="source"></param>
        /// <returns></returns>
        public static TJob GetJob <TJob>(this StartJob source)
            where TJob : class
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(ObjectTypeDeserializer.Deserialize <TJob>(source.Job));
        }
        private IEnumerable <Notification> When(StartJob message)
        {
            yield return(new Notification(ActorTypes.Agent, message.AgentId, new JobEnqueued(Id)));

            yield return(new Notification(ActorTypes.Agent, message.AgentId, new JobStarted(Id)));

            foreach (var jobResult in JobResultsFunc(message))
            {
                yield return(new Notification(ActorTypes.Agent, message.AgentId, jobResult));
            }

            yield return(new Notification(ActorTypes.Agent, message.AgentId, new JobFinished(Id)));
        }
Exemple #5
0
        private void Ready()
        {
            Receive <StartJob>(start =>
            {
                JobToStart = start;

                // contact all of our peers and see if this job is already running
                ApiBroadcaster.Tell(new FindRunningJob(start.Job));

                // and see if we've done this job before
                Context.ActorSelection("/user/downloads").Tell(new DownloadsMaster.RequestDownloadTrackerFor(start.Job, Self));

                Become(SearchingForJob);
                OutstandingAcknowledgements = ApiBroadcaster.Ask <Routees>(new GetRoutees()).Result.Members.Count();
                Context.SetReceiveTimeout(TimeSpan.FromSeconds(3.0));
            });

            Receive <FindRunningJob>(job => HandleFindRunningJob(job));
        }
        private void Receives()
        {
            Receive <AttemptJobStart>(attempt =>
            {
                CommandRouter.Ask <Routees>(new GetRoutees()).ContinueWith(tr =>
                {
                    var route = new StartJobRoutes(tr.Result.Members.Count());
                    return(route);
                }, TaskContinuationOptions.AttachedToParent & TaskContinuationOptions.ExecuteSynchronously).PipeTo(Self, Sender);
            });

            Receive <StartJobRoutes>(ic => ic.NodeCount == 0, ic =>
            {
                Sender.Tell(ic);
            });

            Receive <StartJobRoutes>(ic =>
            {
                Sender.Tell(ic);


                // TODO:  Need to create a task to get the markts and to run them all.
                JobInfo job  = new JobInfo("RunMe");
                var startJob = new StartJob(new Job(job), Sender);

                CommandRouter.Tell(startJob);

                JobInfo job2  = new JobInfo("MyPetMonkey1");
                var startJob2 = new StartJob(new Job(job2), Sender);

                CommandRouter.Tell(startJob2);

                JobInfo job3  = new JobInfo("AkkaNet");
                var startJob3 = new StartJob(new Job(job3), Sender);

                CommandRouter.Tell(startJob3);
            });

            Receive <AttemptSubscription>(attempt =>
            {
                CommandRouter.Tell(new SubscribeToAllJobs(Sender), Self);
                CommandRouter.Ask <Routees>(new GetRoutees()).ContinueWith(tr =>
                {
                    var message = string.Empty;

                    if (!tr.Result.Members.Any())
                    {
                        message = "Could not find item tasker.  Is the Tasker service running?";
                    }
                    else
                    {
                        message = "Item tasker is running.";
                    }

                    return(new SignalRItemStatusActor.ClusterRoutes(message));
                }, TaskContinuationOptions.AttachedToParent & TaskContinuationOptions.ExecuteSynchronously).PipeTo(Sender);
                Sender.Tell(new SubscribeToAllJobs(Sender), Self);
            });

            Receive <AttemptUnSubscribe>(attempt =>
            {
                CommandRouter.Tell(new UnSubscribeToAllJobs(Sender), Self);
                CommandRouter.Ask <Routees>(new GetRoutees()).ContinueWith(tr =>
                {
                    var grrr =
                        new SignalRItemStatusActor.ClusterRoutes(string.Format("{0} has {1} routees: {2}", CommandRouter,
                                                                               tr.Result.Members.Count(),
                                                                               string.Join(",",
                                                                                           tr.Result.Members.Select(
                                                                                               y => y.ToString()))));

                    return(grrr);
                }, TaskContinuationOptions.AttachedToParent & TaskContinuationOptions.ExecuteSynchronously).PipeTo(Sender);
                Sender.Tell(new UnSubscribeToAllJobs(Sender), Self);
            });
        }
 private IEnumerable <JobResult> GetEmptyJobResults(StartJob startJob)
 {
     yield break;
 }
Exemple #8
0
 private IEnumerable <Notification> When(StartJob message)
 {
     yield return(new Notification(ActorTypes.AgentJobGateway, message.JobId, message));
 }
Exemple #9
0
 private IEnumerable <JobResult> GetHDJobResults(StartJob startJob, ScanTarget[] scanTargets)
 {
     return(scanTargets.Select(st => new JobResult(startJob.JobId, new[] { st })));
 }