Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does aspnetboilerplate track entity history in backgroundjobs and workers? #6493

Closed
Omital opened this issue Jul 23, 2022 · 8 comments
Closed
Assignees
Milestone

Comments

@Omital
Copy link

Omital commented Jul 23, 2022

It seems aspnetboilerplate does not track entity change history in BackgroundJobs and Workers. Is any option to enable or implement it?

@ismcagdas
Copy link
Member

Copuld you share a sample entity and a sample job to reproduce this ?

@Omital
Copy link
Author

Omital commented Aug 18, 2022

In this project https://github.com/Omital/ClientInfoProvider
after GenerateDataWorker execution no history is recorded in entity history

@ismcagdas
Copy link
Member

Does that work if you wrap data save operation in the background job with this https://aspnetboilerplate.com/Pages/Documents/Abp-Session#user-identifier

@Omital
Copy link
Author

Omital commented Aug 19, 2022

What if Multitenancy is disabled?

@ismcagdas
Copy link
Member

In that case, you can try with default tenant's admin user. It should be TenantId=1, UserId=2

@Omital
Copy link
Author

Omital commented Sep 3, 2022

I wrap my code with using (AbpSession.Use(1, 2)) in both backgroundJob and backgroundWorker, but entityHistory mechanism not work. You can see it in Omital/ClientInfoProvider@f069b88

@ismcagdas
Copy link
Member

Thanks, I will check it.

@ismcagdas ismcagdas added this to the v7.4 milestone Sep 5, 2022
@ismcagdas ismcagdas modified the milestones: v7.4, v8.0 Oct 14, 2022
@ismcagdas ismcagdas modified the milestones: v8.0, v8.1 Dec 8, 2022
@m-aliozkaya m-aliozkaya assigned ismcagdas and unassigned m-aliozkaya Jan 10, 2023
@ismcagdas
Copy link
Member

@Omital I figure out the problem, even if you use AbpSession.Use, the scope it creates is disposed before the unitOfWork is completed. So, you need to change;

[UnitOfWork(true)]
public override async Task ExecuteAsync(SampleJobArgs args)
{
	using (AbpSession.Use(1, 2))
	{
		BaseData bd = new BaseData()
		{
			Name = Clock.Now.Ticks.ToString()
		};
		await _baseDataRepo.InsertAsync(bd);
	}
}

to

[UnitOfWork(true)]
public override async Task ExecuteAsync(SampleJobArgs args)
{
	using (AbpSession.Use(1, 2))
	{
		BaseData bd = new BaseData()
		{
			Name = Clock.Now.Ticks.ToString()
		};
		await _baseDataRepo.InsertAsync(bd);
               CurrentUnitOfWork.SaveChanges();
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants