Exemple #1
0
        public override Task <RpcResult <TaskVoidRes> > ScheduleSecondTransforAsync(ScheduleTaskReq req)
        {
            RpcResult <TaskVoidRes> res = new RpcResult <TaskVoidRes>();

            _jobClient.Schedule <IHangfireJobService>(x => x.Schedule(0, 1, req.Delay, $"{req.ServiceId}|{req.MessageId}|{req.Data}", null), TimeSpan.FromSeconds(req.Delay));
            return(Task.FromResult(res));
        }
Exemple #2
0
        //同步方法
        public RpcResult <TaskVoidRes> Schedule(ScheduleTaskReq req)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(2001, 102);

            message.FriendlyServiceName = "TaskProducerService.Schedule";


            message.Data = req.ToByteArray();
            var response = base.CallInvoker.BlockingCall(message);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            var result = new RpcResult <TaskVoidRes>();

            if (response.Code != 0)
            {
                result.Code = response.Code;
            }

            if (response.Data == null)
            {
                result.Data = new TaskVoidRes();
            }
            else
            {
                result.Data = TaskVoidRes.Parser.ParseFrom(response.Data);
            }

            return(result);
        }
Exemple #3
0
        public async Task <RpcResult <TaskVoidRes> > ScheduleSecondTransforAsync(ScheduleTaskReq req, int timeOut = 3000)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(2001, 106);

            message.FriendlyServiceName = "TaskProducerService.ScheduleSecondTransfor";
            message.Data = req.ToByteArray();
            var response = await base.CallInvoker.AsyncCall(message, timeOut);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            var result = new RpcResult <TaskVoidRes>();

            if (response.Code != 0)
            {
                result.Code = response.Code;
            }

            if (response.Data == null)
            {
                result.Data = new TaskVoidRes();
            }
            else
            {
                result.Data = TaskVoidRes.Parser.ParseFrom(response.Data);
            }

            return(result);
        }
        //调用委托
        private async Task <AmpMessage> ProcessScheduleAsync(AmpMessage req)
        {
            ScheduleTaskReq request = null;

            if (req.Data == null)
            {
                request = new ScheduleTaskReq();
            }
            else
            {
                request = ScheduleTaskReq.Parser.ParseFrom(req.Data);
            }

            req.FriendlyServiceName = "TaskProducerService.Schedule";

            var result = await ScheduleAsync(request);

            var response = AmpMessage.CreateResponseMessage(req.ServiceId, req.MessageId);

            response.FriendlyServiceName = "TaskProducerService.Schedule";
            response.Code = result.Code;
            if (result.Data != null)
            {
                response.Data = result.Data.ToByteArray();
            }
            return(response);
        }
Exemple #5
0
 /// <summary>
 /// 秒级的延迟任务
 /// </summary>
 /// <param name="req"></param>
 /// <returns></returns>
 public override Task <RpcResult <TaskVoidRes> > ScheduleSecondAsync(ScheduleTaskReq req)
 {
     return(ScheduleSecondTransforAsync(req));
 }
Exemple #6
0
 /// <summary>
 /// 分钟级
 /// </summary>
 /// <param name="req"></param>
 /// <returns></returns>
 public override Task <RpcResult <TaskVoidRes> > ScheduleAsync(ScheduleTaskReq req)
 {
     return(ScheduleAsync(req));
 }
 //抽象方法
 public abstract Task <RpcResult <TaskVoidRes> > ScheduleSecondTransforAsync(ScheduleTaskReq req);
 //抽象方法
 public abstract Task <RpcResult <TaskVoidRes> > ScheduleAsync(ScheduleTaskReq req);