Esempio n. 1
0
        public async Task <HttpResponseMessage> CreateJob([FromUri] string channelName, [FromBody] JobRequest req)
        {
            if (req == null || !ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }

            var job = await _jobMan.CreateJobAsync(channelName, req.FromId, req.ToId);

            HostingEnvironment.QueueBackgroundWorkItem(ct => _jobMan.ExecuteJobAsync(job.Id));

            return(Request.CreateResponse(HttpStatusCode.Accepted, job));
        }
Esempio n. 2
0
        public void ExecuteJobAsync()
        {
            var jobMan  = new JobManager(new WebChannelTools());
            var jobTask = jobMan.CreateJobAsync("telegram", 3, 7);

            jobTask.Wait();
            var job = jobTask.Result;

            var task = jobMan.ExecuteJobAsync(job.Id);

            System.Threading.Thread.Sleep(2000);

            using (var ctx = new TelegtoolsContext())
            {
                var jobNow = ctx.Jobs.Find(job.Id);
                Assert.AreEqual(TelegtoolsJobStatus.InProcess, jobNow?.Status);
            }

            task.Wait();
            job = task.Result;

            Assert.AreEqual(TelegtoolsJobStatus.Done, job.Status);
            Assert.NotNull(job.EndDate);
        }