public void TestScheduleInBatch()
        {
            JobBatch.Do(() =>
            {
                for (var i = 0; i < 100000; i++)
                {
                    MockJob.Publish();
                }
            });

            StopWorkers();

            Assert.AreEqual(100000, _counter.Value);
        }
示例#2
0
        public IActionResult Post(DtoChirpPost dto)
        {
            _db.BeginTransaction();

            var chirp = new Chirp
            {
                UserId       = int.Parse(User.Identity.Name ?? "1"),
                ChirpTimeUtc = DateTime.UtcNow,
                ChirpType    = ChirpType.Chirp,
                Contents     = dto.Contents
            };

            _db.Chirps.Add(chirp);

            _db.SaveChanges();

            // Publish chirp processing job, before commit.
            // If the publishing fails, the transaction will be rolled back.
            //
            // We're using the job publish as the last committing resource because
            // it does not participate in the DB transaction.

            JobBatch.Do(() =>
            {
                TimelineUpdate.Publish(new TimelineUpdateArgs
                {
                    ChirpId  = chirp.Id,
                    AuthorId = chirp.UserId,
                    TimeUtc  = chirp.ChirpTimeUtc
                });

                HashTagUpdate.Publish(chirp.Id);
            });

            _db.CommitTransaction();

            return(Ok(chirp.Id));
        }