Example #1
0
 public void On(ISubscriptionContext <GeoLocation> context, RiderEvent evt)
 {
     if (GeoLocation.Equals(context.Key, evt.PreviousAvailability))
     {
         AvailableRiders.Remove(evt.RiderId);
     }
     else if (GeoLocation.Equals(context.Key, evt.CurrentAvailability))
     {
         AvailableRiders.Add(evt.RiderId, evt);
         context.ForkOrchestration(new TryMatchRider()
         {
             AvailableRider = evt
         });
     }
 }
Example #2
0
        public async Task <UnitType> Execute(IOrchestrationContext context)
        {
            var nearbyArea = AvailableDriver.CurrentAvailability.Value.GetNearbyAreas();

            RiderEvent candidate = null;

            foreach (var location in nearbyArea)
            {
                candidate = await context.PerformRead(new GetAvailableRider()
                {
                    Location = location
                });

                if (candidate != null)
                {
                    break;
                }
            }

            if (candidate == null)
            {
                // there are no matches. So we just wait until someone joins and gets matched to us.
                return(UnitType.Value);
            }

            try
            {
                var result = await context.PerformOrchestration(new TryFinalizeMatch()
                {
                    AvailableDriver = AvailableDriver,
                    AvailableRider  = candidate
                });

                if (result == TryFinalizeMatch.Response.DriverRemainsUnmatched)
                {
                    // retry in order to find another match
                    context.ForkOrchestration(this);
                }
            }
            catch (TransactionException)
            {
                // transaction ran into trouble for some reason... retry this orchestration
                context.ForkOrchestration(this);
            }

            return(UnitType.Value);
        }
Example #3
0
 public void On(ISubscriptionContext <string> context, RiderEvent evt)
 {
     Availability = evt.CurrentAvailability;
 }