Skip to content

Commit

Permalink
Merge pull request #26 from VirtoCommerce/feat/VCPS-import-run-service
Browse files Browse the repository at this point in the history
feat: Make the service methods virtual
  • Loading branch information
tatarincev authored Jun 27, 2024
2 parents 9a994ad + c6297ec commit 5377a4b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@ namespace VirtoCommerce.ImportModule.Data.BackgroundJobs
{
public class BackgroundJobExecutor : IBackgroundJobExecutor
{
public string Enqueue(Expression<Func<Task>> expression)
public virtual string Enqueue(Expression<Func<Task>> expression)
{
return BackgroundJob.Enqueue(expression);
}

public string Enqueue<T>(Expression<Func<T, Task>> expression)
public virtual string Enqueue(string queue, Expression<Func<Task>> expression)
{
return BackgroundJob.Enqueue(queue, expression);
}

public virtual string Enqueue<T>(Expression<Func<T, Task>> expression)
{
return BackgroundJob.Enqueue(expression);
}

public virtual string Enqueue<T>(string queue, Expression<Func<T, Task>> expression)
{
return BackgroundJob.Enqueue(queue, expression);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace VirtoCommerce.ImportModule.Data.BackgroundJobs
public interface IBackgroundJobExecutor
{
string Enqueue(Expression<Func<Task>> expression);
string Enqueue(string queue, Expression<Func<Task>> expression);
string Enqueue<T>(Expression<Func<T, Task>> expression);
string Enqueue<T>(string queue, Expression<Func<T, Task>> expression);
}
}
16 changes: 8 additions & 8 deletions src/VirtoCommerce.ImportModule.Data/Services/ImportRunService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ IDataImportProcessManager dataImportManager
_dataImportManager = dataImportManager;
}

public ImportPushNotification RunImportBackgroundJob(ImportProfile importProfile)
public virtual ImportPushNotification RunImportBackgroundJob(ImportProfile importProfile)
{
var pushNotification = new ImportPushNotification(_userNameResolver.GetCurrentUserName())
{
Expand All @@ -75,7 +75,7 @@ public ImportPushNotification RunImportBackgroundJob(ImportProfile importProfile
return RunImportBackgroundJob(importProfile, pushNotification);
}

public ImportPushNotification RunImportBackgroundJob(ImportProfile importProfile, ImportPushNotification pushNotification)
public virtual ImportPushNotification RunImportBackgroundJob(ImportProfile importProfile, ImportPushNotification pushNotification)
{
var jobId = _backgroundJobExecutor.Enqueue<ImportJob>(x => x.ImportBackgroundAsync(importProfile, pushNotification, JobCancellationToken.Null, null));

Expand All @@ -84,23 +84,23 @@ public ImportPushNotification RunImportBackgroundJob(ImportProfile importProfile
return pushNotification;
}

public void CancelRunBackgroundJob(ImportCancellationRequest cancellationRequest)
public virtual void CancelRunBackgroundJob(ImportCancellationRequest cancellationRequest)
{
BackgroundJob.Delete(cancellationRequest.JobId);
}

public async Task<ImportPushNotification> RunImportAsync(ImportProfile importProfile, CancellationToken cancellationToken)
public virtual Task<ImportPushNotification> RunImportAsync(ImportProfile importProfile, CancellationToken cancellationToken)
{
var pushNotification = new ImportPushNotification(_userNameResolver.GetCurrentUserName())
{
ProfileId = importProfile.Id,
ProfileName = importProfile.Name,
};

return await RunImportAsync(importProfile, pushNotification, cancellationToken);
return RunImportAsync(importProfile, pushNotification, cancellationToken);
}

public async Task<ImportPushNotification> RunImportAsync(ImportProfile importProfile, ImportPushNotification pushNotification, CancellationToken cancellationToken)
public virtual async Task<ImportPushNotification> RunImportAsync(ImportProfile importProfile, ImportPushNotification pushNotification, CancellationToken cancellationToken)
{
var importRunHistory = ExType<ImportRunHistory>.New().CreateNew(importProfile, pushNotification);

Expand Down Expand Up @@ -178,7 +178,7 @@ async Task ProgressInfoCallback(ImportProgressInfo progressInfo)
return pushNotification;
}

public async Task<ImportDataPreview> PreviewAsync(ImportProfile importProfile)
public virtual async Task<ImportDataPreview> PreviewAsync(ImportProfile importProfile)
{
var importer = _dataImporterFactory.Create(importProfile.DataImporterType);
importProfile.ImportFileUrl = Uri.UnescapeDataString(importProfile.ImportFileUrl);
Expand Down Expand Up @@ -212,7 +212,7 @@ public async Task<ImportDataPreview> PreviewAsync(ImportProfile importProfile)
return result;
}

public async Task<ValidationResult> ValidateAsync(ImportProfile importProfile)
public virtual async Task<ValidationResult> ValidateAsync(ImportProfile importProfile)
{
var importer = _dataImporterFactory.Create(importProfile.DataImporterType);
importProfile.ImportFileUrl = Uri.UnescapeDataString(importProfile.ImportFileUrl);
Expand Down

0 comments on commit 5377a4b

Please sign in to comment.