Service Fabric Actor custom actor service SaveReminderAsync usage

86 Views Asked by At

I have a custom actor service, and I want to be able to add reminders to my actors from here, and not to have to call the actor directly for this. I do not want to wait to get in line if the actor is busy, but have it fire a reminder when needed.

I am trying to use StateProvider.SaveReminderAsync and from what the function summary says it should work exactly like I want.. but it does not, and I can not find a single sample online about this function. I've been looking for 2 days and tried a bunch of things to get it working with no luck.

Thanks for any help

    public class ActorReminderTestServices : ActorService, IActorReminderTestService, IService
    {
 
        public ActorReminderTestServices(StatefulServiceContext context,
                ActorTypeInformation actorTypeInfo,
                Func<ActorService, ActorId, ActorBase> actorFactory = null,
                Func<ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                IActorStateProvider stateProvider = null,
                ActorServiceSettings settings = null)
                : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
        {
        }
         
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            await base.RunAsync(cancellationToken);
            #region Code to limit this to running just on 1 partition
            FabricClient _fabricClient = new FabricClient();
            System.Fabric.Query.ServicePartitionList _partitionList = await _fabricClient
                .QueryManager.GetPartitionListAsync(this.Context.ServiceName);
            System.Fabric.Query.Partition _1stPartition = _partitionList.OrderBy(a =>
                 (a.PartitionInformation as Int64RangePartitionInformation).LowKey).FirstOrDefault();

            if (this.Partition.PartitionInfo.Id != _1stPartition.PartitionInformation.Id)
            {
                return;
            }
            #endregion
            Task.Run(async () =>
            {
                await Task.Delay(10000);
                await this.CreateActors(cancellationToken);
            });
        }

        public async Task CreateActors(CancellationToken cancellationToken)
        {  
            try
            { 
                Guid _test2 = Guid.Parse("4C1DC22F-27DF-40C0-AD38-DC1971BDB281"); // {4C1DC22F-27DF-40C0-AD38-DC1971BDB281}
                ActorId _actor2 = new ActorId(_test2);
                // this function on the stateprovider.. how is this suppose to be used??
                // from looking at the SF source this object that is used in the actual actor
                // in an internal class, I tried creating my own version, but than the issues is it uses IActorManager
                // and that is internal.. how can I use this function.  I would like to loop through
                // all the actors and add a reminder to all of them with out having to call the actor directly
                await this.StateProvider.SaveReminderAsync(_actor2, new IActorReminder { Name = "testing", DueTime = TimeSpan.FromSeconds(1), Period = TimeSpan.FromSeconds(1), State = null }, cancellationToken);
             }
            catch (Exception ex)
            { 
            } 
        } 
    }
}
0

There are 0 best solutions below