public void logTest() { for (int i = 0; i < 10; i++) { XxlJobFileAppender.contextHolder.Value = XxlJobFileAppender.makeLogFileName(System.DateTime.Now, 1); XxlJobLogger.log($"{i}|aaaaaaaaaaaaaaaa"); } }
public void logTest1() { XxlJobFileAppender.contextHolder.Value = XxlJobFileAppender.makeLogFileName(System.DateTime.Now, 1); var result = XxlJobFileAppender.readLog(XxlJobFileAppender.contextHolder.Value, 1); Console.WriteLine(result.logContent); }
public ReturnT <LogResult> log(long logDateTim, int logId, int fromLineNum) { // log filename: yyyy-MM-dd/9999.log //todo:这里时间戳转换应该会问题 String logFileName = XxlJobFileAppender.makeLogFileName(TimeUtil.ToTime(logDateTim), logId); LogResult logResult = XxlJobFileAppender.readLog(logFileName, fromLineNum); return(new ReturnT <LogResult>(logResult)); }
void innerStart() { while (!toStop1) { running = false; idleTimes++; try { // to check toStop signal, we need cycle, so wo cannot use queue.take(), instand of poll(timeout) var result = triggerQueue.TryTake(out TriggerParam triggerParam, 3 * 1000); if (triggerParam != null) { running = true; idleTimes = 0; triggerLogIdSet.Remove(triggerParam.logId); // parse param string[] handlerParams = (triggerParam.executorParams != null && triggerParam.executorParams.Trim().Length > 0) ? triggerParam.executorParams.Split(',') : null; // handle job ReturnT <String> executeResult = null; try { // log filename: yyyy-MM-dd/9999.log String logFileName = XxlJobFileAppender.makeLogFileName(TimeUtil.ToTime(triggerParam.logDateTim), triggerParam.logId); XxlJobFileAppender.contextHolder.Value = (logFileName); ShardingUtil.setShardingVo(new ShardingUtil.ShardingVO(triggerParam.broadcastIndex, triggerParam.broadcastTotal)); XxlJobLogger.log("<br>----------- xxl-job job execute start -----------<br>----------- Params:" + string.Join(",", handlerParams ?? new[] { "" })); executeResult = handler.execute(handlerParams); if (executeResult == null) { executeResult = ReturnT <string> .FAIL; } XxlJobLogger.log("<br>----------- xxl-job job execute end(finish) -----------<br>----------- ReturnT:" + executeResult); } catch (Exception e) { if (toStop1) { XxlJobLogger.log("<br>----------- JobThread toStop, stopReason:" + stopReason); } //StringWriter stringWriter = new StringWriter(); //e.printStackTrace(new PrintWriter(stringWriter)); String errorMsg = e.ToString(); executeResult = new ReturnT <String>(ReturnT <string> .FAIL_CODE, errorMsg); XxlJobLogger.log("<br>----------- JobThread Exception:" + errorMsg + "<br>----------- xxl-job job execute end(error) -----------"); } // callback handler info if (!toStop1) { // commonm TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.logId, executeResult)); } else { // is killed ReturnT <String> stopResult = new ReturnT <String>(ReturnT <string> .FAIL_CODE, stopReason + " [业务运行中,被强制终止]"); TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.logId, stopResult)); } } else { if (idleTimes > 30) { XxlJobExecutor.removeJobThread(jobId, "excutor idel times over limit."); } } } catch (Exception e) { if (toStop1) { XxlJobLogger.log("<br>----------- xxl-job toStop, stopReason:" + stopReason); } String errorMsg = e.ToString(); XxlJobLogger.log("----------- xxl-job JobThread Exception:" + errorMsg); } } // callback trigger request in queue while (triggerQueue != null && triggerQueue.Count > 0) { triggerQueue.TryTake(out TriggerParam triggerParam); if (triggerParam != null) { // is killed ReturnT <String> stopResult = new ReturnT <String>(ReturnT <string> .FAIL_CODE, stopReason + " [任务尚未执行,在调度队列中被终止]"); TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.logId, stopResult)); } } logger.Info(string.Format(">>>>>>>>>>>> xxl-job JobThread stoped, hashCode:{0}", Thread.CurrentThread)); }
public void TestMethod1() { //JsonUtil.Registry(); Console.WriteLine(XxlJobFileAppender.makeLogFileName(System.DateTime.Now, 1)); }