/// <summary> /// Dequeues a job to do work on. /// </summary> /// <returns>A working record representing the dequeued job.</returns> internal WorkingRecord DequeueRecord() { WorkingRecord working = null; QueueNameFilters queues = null; lock (this.runLocker) { queues = new QueueNameFilters(this.queueFilters.Include, this.queueFilters.Exclude); } using (IRepository repository = this.repositoryFactory.Create()) { using (IDbTransaction transaction = repository.BeginTransaction(IsolationLevel.RepeatableRead)) { QueueRecord queued = repository.GetQueued(this.applicationName, queues, DateTime.UtcNow, transaction); if (queued != null) { working = CreateWorking(queued, this.id, queued.ScheduleId, DateTime.UtcNow); repository.DeleteQueued(queued.Id.Value, transaction); working = repository.CreateWorking(working, transaction); this.logger.Info("Worker {0} ({1}) dequeued '{2}'.", this.name, this.id, queued.JobName); } transaction.Commit(); } } return(working); }
/// <summary> /// Enqueues a job for the given application name and queue name. /// </summary> /// <param name="applicationName">The name of the application to enqueue the job for.</param> /// <param name="queueName">The name of the queue to enqueue the job on, or null for the default queue.</param> /// <param name="repository">The repository to use when enqueueing the job record.</param> public virtual void Enqueue(string applicationName, string queueName, IRepository repository) { if (string.IsNullOrEmpty(applicationName)) { throw new ArgumentNullException("applicationName", "applicationName must contain a value."); } if (string.IsNullOrEmpty(queueName)) { queueName = "*"; } if (repository == null) { throw new ArgumentNullException("repository", "repository cannot be null."); } QueueRecord record = new QueueRecord() { ApplicationName = applicationName, Data = JobSerializer.Serialize(this), JobName = this.Name, JobType = JobSerializer.GetTypeName(this), QueuedOn = DateTime.UtcNow, QueueName = queueName, TryNumber = 1 }; repository.CreateQueued(record, null); }
//获得某个类型的排队 public QueueLogic GetMatching(QueueRecord tbQueue) { QueueLogic matching; if (!QueueManager.Matchings.TryGetValue(tbQueue.Id, out matching)) { switch ((eQueueType)tbQueue.AppType) { case eQueueType.Dungeon: matching = new FubenQueue(tbQueue.Id); break; case eQueueType.BattleField: matching = new FightQueue(tbQueue.Id); break; case eQueueType.ActivityDungeon: matching = new ActivityFubenQueue(tbQueue.Id); break; } QueueManager.Matchings.Add(tbQueue.Id, matching); QueueManager.RefreshMatchRelation(); } return(matching); }
public void WorkerDispose() { IJob job = new TestJob() { Id = Guid.NewGuid() }; SignalsRecord signals = new SignalsRecord() { QueueNames = "*", WorkerSignal = WorkerSignal.None, WorkingSignal = WorkingSignal.None }; QueueRecord queued = new QueueRecord() { Id = 12, ApplicationName = BlueCollarSection.Section.ApplicationName, Data = JsonConvert.SerializeObject(job), JobName = job.Name, JobType = JobSerializer.GetTypeName(job.GetType()), QueuedOn = DateTime.UtcNow, QueueName = "*", TryNumber = 1 }; var transaction = new Mock <IDbTransaction>(); var repository = new Mock <IRepository>(); repository.Setup(r => r.BeginTransaction()).Returns(transaction.Object); repository.Setup(r => r.BeginTransaction(It.IsAny <IsolationLevel>())).Returns(transaction.Object); repository.Setup(r => r.GetQueued(It.IsAny <string>(), It.IsAny <QueueNameFilters>(), It.IsAny <DateTime>(), It.IsAny <IDbTransaction>())).Returns(queued); repository.Setup(r => r.GetWorkingSignals(It.IsAny <long>(), It.IsAny <long?>(), It.IsAny <IDbTransaction>())).Returns(signals); var factory = new Mock <IRepositoryFactory>(); factory.Setup(f => f.Create()).Returns(repository.Object); var logger = new Mock <ILogger>(); Worker worker = null; try { worker = new Worker(BlueCollarSection.Section.ApplicationName, 1, "Test Worker", null, 1, false, factory.Object, logger.Object); worker.Start(); Thread.Sleep(1500); worker.Stop(false); worker.Dispose(); Assert.IsFalse(worker.LoopThreadsAreAlive); worker = null; } finally { if (worker != null) { worker.Dispose(); } } }
public void WorkerExecuteRetry() { IJob job = new TestJob() { ThrowException = true, Retries = 1 }; SignalsRecord signals = new SignalsRecord() { QueueNames = "*", WorkerSignal = WorkerSignal.None, WorkingSignal = WorkingSignal.None }; QueueRecord queued = new QueueRecord() { Id = 12, ApplicationName = BlueCollarSection.Section.ApplicationName, Data = JsonConvert.SerializeObject(job), JobName = job.Name, JobType = JobSerializer.GetTypeName(job.GetType()), QueuedOn = DateTime.UtcNow, QueueName = "*", TryNumber = 1 }; WorkingRecord working = Worker.CreateWorking(queued, 1, null, DateTime.UtcNow); working.Id = 13; var transaction = new Mock <IDbTransaction>(); var repository = new Mock <IRepository>(); repository.Setup(r => r.BeginTransaction()).Returns(transaction.Object); repository.Setup(r => r.BeginTransaction(It.IsAny <IsolationLevel>())).Returns(transaction.Object); repository.Setup(r => r.CreateWorking(It.IsAny <WorkingRecord>(), It.IsAny <IDbTransaction>())).Returns(working); repository.Setup(r => r.GetQueued(It.IsAny <string>(), It.IsAny <QueueNameFilters>(), It.IsAny <DateTime>(), It.IsAny <IDbTransaction>())).Returns(queued); repository.Setup(r => r.GetWorkingSignals(It.IsAny <long>(), It.IsAny <long?>(), It.IsAny <IDbTransaction>())).Returns(signals); var factory = new Mock <IRepositoryFactory>(); factory.Setup(f => f.Create()).Returns(repository.Object); var logger = new Mock <ILogger>(); using (Worker worker = new Worker(BlueCollarSection.Section.ApplicationName, 1, "Test Worker", null, 1, false, factory.Object, logger.Object)) { worker.Start(); Thread.Sleep(1500); Assert.AreEqual(WorkerStatus.Working, worker.Status); } repository.Verify(r => r.CreateHistory(It.Is <HistoryRecord>(h => h.Status == HistoryStatus.Failed), It.IsAny <IDbTransaction>())); repository.Verify(r => r.CreateQueued(It.Is <QueueRecord>(q => q.TryNumber == 2), It.IsAny <IDbTransaction>())); }
public static QueueOption ConvertTo(this QueueRecord subject) { (string KeyName, string AccessKey) = QueueAuthorization.Parse(subject.AuthSendListen); return(new QueueOption { QueueName = subject.QueueName, Namespace = subject.Namespace, KeyName = KeyName, AccessKey = AccessKey, }); }
public void WorkerDequeue() { IJob job = new TestJob() { Id = Guid.NewGuid() }; SignalsRecord signals = new SignalsRecord() { QueueNames = "*", WorkerSignal = WorkerSignal.None, WorkingSignal = WorkingSignal.None }; QueueRecord queued = new QueueRecord() { Id = 12, ApplicationName = BlueCollarSection.Section.ApplicationName, Data = JsonConvert.SerializeObject(job), JobName = job.Name, JobType = JobSerializer.GetTypeName(job.GetType()), QueuedOn = DateTime.UtcNow, QueueName = "*", TryNumber = 1 }; var transaction = new Mock <IDbTransaction>(); var repository = new Mock <IRepository>(); repository.Setup(r => r.BeginTransaction()).Returns(transaction.Object); repository.Setup(r => r.BeginTransaction(It.IsAny <IsolationLevel>())).Returns(transaction.Object); repository.Setup(r => r.GetQueued(It.IsAny <string>(), It.IsAny <QueueNameFilters>(), It.IsAny <DateTime>(), It.IsAny <IDbTransaction>())).Returns(queued); repository.Setup(r => r.GetWorkingSignals(It.IsAny <long>(), It.IsAny <long?>(), It.IsAny <IDbTransaction>())).Returns(signals); var factory = new Mock <IRepositoryFactory>(); factory.Setup(f => f.Create()).Returns(repository.Object); var logger = new Mock <ILogger>(); using (Worker worker = new Worker(BlueCollarSection.Section.ApplicationName, 1, "Test Worker", null, 1, false, factory.Object, logger.Object)) { worker.Start(); Thread.Sleep(1500); } repository.Verify(r => r.GetQueued(BlueCollarSection.Section.ApplicationName, It.IsAny <QueueNameFilters>(), It.IsAny <DateTime>(), It.IsAny <IDbTransaction>())); repository.Verify(r => r.DeleteQueued(12, It.IsAny <IDbTransaction>())); repository.Verify(r => r.CreateWorking(It.Is <WorkingRecord>(w => w.ApplicationName == BlueCollarSection.Section.ApplicationName && w.WorkerId == 1), It.IsAny <IDbTransaction>())); }
/// <summary> /// Creates a working record from the given queued record. /// </summary> /// <param name="queued">The queued record to create the working record for.</param> /// <param name="workerId">The ID of the worker to create the record for.</param> /// <param name="scheduleId">The ID of the schedule to create the record for.</param> /// <param name="startedOn">The start date to create the record with.</param> /// <returns>A working record.</returns> internal static WorkingRecord CreateWorking(QueueRecord queued, long workerId, long?scheduleId, DateTime startedOn) { return(new WorkingRecord() { ApplicationName = queued.ApplicationName, Data = queued.Data, JobName = queued.JobName, JobType = queued.JobType, QueuedOn = queued.QueuedOn, QueueName = queued.QueueName, ScheduleId = scheduleId, StartedOn = startedOn, TryNumber = queued.TryNumber, WorkerId = workerId }); }
public ErrorCodes CheckPush(QueueRecord tbQuene, List <ulong> ids) { if (ids.Count > tbQuene.CountLimit) { return(ErrorCodes.Error_QueueCountMax); } foreach (var id in ids) { if (QueueManager.Characters.ContainsKey(id)) { Logger.Error("MatchingManager Push Error !characterId is Have ! Id={0}", id); return(ErrorCodes.Error_CharacterHaveQueue); } } return(ErrorCodes.OK); }
public string Put(string queueName, byte[] item, int maxRetries = 5) { var record = new QueueRecord() { Payload = item, QueueName = queueName, RetryCount = 0, MaxRetries = maxRetries }; using (var db = _dbFactory()) { var dbSet = _dbSetProvider(db); dbSet.Add(record); db.SaveChanges(); } return(record.Id); }
public void WorkerDequeue() { IJob job = new TestJob() { Id = Guid.NewGuid() }; SignalsRecord signals = new SignalsRecord() { QueueNames = "*", WorkerSignal = WorkerSignal.None, WorkingSignal = WorkingSignal.None }; QueueRecord queued = new QueueRecord() { Id = 12, ApplicationName = BlueCollarSection.Section.ApplicationName, Data = JsonConvert.SerializeObject(job), JobName = job.Name, JobType = JobSerializer.GetTypeName(job.GetType()), QueuedOn = DateTime.UtcNow, QueueName = "*", TryNumber = 1 }; var transaction = new Mock<IDbTransaction>(); var repository = new Mock<IRepository>(); repository.Setup(r => r.BeginTransaction()).Returns(transaction.Object); repository.Setup(r => r.BeginTransaction(It.IsAny<IsolationLevel>())).Returns(transaction.Object); repository.Setup(r => r.GetQueued(It.IsAny<string>(), It.IsAny<QueueNameFilters>(), It.IsAny<DateTime>(), It.IsAny<IDbTransaction>())).Returns(queued); repository.Setup(r => r.GetWorkingSignals(It.IsAny<long>(), It.IsAny<long?>(), It.IsAny<IDbTransaction>())).Returns(signals); var factory = new Mock<IRepositoryFactory>(); factory.Setup(f => f.Create()).Returns(repository.Object); var logger = new Mock<ILogger>(); using (Worker worker = new Worker(BlueCollarSection.Section.ApplicationName, 1, "Test Worker", null, 1, false, factory.Object, logger.Object)) { worker.Start(); Thread.Sleep(1500); } repository.Verify(r => r.GetQueued(BlueCollarSection.Section.ApplicationName, It.IsAny<QueueNameFilters>(), It.IsAny<DateTime>(), It.IsAny<IDbTransaction>())); repository.Verify(r => r.DeleteQueued(12, It.IsAny<IDbTransaction>())); repository.Verify(r => r.CreateWorking(It.Is<WorkingRecord>(w => w.ApplicationName == BlueCollarSection.Section.ApplicationName && w.WorkerId == 1), It.IsAny<IDbTransaction>())); }
/// <summary> /// Performs the concrete request operation and returns the output /// as a byte array. /// </summary> /// <param name="context">The HTTP context to perform the request for.</param> /// <param name="model">The model passed in the request's content body.</param> /// <returns>The result of the request.</returns> protected override object PerformRequest(HttpContextBase context, EnqueueJobRecord model) { if (model == null) { throw new ArgumentNullException("model", "model cannot be null."); } QueueRecord record = Repository.CreateQueued( new QueueRecord() { ApplicationName = ApplicationName, Data = model.Data, JobName = model.JobName, JobType = model.JobType, QueuedOn = DateTime.UtcNow, QueueName = model.QueueName, TryNumber = 1 }, null); return(new { Id = record.Id }); }
/// <summary> /// Get queue tests. /// </summary> protected void GetQueued() { if (this.Repository != null) { IJob job = new TestJob() { Id = Guid.NewGuid() }; DateTime now = DateTime.UtcNow.FloorWithSeconds().AddSeconds(-1); WorkerRecord workerRecord = new WorkerRecord() { ApplicationName = BlueCollarSection.Section.ApplicationName, MachineAddress = Machine.Address, MachineName = Machine.Name, Name = "Test Worker", QueueNames = "*", Signal = WorkerSignal.Stop, Status = WorkerStatus.Working, Startup = WorkerStartupType.Automatic, UpdatedOn = now }; this.Repository.CreateWorker(workerRecord, null); QueueRecord queueRecord = new QueueRecord() { ApplicationName = workerRecord.ApplicationName, Data = JobSerializer.Serialize(job), JobName = job.Name, JobType = JobSerializer.GetTypeName(job.GetType()), QueuedOn = now, QueueName = "*", TryNumber = 1 }; this.Repository.CreateQueued(queueRecord, null); Assert.IsNotNull(this.Repository.GetQueued(workerRecord.ApplicationName, QueueNameFilters.Any(), DateTime.UtcNow, null)); } }
/// <summary> /// Creates a queue record. /// </summary> /// <param name="record">The record to create.</param> /// <param name="transaction">The transaction to use, if applicable.</param> /// <returns>The created record.</returns> public QueueRecord CreateQueued(QueueRecord record, IDbTransaction transaction) { throw new NotImplementedException(); }
/// <summary> /// Get queued details tests. /// </summary> protected void GetQueuedDetails() { if (this.Repository != null) { IJob job = new TestJob() { Id = Guid.NewGuid() }; WorkerRecord workerRecord = new WorkerRecord() { ApplicationName = BlueCollarSection.Section.ApplicationName, MachineAddress = Machine.Address, MachineName = Machine.Name, Name = "Test Worker", QueueNames = "*", Signal = WorkerSignal.Stop, Status = WorkerStatus.Working, Startup = WorkerStartupType.Automatic, UpdatedOn = DateTime.UtcNow }; this.Repository.CreateWorker(workerRecord, null); QueueRecord queueRecord = new QueueRecord() { ApplicationName = workerRecord.ApplicationName, Data = JobSerializer.Serialize(job), JobName = job.Name, JobType = JobSerializer.GetTypeName(job.GetType()), QueuedOn = DateTime.UtcNow, QueueName = "*", TryNumber = 1 }; this.Repository.CreateQueued(queueRecord, null); QueueDetailsRecord queueDetailsRecord = this.Repository.GetQueuedDetails(queueRecord.Id.Value, null); Assert.IsNotNull(queueDetailsRecord); Assert.AreEqual(queueRecord.Id, queueDetailsRecord.Id); Assert.IsFalse(string.IsNullOrEmpty(queueDetailsRecord.Data)); } }
/// <summary> /// Get queued list tests. /// </summary> protected void GetQueuedList() { if (this.Repository != null) { IJob job = new TestJob() { Id = Guid.NewGuid() }; WorkerRecord workerRecord = new WorkerRecord() { ApplicationName = BlueCollarSection.Section.ApplicationName, MachineAddress = Machine.Address, MachineName = Machine.Name, Name = "Test Worker", QueueNames = "*", Signal = WorkerSignal.Stop, Status = WorkerStatus.Working, Startup = WorkerStartupType.Automatic, UpdatedOn = DateTime.UtcNow }; this.Repository.CreateWorker(workerRecord, null); QueueRecord queueRecord = new QueueRecord() { ApplicationName = workerRecord.ApplicationName, Data = JobSerializer.Serialize(job), JobName = job.Name, JobType = JobSerializer.GetTypeName(job.GetType()), QueuedOn = DateTime.UtcNow, QueueName = "*", TryNumber = 1 }; this.Repository.CreateQueued(queueRecord, null); var list = this.Repository.GetQueuedList(workerRecord.ApplicationName, null, 100, 0, null); Assert.IsNotNull(list); Assert.AreEqual(1, list.TotalCount); Assert.AreEqual(1, list.Records.Count); list = this.Repository.GetQueuedList(workerRecord.ApplicationName, "boo", 100, 0, null); Assert.IsNotNull(list); Assert.AreEqual(0, list.TotalCount); Assert.AreEqual(0, list.Records.Count); } }
/// <summary> /// Get schedule date exists for schedule tests. /// </summary> protected void GetScheduleDateExistsForSchedule() { if (this.Repository != null) { DateTime now = DateTime.UtcNow.FloorWithSeconds(); TestJob job = new TestJob(); ScheduleRecord scheduleRecord = new ScheduleRecord() { ApplicationName = BlueCollarSection.Section.ApplicationName, Name = "Test", RepeatType = ScheduleRepeatType.Days, RepeatValue = 1, StartOn = now.AddDays(-1) }; this.Repository.CreateSchedule(scheduleRecord, null); ScheduledJobRecord scheduledJobRecord = new ScheduledJobRecord() { JobType = JobSerializer.GetTypeName(job), ScheduleId = scheduleRecord.Id.Value }; this.Repository.CreateScheduledJob(scheduledJobRecord, null); Assert.IsFalse(this.Repository.GetScheduleDateExistsForSchedule(scheduleRecord.Id.Value, now, null)); QueueRecord queueRecord = new QueueRecord() { ApplicationName = scheduleRecord.ApplicationName, Data = JobSerializer.Serialize(job), JobName = job.Name, JobType = JobSerializer.GetTypeName(job), QueuedOn = now, ScheduleId = scheduleRecord.Id, TryNumber = 1 }; this.Repository.CreateQueued(queueRecord, null); Assert.IsTrue(this.Repository.GetScheduleDateExistsForSchedule(scheduleRecord.Id.Value, now, null)); } }
/// <summary> /// Creates a queue record. /// </summary> /// <param name="record">The record to create.</param> /// <param name="transaction">The transaction to use, if applicable.</param> /// <returns>The created record.</returns> public QueueRecord CreateQueued(QueueRecord record, IDbTransaction transaction) { throw new NotImplementedException(); }
public QueueRecord CreateQueued(QueueRecord record, IDbTransaction transaction) { const string Sql = @"INSERT INTO [BlueCollarQueue]([ApplicationName],[ScheduleId],[QueueName],[JobName],[JobType],[Data],[QueuedOn],[TryNumber]) VALUES(@ApplicationName,@ScheduleId,@QueueName,@JobName,@JobType,@Data,@QueuedOn,@TryNumber); SELECT CAST(SCOPE_IDENTITY() AS bigint);"; record.Id = this.connection.Query<long>( Sql, record, transaction, true, null, null).First(); return record; }
public void WorkerDispose() { IJob job = new TestJob() { Id = Guid.NewGuid() }; SignalsRecord signals = new SignalsRecord() { QueueNames = "*", WorkerSignal = WorkerSignal.None, WorkingSignal = WorkingSignal.None }; QueueRecord queued = new QueueRecord() { Id = 12, ApplicationName = BlueCollarSection.Section.ApplicationName, Data = JsonConvert.SerializeObject(job), JobName = job.Name, JobType = JobSerializer.GetTypeName(job.GetType()), QueuedOn = DateTime.UtcNow, QueueName = "*", TryNumber = 1 }; var transaction = new Mock<IDbTransaction>(); var repository = new Mock<IRepository>(); repository.Setup(r => r.BeginTransaction()).Returns(transaction.Object); repository.Setup(r => r.BeginTransaction(It.IsAny<IsolationLevel>())).Returns(transaction.Object); repository.Setup(r => r.GetQueued(It.IsAny<string>(), It.IsAny<QueueNameFilters>(), It.IsAny<DateTime>(), It.IsAny<IDbTransaction>())).Returns(queued); repository.Setup(r => r.GetWorkingSignals(It.IsAny<long>(), It.IsAny<long?>(), It.IsAny<IDbTransaction>())).Returns(signals); var factory = new Mock<IRepositoryFactory>(); factory.Setup(f => f.Create()).Returns(repository.Object); var logger = new Mock<ILogger>(); Worker worker = null; try { worker = new Worker(BlueCollarSection.Section.ApplicationName, 1, "Test Worker", null, 1, false, factory.Object, logger.Object); worker.Start(); Thread.Sleep(1500); worker.Stop(false); worker.Dispose(); Assert.IsFalse(worker.LoopThreadsAreAlive); worker = null; } finally { if (worker != null) { worker.Dispose(); } } }
public void WorkerExecuteTimeout() { IJob job = new TestJob() { SleepDuration = 100, Timeout = 10 }; SignalsRecord signals = new SignalsRecord() { QueueNames = "*", WorkerSignal = WorkerSignal.None, WorkingSignal = WorkingSignal.None }; QueueRecord queued = new QueueRecord() { Id = 12, ApplicationName = BlueCollarSection.Section.ApplicationName, Data = JsonConvert.SerializeObject(job), JobName = job.Name, JobType = JobSerializer.GetTypeName(job.GetType()), QueuedOn = DateTime.UtcNow, QueueName = "*", TryNumber = 1 }; WorkingRecord working = Worker.CreateWorking(queued, 1, null, DateTime.UtcNow); working.Id = 13; var transaction = new Mock<IDbTransaction>(); var repository = new Mock<IRepository>(); repository.Setup(r => r.BeginTransaction()).Returns(transaction.Object); repository.Setup(r => r.BeginTransaction(It.IsAny<IsolationLevel>())).Returns(transaction.Object); repository.Setup(r => r.CreateWorking(It.IsAny<WorkingRecord>(), It.IsAny<IDbTransaction>())).Returns(working); repository.Setup(r => r.GetQueued(It.IsAny<string>(), It.IsAny<QueueNameFilters>(), It.IsAny<DateTime>(), It.IsAny<IDbTransaction>())).Returns(queued); repository.Setup(r => r.GetWorkingSignals(It.IsAny<long>(), It.IsAny<long?>(), It.IsAny<IDbTransaction>())).Returns(signals); var factory = new Mock<IRepositoryFactory>(); factory.Setup(f => f.Create()).Returns(repository.Object); var logger = new Mock<ILogger>(); using (Worker worker = new Worker(BlueCollarSection.Section.ApplicationName, 1, "Test Worker", null, 1, false, factory.Object, logger.Object)) { worker.Start(); Thread.Sleep(1500); } repository.Verify(r => r.CreateHistory(It.Is<HistoryRecord>(h => h.Status == HistoryStatus.TimedOut), It.IsAny<IDbTransaction>())); }
/// <summary> /// Delete all tests. /// </summary> protected void DeleteAll() { if (this.Repository != null) { IJob job = new TestJob() { Id = Guid.NewGuid() }; WorkerRecord workerRecord = new WorkerRecord() { ApplicationName = BlueCollarSection.Section.ApplicationName, MachineAddress = Machine.Address, MachineName = Machine.Name, Name = "Test Worker", QueueNames = "*", Signal = WorkerSignal.Stop, Status = WorkerStatus.Working, Startup = WorkerStartupType.Automatic, UpdatedOn = DateTime.UtcNow }; this.Repository.CreateWorker(workerRecord, null); QueueRecord queueRecord = new QueueRecord() { ApplicationName = workerRecord.ApplicationName, Data = JsonConvert.SerializeObject(job), JobName = job.Name, JobType = job.GetType().FullName + ", " + job.GetType().Assembly.GetName().Name, QueuedOn = DateTime.UtcNow, QueueName = "*", TryNumber = 1 }; this.Repository.CreateQueued(queueRecord, null); ScheduleRecord scheduleRecord = new ScheduleRecord() { ApplicationName = workerRecord.ApplicationName, Name = "Test", RepeatType = ScheduleRepeatType.Days, RepeatValue = 1, StartOn = DateTime.UtcNow }; this.Repository.CreateSchedule(scheduleRecord, null); ScheduledJobRecord scheduledJobRecord = new ScheduledJobRecord() { JobType = JobSerializer.GetTypeName(job.GetType()), ScheduleId = scheduleRecord.Id.Value }; this.Repository.CreateScheduledJob(scheduledJobRecord, null); WorkingRecord workingRecord = new WorkingRecord() { ApplicationName = workerRecord.ApplicationName, Data = JobSerializer.Serialize(job), JobName = job.Name, JobType = JobSerializer.GetTypeName(job.GetType()), QueuedOn = DateTime.UtcNow, QueueName = null, ScheduleId = scheduleRecord.Id, StartedOn = DateTime.UtcNow, TryNumber = 1, WorkerId = workerRecord.Id.Value }; this.Repository.CreateWorking(workingRecord, null); HistoryRecord historyRecord = new HistoryRecord() { ApplicationName = workerRecord.ApplicationName, Data = JobSerializer.Serialize(job), FinishedOn = DateTime.UtcNow, JobName = job.Name, JobType = JobSerializer.GetTypeName(job.GetType()), QueuedOn = DateTime.UtcNow, ScheduleId = scheduleRecord.Id, StartedOn = DateTime.UtcNow, Status = HistoryStatus.Succeeded, TryNumber = 1, WorkerId = workerRecord.Id.Value }; this.Repository.CreateHistory(historyRecord, null); this.Repository.DeleteAll(BlueCollarSection.Section.ApplicationName, null); Assert.AreEqual(0, this.Repository.GetHistoryList(workerRecord.ApplicationName, null, 100, 0, null).TotalCount); Assert.AreEqual(0, this.Repository.GetWorkingList(workerRecord.ApplicationName, null, 100, 0, null).TotalCount); Assert.AreEqual(0, this.Repository.GetWorkerList(workerRecord.ApplicationName, null, 100, 0, null).TotalCount); Assert.AreEqual(0, this.Repository.GetQueuedList(workerRecord.ApplicationName, null, 100, 0, null).TotalCount); Assert.AreEqual(0, this.Repository.GetScheduledJobList(workerRecord.ApplicationName, scheduleRecord.Id.Value, null, 0, 100, null).TotalCount); Assert.AreEqual(0, this.Repository.GetScheduleList(workerRecord.ApplicationName, null, 100, 0, null).TotalCount); } }
public static ErrorCodes CheckPush(QueueRecord tbQuene, List <ulong> ids) { return(mStaticImpl.CheckPush(tbQuene, ids)); }
/// <summary> /// Creates a working record from the given queued record. /// </summary> /// <param name="queued">The queued record to create the working record for.</param> /// <param name="workerId">The ID of the worker to create the record for.</param> /// <param name="scheduleId">The ID of the schedule to create the record for.</param> /// <param name="startedOn">The start date to create the record with.</param> /// <returns>A working record.</returns> internal static WorkingRecord CreateWorking(QueueRecord queued, long workerId, long? scheduleId, DateTime startedOn) { return new WorkingRecord() { ApplicationName = queued.ApplicationName, Data = queued.Data, JobName = queued.JobName, JobType = queued.JobType, QueuedOn = queued.QueuedOn, QueueName = queued.QueueName, ScheduleId = scheduleId, StartedOn = startedOn, TryNumber = queued.TryNumber, WorkerId = workerId }; }
/// <summary> /// Delete queued tests. /// </summary> protected void DeleteQueued() { if (this.Repository != null) { IJob job = new TestJob() { Id = Guid.NewGuid() }; WorkerRecord workerRecord = new WorkerRecord() { ApplicationName = BlueCollarSection.Section.ApplicationName, MachineAddress = Machine.Address, MachineName = Machine.Name, Name = "Test Worker", QueueNames = "*", Signal = WorkerSignal.Stop, Status = WorkerStatus.Working, Startup = WorkerStartupType.Automatic, UpdatedOn = DateTime.UtcNow }; this.Repository.CreateWorker(workerRecord, null); QueueRecord queueRecord = new QueueRecord() { ApplicationName = workerRecord.ApplicationName, Data = JsonConvert.SerializeObject(job), JobName = job.Name, JobType = job.GetType().FullName + ", " + job.GetType().Assembly.GetName().Name, QueuedOn = DateTime.UtcNow, QueueName = "*", TryNumber = 1 }; this.Repository.CreateQueued(queueRecord, null); this.Repository.DeleteQueued(queueRecord.Id.Value, null); Assert.IsNull(this.Repository.GetQueued(queueRecord.ApplicationName, QueueNameFilters.Any(), DateTime.UtcNow, null)); } }
/// <summary> /// Get counts tests. /// </summary> protected void GetCounts() { if (this.Repository != null) { IJob job = new TestJob() { Id = Guid.NewGuid() }; string jobData = JobSerializer.Serialize(job); string typeName = JobSerializer.GetTypeName(job.GetType()); WorkerRecord workerRecord = new WorkerRecord() { ApplicationName = BlueCollarSection.Section.ApplicationName, MachineAddress = Machine.Address, MachineName = Machine.Name, Name = "Test Worker", QueueNames = "*", Signal = WorkerSignal.Stop, Status = WorkerStatus.Working, Startup = WorkerStartupType.Automatic, UpdatedOn = DateTime.UtcNow }; this.Repository.CreateWorker(workerRecord, null); QueueRecord queueRecord = new QueueRecord() { ApplicationName = workerRecord.ApplicationName, Data = jobData, JobName = job.Name, JobType = typeName, QueuedOn = DateTime.UtcNow, QueueName = "*", TryNumber = 1 }; this.Repository.CreateQueued(queueRecord, null); for (int i = 0; i < 10; i++) { HistoryRecord historyRecord = new HistoryRecord() { ApplicationName = workerRecord.ApplicationName, Data = jobData, FinishedOn = DateTime.UtcNow, JobName = job.Name, JobType = typeName, QueuedOn = DateTime.UtcNow, QueueName = "*", StartedOn = DateTime.UtcNow, Status = HistoryStatus.Succeeded, TryNumber = 1, WorkerId = workerRecord.Id.Value }; this.Repository.CreateHistory(historyRecord, null); } ScheduleRecord scheduleRecord = new ScheduleRecord() { ApplicationName = workerRecord.ApplicationName, Name = "Test Schedule 1", RepeatType = ScheduleRepeatType.Days, RepeatValue = 1, StartOn = DateTime.UtcNow }; this.Repository.CreateSchedule(scheduleRecord, null); scheduleRecord.Id = null; scheduleRecord.Name = "Test Schedule 2"; this.Repository.CreateSchedule(scheduleRecord, null); CountsRecord counts = this.Repository.GetCounts(workerRecord.ApplicationName, null); Assert.IsNotNull(counts); Assert.AreEqual(10, counts.HistoryCount); Assert.AreEqual(1, counts.QueueCount); Assert.AreEqual(2, counts.ScheduleCount); Assert.AreEqual(1, counts.WorkerCount); Assert.AreEqual(0, counts.WorkingCount); } }
//获得某个类型的排队 public static QueueLogic GetMatching(QueueRecord tbQueue) { return(mStaticImpl.GetMatching(tbQueue)); }
/// <summary> /// Enqueues a job for the given application name and queue name. /// </summary> /// <param name="applicationName">The name of the application to enqueue the job for.</param> /// <param name="queueName">The name of the queue to enqueue the job on, or null for the default queue.</param> /// <param name="repository">The repository to use when enqueueing the job record.</param> public virtual void Enqueue(string applicationName, string queueName, IRepository repository) { if (string.IsNullOrEmpty(applicationName)) { throw new ArgumentNullException("applicationName", "applicationName must contain a value."); } if (string.IsNullOrEmpty(queueName)) { queueName = "*"; } if (repository == null) { throw new ArgumentNullException("repository", "repository cannot be null."); } QueueRecord record = new QueueRecord() { ApplicationName = applicationName, Data = JobSerializer.Serialize(this), JobName = this.Name, JobType = JobSerializer.GetTypeName(this), QueuedOn = DateTime.UtcNow, QueueName = queueName, TryNumber = 1 }; repository.CreateQueued(record, null); }