public void Add(JobProcess jobProcess) { if (string.IsNullOrWhiteSpace(jobProcess.TraceId)) { throw new ArgumentNullException(nameof(jobProcess.TraceId)); } if (string.IsNullOrWhiteSpace(jobProcess.JobId)) { throw new ArgumentNullException(nameof(jobProcess.JobId)); } if (jobProcess.Sharding <= 0) { throw new ArgumentException($"{nameof(jobProcess.Sharding)} should larger than 0"); } if (jobProcess.ProcessId <= 0) { throw new ArgumentException($"{nameof(jobProcess.ProcessId)} should larger than 0"); } if (string.IsNullOrWhiteSpace(jobProcess.Application)) { throw new ArgumentNullException(nameof(jobProcess.Application)); } var key = new ProcessKey(jobProcess.JobId, jobProcess.TraceId, jobProcess.Sharding); var path = Path.Combine(_folder, key.ToString()); File.WriteAllText(path, JsonConvert.SerializeObject(jobProcess)); }
private void btnSave_Click(object sender, RoutedEventArgs e) { try { if (Validation()) { SYS_JOB_SUBSCRIBE obj = new SYS_JOB_SUBSCRIBE(); List <SYS_JOB_SUBSCRIBE> lstDoiTuong = new List <SYS_JOB_SUBSCRIBE>(); GetFormData(ref obj); JobProcess process = new JobProcess(); bool ret = false; string sMessage = ""; ret = process.SysJobSubscribe(DatabaseConstant.Action.CAU_HINH, ref loaiDoiTuong, ref obj, ref lstDoiTuong, ref sMessage); if (ret) { LMessage.ShowMessage("Insert/Update successfull", LMessage.MessageBoxType.Warning); return; } else { LMessage.ShowMessage("Insert/Update failed", LMessage.MessageBoxType.Warning); return; } } } catch (System.Exception ex) { CommonFunction.ThongBaoLoi(ex); LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, ex); } }
//系统会每帧调用这个函数 protected override JobHandle OnUpdate(JobHandle inputDeps) { // ------- input handle ------ if (Input.GetMouseButtonDown(0)) { _isForceOn = true; } if (Input.GetMouseButtonUp(0)) { _isForceOn = false; } _mousePos = Camera.main.ScreenToWorldPoint(new float3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y)); _mousePos.y = 0; // ------- end input handle ------ //initial job var job = new JobProcess { isForceOn = _isForceOn, mousePosition = _mousePos, mouseMass = Mass }; //schedule job return(job.Schedule(this, inputDeps)); }
private void SetFormData() { try { SYS_JOB_SUBSCRIBE obj = new SYS_JOB_SUBSCRIBE(); List <SYS_JOB_SUBSCRIBE> lstDoiTuong = new List <SYS_JOB_SUBSCRIBE>(); obj.ID = id; JobProcess process = new JobProcess(); bool ret = false; string sMessage = ""; ret = process.SysJobSubscribe(DatabaseConstant.Action.LOAD, ref loaiDoiTuong, ref obj, ref lstDoiTuong, ref sMessage); if (obj != null) { txtName.Text = obj.SUB_NAME; txtDescription.Text = obj.DESCRIPTION; txtEmail.Text = obj.SUB_EMAIL; bool status = obj.SUB_STATUS.Equals("DEACTIVE") ? true : false; chkStatusDeactive.IsChecked = status; } } catch (Exception ex) { LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); throw ex; } }
//系统会每帧调用这个函数 protected override JobHandle OnUpdate(JobHandle inputDeps) { //初始化一个job var job = new JobProcess { }; //开始job return(job.Schedule(this, inputDeps)); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var random = new Random(1); var job = new JobProcess { random = random, }; return(job.Schedule(this, inputDeps)); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { //CommandBuff不支持burst,所以这里没有burst compiler EntityCommandBuffer.Concurrent entityCommandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); var job = new JobProcess { entityCommandBuffer = entityCommandBuffer }; return(job.Schedule(this, inputDeps)); }
/// <summary> /// Process jobs /// </summary> private async Task ProcessAsync(JobProcessingInstructionModel jobProcessInstruction, CancellationToken ct) { var currentProcessInstruction = jobProcessInstruction ?? throw new ArgumentNullException(nameof(jobProcessInstruction)); try { // Stop worker heartbeat to start the job heartbeat process _heartbeatTimer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); // Stop worker heartbeat _logger.Information("Worker {WorkerId} processing job {JobId}, mode: {ProcessMode}", WorkerId, currentProcessInstruction.Job.Id, currentProcessInstruction.ProcessMode); // Execute processor while (true) { ct.ThrowIfCancellationRequested(); if (_jobProcess == null) { _jobProcess = new JobProcess(this, currentProcessInstruction, _lifetimeScope, _logger); } else { _jobProcess.ProcessNewInstruction(currentProcessInstruction); } await _jobProcess.WaitAsync(ct).ConfigureAwait(false); // Does not throw // Check if the job is to be continued with new configuration settings if (_jobProcess?.JobContinuation?.Job?.JobConfiguration == null || _jobProcess?.JobContinuation?.ProcessMode == null) { await StopJobProcess().ConfigureAwait(false); break; } currentProcessInstruction = _jobProcess.JobContinuation; _logger.Information("Worker {WorkerId} processing job {JobId} continuation in mode {ProcessMode}", WorkerId, currentProcessInstruction.Job.Id, currentProcessInstruction.ProcessMode); } } catch (OperationCanceledException) { _logger.Information("Worker {WorkerId} cancellation received ...", WorkerId); await StopJobProcess().ConfigureAwait(false); } finally { _logger.Information("Worker: {WorkerId}, Job: {JobId} processing completed ... ", WorkerId, currentProcessInstruction.Job.Id); if (!ct.IsCancellationRequested) { _heartbeatTimer.Change(TimeSpan.Zero, Timeout.InfiniteTimeSpan); // restart worker heartbeat } } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { //Concurrent可以让ECB在job中使用。 EntityCommandBuffer.Concurrent entityCommandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); var job = new JobProcess { entityCommandBuffer = entityCommandBuffer }; return(job.Schedule(this, inputDeps)); }
//系统会每帧调用这个函数 protected override JobHandle OnUpdate(JobHandle inputDeps) { UIManager.Instance.ChangeHomeHPText((int)_Group.home[0].health); //初始化一个job var job = new JobProcess { group = _Group }; //开始job return(job.Schedule(this, inputDeps)); }
//系统会每帧调用这个函数 protected override JobHandle OnUpdate(JobHandle inputDeps) { //Cube计数 UIManager.Instance.ChangeCubeNumText(_GroupCube.Cubes.Length); //初始化一个job var job = new JobProcess { group = _Group, groupLaser = _GroupLaser }; //开始job return(job.Schedule(this, inputDeps)); }
/// <summary> /// Process jobs /// </summary> /// <returns></returns> private async Task ProcessAsync(JobProcessingInstructionModel jobProcessInstruction, CancellationToken ct) { try { // Stop worker heartbeat to start the job heartbeat process _heartbeatTimer.Change(-1, -1); // Stop worker heartbeat _logger.Information("Worker: {WorkerId} processing job: {JobId}, mode: {ProcessMode}", WorkerId, jobProcessInstruction.Job.Id, jobProcessInstruction.ProcessMode); // Execute processor while (true) { _jobProcess = null; ct.ThrowIfCancellationRequested(); using (_jobProcess = new JobProcess(this, jobProcessInstruction, _lifetimeScope, _logger)) { await _jobProcess.WaitAsync(ct).ConfigureAwait(false); // Does not throw } // Check if the job is to be continued with new configuration settings if (_jobProcess.JobContinuation == null) { _jobProcess = null; break; } jobProcessInstruction = _jobProcess.JobContinuation; if (jobProcessInstruction?.Job?.JobConfiguration == null || jobProcessInstruction?.ProcessMode == null) { _logger.Information("Job continuation invalid, continue listening..."); _jobProcess = null; break; } _logger.Information("Processing job continuation..."); } } catch (OperationCanceledException) { _logger.Information("Processing cancellation received ..."); _jobProcess = null; } finally { _logger.Information("Worker: {WorkerId}, Job: {JobId} processing completed ... ", WorkerId, jobProcessInstruction.Job.Id); if (!ct.IsCancellationRequested) { _heartbeatTimer.Change(0, -1); // restart worker heartbeat } } }
private void SetFormData() { try { SYS_JOB_EMAIL obj = new SYS_JOB_EMAIL(); obj.ID = 1; JobProcess process = new JobProcess(); bool ret = false; string sMessage = ""; ret = process.SysJobEmail(DatabaseConstant.Action.LAY_LAI, ref obj, ref sMessage); if (obj != null) { txtName.Text = obj.NAME; txtDescription.Text = obj.DESCRIPTION; txtHostAddress.Text = obj.MAIL_FROM; txtHostAddress.Text = obj.MAIL_HOST_ADDRESS; txtPort.Text = obj.MAIL_HOST_SMTP_PORT; txtUserName.Text = obj.MAIL_USERNAME; txtPassWord.Password = obj.MAIL_PASSWORD; string pro = obj.MAIL_HOST_PROTOCOL; if (!pro.IsNullOrEmpty()) { if (pro.Equals("SMTP")) { cboProtocol.SelectedIndex = 0; } if (pro.Equals("SMTPS")) { cboProtocol.SelectedIndex = 1; } else { cboProtocol.SelectedIndex = 0; } } else { cboProtocol.SelectedIndex = 0; } } } catch (Exception ex) { LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); throw ex; } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityCommandBuffer.Concurrent entityCommandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); //初始化一个job var job = new JobProcess { entityCommandBuffer = entityCommandBuffer, deltaTime = Time.deltaTime }; //开始job return(job.Schedule(this, inputDeps)); }
/// <summary> /// Process jobs /// </summary> /// <returns></returns> private async Task ProcessAsync(JobProcessingInstructionModel jobProcessInstruction, CancellationToken ct) { try { // Stop worker heartbeat to start the job heartbeat process _heartbeatTimer.Change(-1, -1); // Stop worker heartbeat _logger.Information("Starting to process new job..."); // Execute processor while (true) { _jobProcess = null; ct.ThrowIfCancellationRequested(); using (_jobProcess = new JobProcess(this, jobProcessInstruction, _lifetimeScope, _logger)) { await _jobProcess.WaitAsync(); // Does not throw } // Check if the job is to be continued with new configuration settings if (_jobProcess.JobContinuation == null) { _jobProcess = null; break; } jobProcessInstruction = _jobProcess.JobContinuation; if (jobProcessInstruction?.Job?.JobConfiguration == null || jobProcessInstruction?.ProcessMode == null) { _logger.Information("Job continuation invalid, continue listening..."); _jobProcess = null; break; } _logger.Information("Processing job continuation..."); } } finally { _logger.Information("Job processing completed..."); if (!ct.IsCancellationRequested) { _heartbeatTimer.Change(0, -1); // restart worker heartbeat } } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityCommandBuffer.Concurrent entityCommandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); //初始化一个job var job = new JobProcess { entityCommandBuffer = entityCommandBuffer, results = results }; if (results == 1) { UIManager.Instance.ChangeHomeHPText(-1); } //开始job return(job.Schedule(this, inputDeps)); }
internal static async Task CreateJobProcessAsync(JobRepositoryWorkerRequest @event) { var jobId = @event.JobId; var table = new DynamoDbTable(@event.Request.StageVariables["TableName"]); var job = await table.GetAsync <Job>(jobId); var resourceManager = @event.Request.GetAwsV4ResourceManager(); try { var jobProcess = new JobProcess { Job = jobId, NotificationEndpoint = new NotificationEndpoint { HttpEndpoint = jobId + "/notifications" } }; jobProcess = await resourceManager.CreateAsync(jobProcess); job.Status = "QUEUED"; job.JobProcess = jobProcess.Id; } catch (Exception error) { Logger.Error("Failed to create JobProcess."); Logger.Exception(error); job.Status = "FAILED"; job.StatusMessage = $"Failed to create JobProcess due to error '{error}'"; } job.DateModified = DateTime.UtcNow; await table.PutAsync <Job>(jobId, job); await resourceManager.SendNotificationAsync(job, job.NotificationEndpoint); }
public JobController(JobProcess job) { this._job = job; }
/// <summary> /// Executes work for the given input /// </summary> /// <param name="jobAssignment"></param> /// <returns></returns> async Task IWorker.Execute(JobAssignment jobAssignment) { JobProcess jobProcess = null; T job = null; try { // update status and modified date/time jobAssignment.JobProcessStatus = "Running"; jobAssignment.DateModified = DateTime.UtcNow; // persist the updated job assignment await DataHandler.Update(jobAssignment); // get the job process from the job assignment jobProcess = await DataHandler.Get <JobProcess>(jobAssignment.JobProcess); if (jobProcess == null) { throw new Exception("Failed to resolve jobAssignment.jobProcess"); } // get the job from the job process job = await DataHandler.Get <T>(jobProcess.Job.Id); if (job == null) { throw new Exception("Failed to resolve jobProcess.job"); } // load the job profile job.JobProfile = await DataHandler.Get <JobProfile>(job.JobProfile.Id); if (job.JobProfile == null) { throw new Exception("Failed to resolve job.jobProfile"); } // do the work await Execute(job); // update the job with output job.JobStatus = jobAssignment.JobProcessStatus = "Completed"; await DataHandler.Update(job); // mark the job completed and set its output jobAssignment.JobOutput = job.JobOutput; } catch (Exception exception) { // mark failed if an exception is encountered jobAssignment.JobProcessStatus = "Failed"; jobAssignment.JobProcessStatusReason = exception.ToString(); } // update the job assignment to current state after attempting to run the job await DataHandler.Update(jobAssignment); // update the job process from the job assignment if (jobProcess != null) { jobProcess.JobProcessStatus = jobAssignment.JobProcessStatus; jobProcess.JobProcessStatusReason = jobAssignment.JobProcessStatusReason; jobProcess.JobEnd = DateTime.UtcNow; await DataHandler.Update(jobProcess); } // hit the async callback endpoint if (job?.AsyncEndpoint != null) { switch (jobAssignment.JobProcessStatus) { case "Failed" when !string.IsNullOrWhiteSpace(job.AsyncEndpoint.AsyncFailure): await DataHandler.Get <Resource>(job.AsyncEndpoint.AsyncFailure); break; case "Completed" when !string.IsNullOrWhiteSpace(job.AsyncEndpoint.AsyncSuccess): await DataHandler.Get <Resource>(job.AsyncEndpoint.AsyncSuccess); break; } } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { ////鼠标检测 //if (Input.GetMouseButtonDown(0)) //{ // _isForceOn = true; // _forceMode = ForceComponent.ForceMode.PULL; //} //if (Input.GetMouseButtonUp(0)) //{ // _isForceOn = false; //} ////right - push //if (Input.GetMouseButtonDown(1)) //{ // _isForceOn = true; // _forceMode = ForceComponent.ForceMode.PUSH; //} //if (Input.GetMouseButtonUp(1)) //{ // _isForceOn = false; //} //触屏检测 if (Input.touchCount >= 1) { if (Input.touches[0].phase == TouchPhase.Stationary || Input.touches[0].phase == TouchPhase.Moved) { _isForceOn = true; _forceMode = ForceComponent.ForceMode.PULL; } if (Input.touches[0].phase == TouchPhase.Ended || Input.touches[0].phase == TouchPhase.Canceled) { _isForceOn = false; } //right - push if (Input.touches[0].phase == TouchPhase.Began) { _isForceOn = true; _forceMode = ForceComponent.ForceMode.PUSH; } if (Input.touches[0].phase == TouchPhase.Ended || Input.touches[0].phase == TouchPhase.Canceled) { _isForceOn = false; } } //mousePos = Camera.main.ScreenToWorldPoint(new float3(Input.touches[0].position.x, Input.touches[0].position.y, 248f/*Camera.main.transform.position.y*/)); //mousePos.z = 248.0f; mousePos = Camera.main.ScreenToWorldPoint(new float3(Input.mousePosition.x, Input.mousePosition.y, 248f /*Camera.main.transform.position.y*/)); mousePos.z = 248.0f; //初始化一个job var job = new JobProcess { isForceOn = _isForceOn, forceMode = _forceMode, mousePosition = mousePos }; //开始job return(job.Schedule(this, inputDeps)); }
//equivalent to Update method from MonoBehaviour. protected override JobHandle OnUpdate(JobHandle inputDeps) { while (_maxDistance == 0) { furthestMous = GetWorldPositionOnPlane( new Vector3(Camera.main.pixelWidth, Camera.main.pixelHeight, 0), 0); _maxDistance = math.length(furthestMous - Vector3.zero); Debug.Log(_maxDistance); } // ------- input handle ------ //left - pull if (Input.GetMouseButtonDown(0)) { _isForceOn = true; _forceMode = Forcefield.ForceMode.PULL; } if (Input.GetMouseButtonUp(0)) { _isForceOn = false; } //right - push if (Input.GetMouseButtonDown(1)) { _isForceOn = true; _forceMode = Forcefield.ForceMode.PUSH; } if (Input.GetMouseButtonUp(1)) { _isForceOn = false; } mousePos = GetWorldPositionOnPlane(Input.mousePosition, 0); mousePos.z = 0; // ------- end input handle ------ //start a job for entity. you will access the properties of entity from here. //JobProcess is a struct that will implement the IJobProcessComponentData interface //job receives parameters and operates on data, similar to how a method call behaves. //you can not have instance property or initializer inside a struct. You have to pass it from outside var job = new JobProcess { isForceOn = _isForceOn, forceMode = _forceMode, mousePosition = mousePos, deltaTime = Time.deltaTime, freePos = _freePos, isFreePosGot = _isFreePosGot, k = _k, fric = _fric, force = _force, mVelocity = _mVelocity, maxDistance = _maxDistance }; //start the job execution. This allows you to schedule a single job that runs //in parallel to other jobs and the main thread. return(job.Schedule(this, inputDeps)); }
//系统会每帧调用这个函数 protected override JobHandle OnUpdate(JobHandle inputDeps) { //#if UNITY_STANDALONE // ------- input handle ------ //left - pull if (Input.GetMouseButtonDown(0)) { _isForceOn = true; _forceMode = ForceComponent.ForceMode.PULL; } if (Input.GetMouseButtonUp(0)) { _isForceOn = false; } //right - push if (Input.GetMouseButtonDown(1)) { _isForceOn = true; _forceMode = ForceComponent.ForceMode.PUSH; } if (Input.GetMouseButtonUp(1)) { _isForceOn = false; } if (Input.GetKey(KeyCode.W)) { Camera.main.transform.SetPositionAndRotation(Camera.main.transform.position + Vector3.down * 5f, Camera.main.transform.rotation); } if (Input.GetKey(KeyCode.S)) { Camera.main.transform.SetPositionAndRotation(Camera.main.transform.position + Vector3.up * 5f, Camera.main.transform.rotation); } mousePos = Camera.main.ScreenToWorldPoint(new float3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y)); mousePos.y = 0; // ------- end input handle ------ //#endif #if UNITY_ANDROID if (Input.touchCount == 1) { if (Input.touches[0].phase == TouchPhase.Moved) { _isForceOn = true; mousePos = Camera.main.ScreenToWorldPoint(new float3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y, Camera.main.transform.position.y)); mousePos.y = 0; } } else { //_isForceOn = false; } #endif //初始化一个job var job = new JobProcess { isForceOn = _isForceOn, forceMode = _forceMode, mousePosition = mousePos }; //开始job return(job.Schedule(this, inputDeps)); }