public void Execute(PersistBrokerPluginContext context)
        {
            if (context.EntityName != "robot_message_task")
            {
                return;
            }

            var obj = context.Entity as robot_message_task;

            switch (context.Action)
            {
            case EntityAction.PostCreate:
            case EntityAction.PostUpdate:
                JobHelpers.RegisterJob(new RobotMessageTaskJob(obj.name, obj.robotidName, obj.runtime), obj, obj.job_state.ToTriggerState());
                break;

            case EntityAction.PreCreate:
                var jobState = new RobotMessageTaskJob().DefaultTriggerState.ToSelectOption();
                obj.job_state     = jobState.Value.ToString();
                obj.job_stateName = jobState.Name;
                break;

            case EntityAction.PreUpdate:
            case EntityAction.PostDelete:
                JobHelpers.DeleteJob(obj.name, obj.robotidName);
                break;

            default:
                break;
            }
        }
Esempio n. 2
0
        public virtual void Configure()
        {
            var logger = LogFactory.GetLogger("startup");

            logger.Info("正在启动机器人作业...");
            try
            {
                new RobotMessageTaskService().GetAllData().Each(item =>
                {
                    JobHelpers.RegisterJob(new RobotMessageTaskJob(item.name, item.robotidName, item.runtime), item, item.job_state.ToTriggerState());
                    logger.Info($"机器人[{item.robotidName}]的[{item.name}]作业已启动");
                });
                logger.Info("机器人启动完毕");
            }
            catch (Exception e)
            {
                logger.Error("注册机器人失败", e);
                throw e;
            }
        }