public PoolJobProducer(IEnumerable <string> poolAddresses, string user, string worker)
        {
            this.user   = user;
            this.worker = worker;

            foreach (var poolAddress in poolAddresses)
            {
                this.connection = new HubConnectionBuilder()
                                  .WithUrl(poolAddress + "/poolhub", h =>
                {
                    h.Headers.Add("X-USER", this.user);
                    h.Headers.Add("X-WORKER", this.worker);
                })
                                  .Build();

                this.connection.On <JobDTO>("NewJob", j =>
                {
                    lastJob = j;
                    JobCreated?.Invoke(this, new JobCreatedEventArgs {
                        Job = j
                    });
                });

                this.connection.StartAsync().GetAwaiter().GetResult();

                break;
            }
        }
Esempio n. 2
0
        public JobInfo CreateJob(string name,
                                 string userId           = null,
                                 bool trackWhenScheduled = false,
                                 IDictionary <string, object> jobData = null,
                                 int retryCount        = 0,
                                 int retryIntervalSecs = 600)
        {
            using var scope       = scopeFactory.CreateScope();
            using var dataContext = scope.ServiceProvider.GetRequiredService <DataContext>();

            var job = new JobInfo()
            {
                UserId             = userId,
                Name               = name,
                TrackWhenScheduled = trackWhenScheduled,
                JobData            = new Dictionary <string, object>(),
                RetryCount         = retryCount,
                RetryInterval      = retryIntervalSecs,
                State              = JobState.Created,
                Created            = DateTimeOffset.UtcNow,
            };

            if (jobData != null)
            {
                job.JobData = new Dictionary <string, object>(jobData);
            }

            dataContext.Add(job);
            dataContext.SaveChanges();

            JobCreated?.Invoke(this, new JobCreatedEventArgs()
            {
                Job = job
            });

            return(job);
        }
 public void OnJobCreated(IJob e)
 {
     JobCreated?.Invoke(this, e);
 }