示例#1
0
        public DefaultJobPublisher(MassiveJobsSettings settings,
                                   IMessagePublisher messagePublisher,
                                   IJobTypeProvider jobTypeProvider,
                                   IJobSerializer jobSerializer,
                                   IJobLogger <DefaultJobPublisher> logger)
        {
            _batchSize = settings.PublishBatchSize;

            Settings         = settings;
            MessagePublisher = messagePublisher;
            JobTypeProvider  = jobTypeProvider;
            JobSerializer    = jobSerializer;
            Logger           = logger;

            // This is just to avoid always publishing to a first worker
            // since the new instance of publisher is created on each job batch
            // for scheduled/periodic workers. Actually, immediate workers will
            // also create one instance of publisher per batch to inject into
            // jobs if jobs require it in their constructors.

            var tickCount = Math.Abs(Environment.TickCount);

            if (settings.ImmediateWorkersCount > 0)
            {
                _nextImmediateWorkerIndex = tickCount % settings.ImmediateWorkersCount;
            }
            if (settings.ScheduledWorkersCount > 0)
            {
                _nextScheduledWorkerIndex = tickCount % settings.ScheduledWorkersCount;
            }
            if (settings.LongRunningWorkersCount > 0)
            {
                _nextLongRunningWorkerIndex = tickCount % settings.LongRunningWorkersCount;
            }
        }
示例#2
0
        public JobsBuilder WithSettings(string namePrefix = "", Action <MassiveJobsSettings> configureAction = null)
        {
            var settings = new MassiveJobsSettings(namePrefix);

            configureAction?.Invoke(settings);
            RegisterInstance(settings);
            return(this);
        }
示例#3
0
        public WorkerCoordinator(IJobServiceFactory serviceFactory, IJobLogger <WorkerCoordinator> logger = null)
        {
            ServiceScopeFactory = serviceFactory.GetRequiredService <IJobServiceScopeFactory>();
            ServiceScope        = ServiceScopeFactory.CreateScope();

            _settings = ServiceScope.GetRequiredService <MassiveJobsSettings>();

            _reconnectTimer              = ServiceScope.GetRequiredService <ITimer>();
            _reconnectTimer.TimeElapsed += Reconnect;

            Workers = new List <IWorker>();
            Logger  = logger ?? ServiceScope.GetRequiredService <IJobLogger <WorkerCoordinator> >();

            MessageConsumer = ServiceScope.GetRequiredService <IMessageConsumer>();
            MessageConsumer.Disconnected += MessageBrokerDisconnected;
        }