Esempio n. 1
0
        private void HandleMsg(IMQConsumer consumer, string message, ulong deliveryTag)
        {
            var context = new HpScheduleContext(mFactory);

            try
            {
                var entity = JsonConvert.DeserializeObject <DeliveredModel>(message);

                context.taskid     = entity.task_id;
                context.param      = entity.param;
                context.routingkey = this.dispatcher_center_callback;
                context.rabbimqUrl = this.rabbitmq_url;

                if (!context.Log("开始执行任务", 0))
                {
                    //应答,并使该消息重新从队列获取
                    consumer.NAck(deliveryTag);
                    return;
                }

                //应答
                consumer.Ack(deliveryTag);

                try
                {
                    //执行任务
                    Execute(context);
                }
                catch (Exception e)
                {
                    Loging.LogError <HpScheduleJob>("执行任务失败", e);
                    context.Log(e.ToString(), -1);
                }
            }
            catch (System.Exception e)
            {
                Loging.LogInformation <HpScheduleJob>(e.ToString());
                context.Log(e.ToString(), -1);
            }
        }
Esempio n. 2
0
 public abstract void Execute(HpScheduleContext context);