Ejemplo n.º 1
0
        public async Task <ActionResult> FindTime(long id, DateTime dt, SchedulerResponse response)
        {
            var user = await _userService.FindUserById(User.Identity.GetUserId());

            _eventShedulerService.SetResponse(id, user, response, dt);

            _unitOfWork.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public static SchedulerResponse Update(SchedulerResponse updatedRecord)
        {
            //
            SchedulerResponse _m = GlobalStorage.SchedulerStorage.Values
                                   .Where(a => a.Id == updatedRecord.Id)
                                   .Select(a => a).ToList()[0];

            //

            GlobalStorage.SchedulerStorage.TryUpdate(updatedRecord.Id, updatedRecord, _m);
            return(updatedRecord);
        }
Ejemplo n.º 3
0
        public static bool RemoveOnlyFromSchedulerPayload(string id)
        {
            bool result = false;

            SchedulerResponse _data = new SchedulerResponse();

            foreach (var item in GlobalStorage.SchedulerStorage)
            {
                GlobalStorage.SchedulerStorage.TryRemove(id, out _data);
                result = true;
            }
            return(result);
        }
Ejemplo n.º 4
0
        private void setSchedule()
        {
            string applicationPath = System.Reflection.Assembly.GetEntryAssembly().Location + " /silent /update";


            SchedulerResponse response = WindowTaskScheduler
                                         .Configure()
                                         .CreateTask("r1-updater", applicationPath)
                                         .RunDaily()
                                         .RunEveryXMinutes(Properties.Settings.Default.runevery * 60)
                                         .RunDurationFor(new TimeSpan(18, 0, 0))
                                         .SetStartDate(new DateTime(2015, 8, 8))
                                         .SetStartTime(new TimeSpan(8, 0, 0))
                                         .Execute();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Delete record from the payload
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool Delete(string id)
        {
            bool result = false;
            //logic to delete
            SchedulerResponse _scheduler = new SchedulerResponse();

            foreach (var item in GlobalStorage.SchedulerStorage)
            {
                try
                {
                    if ((item.Key == id))
                    {
                        GlobalStorage.SchedulerStorage.TryRemove(id, out _scheduler);
                        result = true;
                        break;
                    }
                }
                catch (Exception ex)
                {
                    var err = ex.InnerException;
                }
            }
            return(result);
        }
Ejemplo n.º 6
0
        public void SetResponse(long eventId, AngoraUser user, SchedulerResponse response, DateTime time)
        {
            var vent = _eventService.FindById(eventId);

            vent.Scheduler = vent.Scheduler ?? new EventScheduler();

            var resp = vent.Scheduler.Responses.FirstOrDefault(r => r.User.Id.Equals(user.Id) && r.Time.CompareTo(time) == 0);

            if (resp == null)
            {
                vent.Scheduler.Responses.Add(new EventSchedulerResponse
                {
                    User     = user,
                    Response = response,
                    Time     = time
                });
            }
            else
            {
                resp.Response = response;
            }

            _eventService.Update(vent);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Create SchedulerPayload
 /// </summary>
 /// <param name="newRecord"></param>
 /// <returns></returns>
 public static SchedulerResponse Create(SchedulerResponse newRecord)
 {
     GlobalStorage.SchedulerStorage.TryAdd(newRecord.Id, newRecord);
     return(newRecord);
 }
Ejemplo n.º 8
0
        public async Task <IActionResult> ExecutePyAsync(string id)
        {
            string zmkResponse = "";
            string filePath    = "";
            string reqBody     = "";

            try
            {
                //read cron information from the request body
                using (var reader = new StreamReader(Request.Body))
                {
                    var body = reader.ReadToEnd();
                    reqBody = body.ToString();
                }

                //
                foreach (var record in codeResponse)
                {
                    if (record.Id.ToString() == id)
                    {
                        filePath = record.FilePath;
                        break;
                    }
                }
                //
                if (!string.IsNullOrEmpty(filePath))
                {
                    zmkResponse = await pyCompileClient.ExecutePy(filePath, "");

                    var jsonObj = JsonConvert.DeserializeObject <ExecuteCodeResponse>(zmkResponse);
                    jsonObj.executedAt = DateTime.Now;
                    List <ExecuteCodeResponse> tresp = new List <ExecuteCodeResponse>();
                    tresp.Add(jsonObj);

                    JObject cronjson = JObject.Parse(reqBody);
                    if (cronjson["recurrence"].ToString() == "REPEAT")
                    {
                        //check if same job is scheduled
                        ISchedulerFactory schfack   = new StdSchedulerFactory();
                        IScheduler        scheduler = await schfack.GetScheduler();

                        var jobKey = new JobKey(filePath);
                        if (await scheduler.CheckExists(jobKey))
                        {
                            await scheduler.ResumeJob(jobKey);
                        }
                        else
                        {
                            #region create quartz job for execute code
                            ITrigger trigger = TriggerBuilder.Create()
                                               .WithIdentity($"Execute Code Job-{DateTime.Now}")
                                               .WithCronSchedule(cronjson["cronExpression"].ToString())
                                               .WithPriority(1)
                                               .Build();

                            IJobDetail job = JobBuilder.Create <ExecuteCodeJob>()
                                             .WithIdentity(filePath)
                                             .Build();

                            job.JobDataMap["id"]       = id;
                            job.JobDataMap["filePath"] = filePath;
                            job.JobDataMap["baseurl"]  = Configuration["PyServiceLocation:srvurl"];

                            await _scheduler.ScheduleJob(job, trigger);

                            //add to scheduler payload
                            SchedulerResponse schJob = new SchedulerResponse()
                            {
                                CreatedOn      = DateTime.Now.ToString(),
                                CronExpression = cronjson["cronExpression"].ToString(),
                                DateCreated    = DateTime.Now,
                                EditedOn       = DateTime.Now.ToString(),
                                FilePath       = filePath,
                                Id             = id,
                                Name           = id,
                                Type           = "PYTHON",
                                Url            = "",
                                Recurrence     = cronjson["recurrence"].ToString(),
                                StartDate      = (cronjson["startDate"] == null) ? "" : cronjson["startDate"].ToString(),
                                //cronjson["startDate"].ToString(),
                                StartTimeH = (cronjson["startTimeH"] == null) ? "" : cronjson["startTimeH"].ToString(),
                                StartTimeM = (cronjson["startTimeM"] == null) ? "" : cronjson["startTimeM"].ToString(),
                                // ZMKResponse = tresp.ToList<object>(),
                                History = tresp.ToList <object>()
                            };
                            SchedulerPayload.Create(schJob);
                            #endregion
                        }
                    }
                    else
                    {
                        //add history
                        JArray jHist = new JArray();
                        foreach (var r in tresp)
                        {
                            jHist.Add(new JObject()
                            {
                                { "idforData", r.idforData },
                                { "status", r.status },
                                { "executedAt", r.executedAt }
                            });
                        }
                        //add to scheduler payload
                        SchedulerResponse schJob = new SchedulerResponse()
                        {
                            CreatedOn      = DateTime.Now.ToString(),
                            CronExpression = "",
                            DateCreated    = DateTime.Now,
                            EditedOn       = DateTime.Now.ToString(),
                            FilePath       = filePath,
                            Id             = id,
                            Name           = id,
                            Type           = "PYTHON",
                            Url            = "",
                            Recurrence     = "ONE_TIME",
                            StartDate      = "",
                            StartTimeH     = "",
                            StartTimeM     = "",
                            // ZMKResponse = tresp.ToList<object>(),
                            Status  = "",
                            History = jHist.ToList <object>()
                        };


                        SchedulerPayload.Create(schJob);
                    }


                    return(Json(jsonObj));
                }
                else
                {
                    return(BadRequest(new { message = "File execution failed." }));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = "File execution failed.", exception = ex.StackTrace }));
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> CreateScoringJobAsync(string id, [FromBody] TrainingRequestParam jsonbody)
        {
            string  filePath = "";
            var     json     = JsonConvert.SerializeObject(jsonbody);
            JObject jo       = JObject.Parse(json);

            /* TODO: validation for req body */
            JObject cronjson = JObject.Parse(jo.ToString());

            filePath = cronjson["filePath"].ToString();

            /*request json for zmk */
            JObject req = JObject.Parse(jo.ToString());

            req.Remove("recurrence");
            req.Remove("cronExpression");
            req.Remove("startDate");
            req.Remove("startTimeH");
            req.Remove("startTimeM");

            /* validate if model exists in the ZMOD directory and loaded. */
            if (ModelPayload.Get().Where(m => m.Id == id).Count() == 1)
            {
                List <TrainingResponse> tresp = new List <TrainingResponse>();

                #region schedule scoring

                /* check if same job is scheduled */
                ISchedulerFactory schfack   = new StdSchedulerFactory();
                IScheduler        scheduler = await schfack.GetScheduler();

                var jobKey = new JobKey(filePath);
                if (await scheduler.CheckExists(jobKey))
                {
                    await scheduler.ResumeJob(jobKey);
                }
                else
                {
                    try
                    {
                        #region create quartz job for training model
                        ITrigger trigger = TriggerBuilder.Create()
                                           .WithIdentity($"Training Model Job-{DateTime.Now}")
                                           .WithCronSchedule(cronjson["cronExpression"].ToString())
                                           .WithPriority(1)
                                           .Build();

                        IJobDetail job = JobBuilder.Create <TrainModelJob>()
                                         .WithIdentity(filePath)
                                         .Build();

                        job.JobDataMap["id"]       = id;
                        job.JobDataMap["filePath"] = filePath;
                        job.JobDataMap["reqBody"]  = req.ToString();
                        job.JobDataMap["baseurl"]  = Configuration["PyServiceLocation:srvurl"];

                        await _scheduler.ScheduleJob(job, trigger);

                        //add to scheduler payload
                        SchedulerResponse schJob = new SchedulerResponse()
                        {
                            CreatedOn      = DateTime.Now.ToString(),
                            CronExpression = cronjson["cronExpression"].ToString(),
                            DateCreated    = DateTime.Now,
                            EditedOn       = DateTime.Now.ToString(),
                            FilePath       = filePath,
                            Id             = id,
                            Name           = id,
                            Type           = "PMML",
                            Url            = "",
                            Recurrence     = cronjson["recurrence"].ToString(),
                            StartDate      = cronjson["startDate"].ToString(),
                            StartTimeH     = (cronjson["startTimeH"].ToString() == null) ? "" : cronjson["startTimeH"].ToString(),
                            StartTimeM     = (cronjson["startTimeM"].ToString() == null) ? "" : cronjson["startTimeM"].ToString(),
                            // ZMKResponse = tresp.ToList<object>()
                        };
                        SchedulerPayload.Create(schJob);
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                }
                #endregion

                return(Ok(new { modelId = id, modelState = "model valid", message = "training job scheduled successfully!" }));
            }
            else
            {
                return(BadRequest(new { modelId = id, modelState = "model not found", message = "model does not exists!" }));
            }
        }
Ejemplo n.º 10
0
        public ActionResult RSVP(long id, SchedulerResponse response)
        {
            // TODO -- do oodles of things here later, potentially with invites.

            return(RedirectToAction("Index", "EventFeed"));
        }