We are implementing a periodic background worker to send daily tasks reminders to users via email. Here, in the worker class we are looping the tasks every 1 hour, which is mentioned inside the constructor of the worker class. Right now since we have mentioned Timer.Period = 3600000; inside the constructor, the worker will be executed every 1 hour for all the tenants. But what we want is that we should be able to set different looping time for different tenants, the value for which would be fetched from the database table.
Currently we have
public class TasksReminderAlertNotificationWorker : AsyncPeriodicBackgroundWorkerBase
{
public TasksReminderAlertNotificationWorker(
AbpAsyncTimer timer,
IServiceScopeFactory serviceScopeFactory)
: base(timer, serviceScopeFactory)
{
Timer.Period = 3600000;
}
}
Here, as the value of Timer.Period is set as 3600000 milliseconds, the worker will be executed every 1 hour. What we want to achieve is that different tenants should be able to have different value for this Time.Period value (2 hours, 3 hours etc.)
How can we achieve this?
Also, since this worker will be executed every specific time period, it will unnecessarily be executed every hour because we want to run only 1 time in a day and we want to do it at a specific time of the day (for example 10 AM or 5 PM).
Is there a way to achieve that? Instead of looping the worker for the whole day and check for the current time and then based on the condition it will be executed, it should be executed at the exact mentioned time. Please elaborate.
Here's the current piece of code we have implemented.
public class TasksReminderAlertNotificationWorker : AsyncPeriodicBackgroundWorkerBase
{
private TimeSpan TargetTime;
protected IConfiguration Configuration;
public TasksReminderAlertNotificationWorker(
AbpAsyncTimer timer,
IServiceScopeFactory serviceScopeFactory,
IConfiguration configuration)
: base(timer, serviceScopeFactory)
{
Configuration = configuration;
Timer.Period = Configuration
.GetSection("TasksReminderAlertNotificationWorker")
.GetValue<int>("Default");
}
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
var now = DateTime.UtcNow;
var sharedRepository = workerContext.ServiceProvider
.GetRequiredService<ISharedRepository>();
var items = await sharedRepository.GetOrgTasksALertNotificationTeemplate();
foreach (var item in items)
{
double time = 0;
if (item.ExecutionTime.HasValue)
{
time = item.ExecutionTime.Value;
}
TimeSpan localTimeOfDay = TimeSpan.FromMilliseconds(time);
DateTime localDateTime = DateTime.Today.Add(localTimeOfDay);
DateTime utcDateTime = TimeZoneInfo.ConvertTimeToUtc(localDateTime);
TargetTime = utcDateTime.TimeOfDay;
if (now.TimeOfDay >= TargetTime && (item.LastRunOn == null || item.LastRunOn.Value.Date != now.Date))
{
var workersAppService = workerContext.ServiceProvider
.GetRequiredService<IWorkersAppService>();
if (item.TenantId.HasValue)
{
await workersAppService.SendTasksNotification(item.TenantId.Value, TargetTime);
await sharedRepository.UpdateLastRunOnDateTime(item.Id, now);
}
}
}
await Task.CompletedTask;
}
}
What are database changes introduced in each release? How do we track it if we want to have database first approach for my application?
Any update on this?
The issue is in the test process.
Any tentative date of release?
The new modules will continue being DDD layered.
Then why not provide a param in the add microservice command to use DDD layer solution or the new one which will be default while adding microservice?
Hi @smansuri
Sorry for our late reply. I think what @yekalkan means, you need to do this in new microservice template. If you follow this approach https://abp.io/support/questions/8755/ABP-studio-not-able-to-add-Wi new-micro-service-in-the-existing-solution#answer-3a180b89-76d4-b0ff-a534-dd45c2339225, you should be able to work on new microservice solution template.
Are you having this issue on new microservice template as well ?
with new micro service template i have seen the DDD layer is removed now. We already have a application developed using DDD domain and now you have remove the option to generate DDD layered from new template. So if we do not migrate to latest microservice template and if you introduce the new module like payments in future it will follow the new micro service template right? and what if we need to customize the features in the newly introduce module? how do we achieve this if we do not migrate to new template and only upgrade the abp version to latest version. And how am i supposed to maintain the source code of these modules in case in case if stop using the abp license?
Do we have any update on fixing the expo web issue?
Any update on this?
suite does not allow to load the whole microservice solution template as existing solution
You can add service by service. And then generate code on the services.
issue is it does not allow new service to be added.