Ejemplo n.º 1
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req,
            TraceWriter log,
            Binder binder)
        {
            QiStreamBatchRepository repository = new QiStreamBatchRepository();
            await repository.DeleteExistingStreamBatches().ConfigureAwait(false);

            string batchSizeString = ConfigurationManager.AppSettings["QiStreamsPerWorker"];
            int    batchSize;

            if (!int.TryParse(batchSizeString, out batchSize))
            {
                batchSize = 10000;
            }
            List <string> qiStreams = await GetQiStreamsAsync().ConfigureAwait(false);

            int batchCount = (int)Math.Ceiling(qiStreams.Count * 1d / batchSize);

            List <QiStreamEntity> qiStreamEntities = qiStreams.Select((streamId, index) => new QiStreamEntity()
            {
                id = streamId, batchid = index % batchCount
            }).ToList();
            var qiStreamBatches = qiStreamEntities.GroupBy(qse => qse.batchid).ToDictionary(group => group.Key, group => group.Select(qse => qse.id).ToList());

            await repository.SaveStreamBatchesAsync(qiStreamBatches);

            return(req.CreateResponse(HttpStatusCode.OK, $"{qiStreamEntities.Count} streams resolved"));
        }
Ejemplo n.º 2
0
        public static async Task Run([ServiceBusTrigger("qillion", AccessRights.Manage, Connection = "QillionTriggerBus")] BatchEntity batchEntity, TraceWriter log, Microsoft.Azure.WebJobs.ExecutionContext context)
        {
            log.Info($"Qi stream batch worker processing batch {batchEntity.id}");

            BindingRedirector.RedirectAssembly("Google.Apis.Auth", new Version("1.28.0.0"), "4b01fa6e34db77ab");
            BindingRedirector.RedirectAssembly("Google.Apis.Auth.PlatformServices", new Version("1.28.0.0"), "4b01fa6e34db77ab");

            QiStreamBatchRepository repository = new QiStreamBatchRepository();
            List <string>           streamIds  = await repository.GetStreamsInBatch(batchEntity.id);

            string       qiNamespace = ConfigurationManager.AppSettings["QiNamespace"];
            QiClientSlim qiClient    = new QiClientSlim();

            await GetAndSendSnapshotsAsync(qiNamespace, streamIds, qiClient, context, log);
        }
Ejemplo n.º 3
0
        public static async Task Run(
            [TimerTrigger("0 */15 * * * *")] TimerInfo myTimer,
            [ServiceBus("qillion", AccessRights.Manage, Connection = "QillionTriggerBus")] ICollector <BatchEntity> batchQueue,
            TraceWriter log)
        {
            log.Info($"Stream Batch Enqueuer executed at: {DateTime.Now}");

            QiStreamBatchRepository repository = new QiStreamBatchRepository();
            int batchCount = await repository.GetStreamBatchCountAsync();

            IEnumerable <BatchEntity> batchEntities = Enumerable.Range(0, batchCount).Select(i => new BatchEntity()
            {
                id = i
            });

            foreach (BatchEntity batchEntity in batchEntities)
            {
                batchQueue.Add(batchEntity);
            }
        }