/// <summary> /// <para> /// POST api/createjob. Accepts a JSON Job Model object, which, if valid, is stored. /// The job is stored in memory in the ProcessManager, and cached to the hard drive. /// </para> /// <para> /// Jobs created this way are queued for execution - their progress and results can /// be checked using the otehr api methods. /// </para> /// <para> /// The Job's ID must not already be in use on the server. /// </para> /// </summary> /// <param name="value">JSON representing job</param> /// <returns>JSON Response indicating success</returns> public GenericResponse Post([FromBody] Job value) { // Check our input if (value == null) { return(GenericResponse.Failure("Invalid or missing job definition")); } // Check for existing job if (!ProcessManager.JobCached(value.JobId)) { Debug.WriteLine("Caching new Job"); ProcessManager.AddJob(value); Debug.WriteLine("Job stored"); // Queue the job Action a = delegate { JobQueue.AddToQueue(value.Command, value.JobId); }; //Change to actual name a(); return(GenericResponse.Success(value.JobId)); } else { return(GenericResponse.Failure("Job already cached")); } }
public async Task <ActionResult> AddAccounts(AddAccounts accounts) { var response = new GenericResponse <List <DiscoveryPatchResponse> >(); try { var addedAccounts = _transactionService.AddAccounts(accounts.AccountsIds); if (addedAccounts.IsSuccess) { var discoveryResult = await _transactionService.DiscoverPayments(addedAccounts.Data); if (discoveryResult.IsSuccess) { var responseData = new List <DiscoveryPatchResponse>(); discoveryResult.Data.ForEach(d => { responseData.Add(new DiscoveryPatchResponse() { AccountId = d.Account.PublicKey, IsSuccess = d.Status == PatchStatus.Success, PulledRecordsCount = d.PulledRecordsCount }); }); response.Success(responseData); } else { response.Failed("Failed to discover payments"); } } else { response.Failed("Failed to Add Account to Database Please check Logs"); } } catch (Exception ex) { response.Failed("Failed to Add Account to Database or discover paymets Please check Logs"); } return(Ok(response)); }
/// <summary> /// <para>POST api/job</para> /// <para></para> /// </summary> /// <param name="value">JobControl model object input</param> /// <returns>JSON GenericResponse indicating success or failure</returns> public GenericResponse Post([FromBody] JobControl value) { if (value == null) { return(GenericResponse.Failure("Invalid request")); } int id = value.JobId; string option = value.Option; StoredJob job = ProcessManager.GetJob(id); if (job == null) { return(GenericResponse.Failure("Job not stored")); } if (job.Completed) { return(GenericResponse.Failure("Job already completed")); } if (!job.Started) { return(GenericResponse.Failure("Job not started")); } if (option == "PAUSE") { Action c = delegate { job.Paused = true; }; //Pause the job here, if already paused do nothing c(); return(GenericResponse.Success(value.JobId)); } else if (option == "RESUME") { Action d = delegate { job.Paused = false; }; d(); return(GenericResponse.Success()); } else if (option == "STOP") { Action e = delegate { job.Stopped = true; if (job.exeProcess != null && !job.exeProcess.HasExited) { job.exeProcess.Kill(); } }; e(); return(GenericResponse.Success()); } else if (option == "RESTART") { Action f = delegate { job.Stopped = false; job.Paused = false; JobQueue.AddToQueue(job.Command, job.JobId); }; f(); return(GenericResponse.Success()); } else { return(GenericResponse.Failure("Option does not exist")); } }