public Task <LotPickResult> BeginPick(LotPickerAttempt attempt) { State = LotAllocationState.ALLOCATING; PickingAttempt = attempt; PickingTask = new TaskCompletionSource <LotPickResult>(); var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20)); PickingTaskWithTimeout = PickingTask.Task.ContinueWith(x => { return(x.Result); }, cts.Token); try { attempt.Session.Write(new TransferClaim { Type = ClaimType.LOT, Action = OpenAction, //x,y used as id for lots EntityId = Lot.lot_id, SpecialId = SpecialId, ClaimId = ClaimId ?? 0, FromOwner = Context.Config.Call_Sign }); } catch (Exception ex) { PickingTask.SetException(ex); } return(PickingTaskWithTimeout); }
public LotPickerAttempt PickServer() { lock (Servers) { var best = Servers.OrderByDescending(x => x.Rank).FirstOrDefault(); if (best == null || best.Rank <= 0) { return(new LotPickerAttempt(null) { Success = false }); } var attempt = new LotPickerAttempt(best) { Success = true }; best.InFlight.Add(attempt); return(attempt); } }