Skip to content

Commit

Permalink
VCST-918: Add scheduling (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-dudarev authored Apr 25, 2024
1 parent 5f03bb7 commit c6bec87
Show file tree
Hide file tree
Showing 37 changed files with 1,354 additions and 145 deletions.
1 change: 1 addition & 0 deletions module.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ GraphQL.Server.Core.dll
GraphQL.Server.Transports.AspNetCore.dll
GraphQL.Server.Transports.AspNetCore.NewtonsoftJson.dll
GraphQL.Server.Transports.Subscriptions.Abstractions.dll
GraphQL.Server.Transports.Subscriptions.WebSockets.dll
GraphQL.SystemReactive.dll
GraphQL-Parser.dll
MediatR.dll
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Threading.Tasks;

namespace VirtoCommerce.PushMessages.Core.BackgroundJobs;

public interface IPushMessageJobService
{
Task StartStopRecurringJobs();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Events;
using VirtoCommerce.PushMessages.Core.Models;

namespace VirtoCommerce.PushMessages.Core.Extensions;

public static class PushMessageExtensions
{
public static bool IsSent(this GenericChangedEntry<PushMessage> entry)
{
return entry.NewEntry.Status == PushMessageStatus.Sent &&
(entry.EntryState == EntryState.Added ||
entry.EntryState == EntryState.Modified && entry.OldEntry.Status != PushMessageStatus.Sent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Threading.Tasks;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.GenericCrud;

namespace VirtoCommerce.PushMessages.Core.Extensions
{
public static class SearchServiceExtensions
{
public static async Task SearchWhileResultIsNotEmpty<TCriteria, TResult, TModel>(this ISearchService<TCriteria, TResult, TModel> searchService, TCriteria searchCriteria, Func<TResult, Task> action)
where TCriteria : SearchCriteriaBase
where TResult : GenericSearchResult<TModel>
where TModel : IEntity
{
TResult searchResult;

do
{
searchResult = await searchService.SearchAsync(searchCriteria);

if (searchResult.Results.Count > 0)
{
await action(searchResult);
}
}
while (searchCriteria.Take > 0 &&
searchResult.Results.Count == searchCriteria.Take &&
searchResult.Results.Count != searchResult.TotalCount);
}
}
}
6 changes: 6 additions & 0 deletions src/VirtoCommerce.PushMessages.Core/Models/PushMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ namespace VirtoCommerce.PushMessages.Core.Models;

public class PushMessage : AuditableEntity, ICloneable
{
public string Topic { get; set; }

public string ShortMessage { get; set; }

public DateTime? StartDate { get; set; }

public string Status { get; set; }

public IList<string> MemberIds { get; set; }

[JsonIgnore]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System;
using System.Collections.Generic;
using VirtoCommerce.Platform.Core.Common;

namespace VirtoCommerce.PushMessages.Core.Models;

public class PushMessageSearchCriteria : SearchCriteriaBase
{
public DateTime? StartDateBefore { get; set; }
public IList<string> Statuses { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VirtoCommerce.PushMessages.Core.Models;

public static class PushMessageStatus
{
public const string Scheduled = "Scheduled";
public const string Sent = "Sent";
}
50 changes: 35 additions & 15 deletions src/VirtoCommerce.PushMessages.Core/ModuleConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using VirtoCommerce.Platform.Core.Settings;

namespace VirtoCommerce.PushMessages.Core;
Expand All @@ -16,42 +17,61 @@ public static class Permissions
public const string Delete = "PushMessages:delete";

public static string[] AllPermissions { get; } =
{
[
Access,
Create,
Read,
Update,
Delete,
};
];
}
}

public static class Settings
{
public static class General
{
public static SettingDescriptor PushMessagesEnabled { get; } = new()
public static SettingDescriptor BatchSize { get; } = new()
{
Name = "PushMessages.BatchSize",
GroupName = "Push Messages|General",
ValueType = SettingValueType.Integer,
DefaultValue = 50,
};

public static IEnumerable<SettingDescriptor> AllGeneralSettings
{
Name = "PushMessages.PushMessagesEnabled",
GroupName = "PushMessages|General",
get
{
yield return BatchSize;
}
}
}

public static class BackgroundJobs
{
public static SettingDescriptor Enable { get; } = new()
{
Name = "PushMessages.BackgroundJobs.Enable",
GroupName = "Push Messages|Background Jobs",
ValueType = SettingValueType.Boolean,
DefaultValue = false,
DefaultValue = true,
};

public static SettingDescriptor PushMessagesPassword { get; } = new()
public static SettingDescriptor CronExpression { get; } = new()
{
Name = "PushMessages.PushMessagesPassword",
GroupName = "PushMessages|Advanced",
ValueType = SettingValueType.SecureString,
DefaultValue = "qwerty",
Name = "PushMessages.BackgroundJobs.CronExpression",
GroupName = "Push Messages|Background Jobs",
ValueType = SettingValueType.ShortText,
DefaultValue = "0/5 * * * *",
};

public static IEnumerable<SettingDescriptor> AllGeneralSettings
public static IEnumerable<SettingDescriptor> AllBackgroundJobsSettings
{
get
{
yield return PushMessagesEnabled;
yield return PushMessagesPassword;
yield return Enable;
yield return CronExpression;
}
}
}
Expand All @@ -60,7 +80,7 @@ public static IEnumerable<SettingDescriptor> AllSettings
{
get
{
return General.AllGeneralSettings;
return General.AllGeneralSettings.Concat(BackgroundJobs.AllBackgroundJobsSettings);
}
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c6bec87

Please sign in to comment.