public string Enqueue(Expression <Action> action) { var grainId = GetGrainId(); AddGrainState(grainId); var jobId = _client.Enqueue(action); var endId = _client.ContinueJobWith(jobId, () => AggregationGrainEnd(_aggregateJobId, _lockId, grainId, null)); return(endId); }
public override string Schedule(IBackgroundJobClient jobClient) { Guid changeInfoId = GetStateChangeRecord().Id; string jobId = jobClient.Schedule <StateTransition>( transition => transition.Execute(changeInfoId), GetIntendedRunAt() ); jobClient.ContinueJobWith <SynchronizeDelayedJobsJob>(jobId, job => job.Execute(Entity.Id)); jobClient.ContinueJobWith <StateTransition>(jobId, job => job.SendTransitionEmails(changeInfoId)); return(jobId); }
public ActionResult CreateContinuationJob() { var parentJobId = _backgroundJobClient.Enqueue(() => _jobTestService.FireAndForgetJob()); _backgroundJobClient.ContinueJobWith(parentJobId, () => _jobTestService.ContinuationJob()); return(Ok()); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IBackgroundJobClient backgroundJobClient, IRecurringJobManager recurringJobManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Hangfire v1")); } #region Configure Hangfire app.UseHangfireServer(); //Basic Authentication added to access the Hangfire Dashboard app.UseHangfireDashboard("/hangfire", new DashboardOptions() { AppPath = null, DashboardTitle = "Hangfire Dashboard", Authorization = new[] { new HangfireCustomBasicAuthenticationFilter { User = Configuration.GetSection("HangfireCredentials:UserName").Value, Pass = Configuration.GetSection("HangfireCredentials:Password").Value } }, //Authorization = new[] { new DashboardNoAuthorizationFilter() }, //IgnoreAntiforgeryToken = true });; #endregion app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); #region Job Scheduling Tasks // Recurring Job for every 5 min recurringJobManager.AddOrUpdate("Insert Employee : Runs Every 1 Min", () => jobscheduler.JobAsync(), "*/5 * * * *"); //Fire and forget job var jobId = backgroundJobClient.Enqueue(() => jobscheduler.JobAsync()); //Continous Job backgroundJobClient.ContinueJobWith(jobId, () => jobscheduler.JobAsync()); //Schedule Job / Delayed Job backgroundJobClient.Schedule(() => jobscheduler.JobAsync(), TimeSpan.FromDays(5)); #endregion }
public async Task Given_parent_job_is_queued_when_queueing_continuation_outside_of_correlation_context_should_use_same_correlation_id_as_parent() { const string correlationId = "my-id"; var expectedParentJob = new BackgroundTestExecutor { CorrelationId = correlationId, JobHasCompleted = true }; var expectedContinuationJob = new BackgroundTestExecutor { CorrelationId = correlationId, JobHasCompleted = true }; // Queue parent _correlationManager.Correlate(correlationId, () => { expectedParentJob.JobId = _client.Enqueue <BackgroundTestExecutor>( job => job.RunAsync(TimeoutInMillis, null) ); }); // Act // We queue on purpose outside of context, so we are able to test if the job inherits the correlation id from parent job. expectedContinuationJob.JobId = _client.ContinueJobWith <BackgroundTestExecutor>( expectedParentJob.JobId, job => job.RunAsync(TimeoutInMillis, null) ); await WaitUntilJobCompletedAsync(expectedContinuationJob.JobId); // Assert ExecutedJobs.Should().BeEquivalentTo( new List <object> { expectedParentJob, expectedContinuationJob }, "the continuation job should have the same correlation id" ); }
public IActionResult UploadBinaryAsync(UploadBinaryUserTemplateViewModel model) { using (var memoryStream = new MemoryStream()) { model.Template.CopyTo(memoryStream); var binaries = memoryStream.ToArray(); var jobId = _backgroundJobClient.Enqueue((IUserService userService) => userService.ImportUserAsync(binaries)); _backgroundJobClient.ContinueJobWith(jobId, () => Console.WriteLine("Job done")); } return(Ok()); }
public ActionResult <string> DarknetS3(string bucketName, string weightsFile, int[] gpus, bool clear) { var hubId = Guid.NewGuid(); var outputDirectory = Path.Combine(Path.GetTempPath(), hubId.ToString()); var weightsFileJob = _backgroundJobs.Enqueue <AmazonS3DownloadJob>(job => job.File(bucketName, weightsFile, outputDirectory) ); var configFileJob = _backgroundJobs.ContinueJobWith <AmazonS3DownloadJob>(weightsFileJob, job => job.File(bucketName, "config.cfg", outputDirectory) ); var trainingImagesPath = "images/train"; var trainingImagesJob = _backgroundJobs.ContinueJobWith <AmazonS3DownloadJob>(configFileJob, job => job.Directory(bucketName, trainingImagesPath, outputDirectory, null, null) ); var trainingLabelsPath = "labels/train"; var trainingLabelsJob = _backgroundJobs.ContinueJobWith <AmazonS3DownloadJob>(trainingImagesJob, job => job.Directory(bucketName, trainingLabelsPath, outputDirectory, null, null) ); var trainimages = Path.Combine(outputDirectory, "train.txt"); var imageListJobId = _backgroundJobs.ContinueJobWith <GenerateImageListJob>(trainingLabelsJob, job => job.Start(Path.Join(outputDirectory, "images", "train"), Path.Join(outputDirectory, "labels", "train"), trainimages, null, null) ); var jobId = _backgroundJobs.ContinueJobWith <DarknetTrainJob>(imageListJobId, job => job.Start(trainimages, Path.Combine(outputDirectory, "config.cfg"), Path.Combine(outputDirectory, weightsFile), gpus, clear, null, null)); return(new JsonResult(new { jobId })); }
private void ScheduleJob(IDelayedJobDescriptor descriptor, IBackgroundJobClient jobClient) { string jobId = descriptor.Schedule(jobClient); ScheduledJobInfo jobInfo = new ScheduledJobInfo() { JobId = jobId, RunAt = descriptor.GetIntendedRunAt() }; descriptor.GetJobInfoReference().Value = jobInfo; _db.ScheduledJobInfos.Add(jobInfo); jobClient.ContinueJobWith <ScheduledJobCleaner>(jobId, cleaner => cleaner.Cleanup(jobInfo.Id)); }
public async Task SyncAsync(string curUserId, string projectId, bool trainEngine) { string sourceProjectId = null; using (IConnection conn = await _realtimeService.ConnectAsync(curUserId)) { IDocument <SFProject> projectDoc = await conn.FetchAsync <SFProject>(projectId); if (projectDoc.Data.SyncDisabled) { throw new ForbiddenException(); } sourceProjectId = projectDoc.Data.TranslateConfig.Source?.ProjectRef; await projectDoc.SubmitJson0OpAsync(op => op.Inc(pd => pd.Sync.QueuedCount)); // See if we can sync the source project if (!string.IsNullOrWhiteSpace(sourceProjectId)) { IDocument <SFProject> sourceProjectDoc = await conn.FetchAsync <SFProject>(sourceProjectId); if (!sourceProjectDoc.IsLoaded || sourceProjectDoc.Data.SyncDisabled) { sourceProjectId = null; } else { await sourceProjectDoc.SubmitJson0OpAsync(op => op.Inc(pd => pd.Sync.QueuedCount)); } } } if (!string.IsNullOrWhiteSpace(sourceProjectId)) { // We need to sync the source first so that we can link the source texts and train the engine string parentId = _backgroundJobClient.Enqueue <ParatextSyncRunner>( r => r.RunAsync(sourceProjectId, curUserId, false)); _backgroundJobClient.ContinueJobWith <ParatextSyncRunner>(parentId, r => r.RunAsync(projectId, curUserId, trainEngine)); } else { _backgroundJobClient.Enqueue <ParatextSyncRunner>(r => r.RunAsync(projectId, curUserId, trainEngine)); } }
public async Task <ActionResult> Post([FromBody] People model) { _demoContext.People.Add(model); await _demoContext.SaveChangesAsync(); try { _backgroundJobClient.Enqueue(() => AddNewPersonLog(model.Id)); var idSendEmail = _backgroundJobClient.Schedule(() => SendEmail(model), DateTimeOffset.Now.AddSeconds(15)); _backgroundJobClient.ContinueJobWith(idSendEmail, () => EmailSentLog(model.Id, model.Email)); } catch (Exception ex) { } return(Ok()); }
public async Task <Guid> ProcessBatch(BatchSubmitModel model) { var id = Guid.NewGuid(); var batch = new Batch { Id = id, BatchUri = $"HealthcareClaimsV1/{id}.json", CreationDate = DateTime.UtcNow }; _batchesContext.Batches.Add(batch); using (var stream = model.BatchJsonFile.OpenReadStream()) { await _objectsStorageService.UploadObjectAsync( "healthcare-claims-app-v1", batch.BatchUri, stream); } await _batchesContext.SaveChangesAsync(); var batchJobData = new BatchJobData { BatchId = batch.Id }; var submissionJobId = _backgroundJobClient .Enqueue <GenerateBatchSubmissionFeedbackDocumentJob>( job => job.Execute(batchJobData, null, JobCancellationToken.Null)); _backgroundJobClient .ContinueJobWith <VetBatchJob>( submissionJobId, job => job.Execute(batchJobData, null, JobCancellationToken.Null)); _logger.LogInformation("Batch submission initiated: {Id}", batch.Id); return(batch.Id); }
public string AddContinuations(Expression <Action> methodCall, string jobid) { return(_backgroundClient.ContinueJobWith(jobid, methodCall)); }
public string ContinueJobWith(string parentId, Expression <Action> methodCall, BackgroundJobContinuationOptions options = BackgroundJobContinuationOptions.OnlyOnSucceededState) => _client.ContinueJobWith(parentId, methodCall, (JobContinuationOptions)options);
public string Enqueue <T>(Expression <Func <T, Task> > methodCall) { return(string.IsNullOrWhiteSpace(_parentId) ? _backgroundJobClient.Create(methodCall, _queue) : _backgroundJobClient.ContinueJobWith(_parentId, methodCall, _queue)); }
public string ContinueWith <T>(string parentId, Expression <Func <T, Task> > methodCall) => _backgroundJobClient.ContinueJobWith(parentId, methodCall);