private static async Task ExecuteAsync(FlexibleOptions options, CancellationToken token)
        {
            logger.Info("Start");

            // TODO: implement execution
            // ...
            // if (token.IsCancellationRequested) return;
            // ...

            var publish = Task.Run(() => {
                using (var queue = CreateQueue())
                {
                    for (var j = 0; j < 10; j++)
                    {
                        for (var i = 0; i < 250; i++)
                        {
                            queue.Publish("teste khalid " + i);
                        }
                        logger.Debug("publish progress " + (j + 1) * 250);
                    }
                }
            });

            Task.Delay(30000).Wait();

            var consume = Task.Run(() =>
            {
                int count = 0;
                using (var queue = CreateQueue())
                {
                    //foreach (var i in queue.Get (TimeSpan.FromMinutes (30)))
                    ParallelTasks <RabbitWorkMessage> .Process(queue.Get(TimeSpan.FromSeconds(1800)), 30, i =>
                    {
                        // ...
                        //i.Ack ();

                        if (count % 2 == 0)
                        {
                            i.Nack();
                        }
                        else
                        {
                            i.Requeue();
                        }

                        //Task.Delay (50).Wait ();
                        if (count++ % 250 == 0)
                        {
                            logger.Debug("ack progress " + count);
                        }
                        //}
                    });
                }
            });

            await publish;

            consume.Wait();

            logger.Info("End");
        }
Пример #2
0
        public bool Execute(ISessionContext context)
        {
            _context = context;
            _logger  = context.GetLogger();
            _options = context.Options;

            IFileTransfer input = null;

            _fileTransferService = context.GetContainer().GetInstanceOf <IFileService> ();
            _deleteSourceFile    = _options.Get <bool> ("deleteSourceFile", false);
            _retryCount          = _options.Get <int> ("retryCount", 2);
            _retryWait           = TimeSpan.FromMilliseconds(_options.Get <int> ("retryWaitMs", 250));

            try
            {
                var searchPath = _options.Get("inputPath", _options.Get("searchPath", ""));
                if (String.IsNullOrEmpty(searchPath))
                {
                    throw new ArgumentNullException("inputPath");
                }

                if (String.IsNullOrEmpty(_options.Get("outputPath", "")))
                {
                    throw new ArgumentNullException("outputPath");
                }

                _maxFilesCount = _options.Get("maxFileCount", _maxFilesCount);
                if (_maxFilesCount <= 0)
                {
                    _maxFilesCount = Int32.MaxValue;
                }

                // prepare paths
                input = _fileTransferService.Open(searchPath, _options);
                if (!input.IsOpened())
                {
                    throw new Exception(String.Format("Invalid inputPath, {0}: {1}", input.LastError ?? "", searchPath));
                }

                // try move files
                ParallelTasks <FileTransferInfo> .Process(input.ListFiles().Take(_maxFilesCount), 0, _options.Get("maxConcurrency", 2), f => MoveFileInternal(f, searchPath));

                if (!String.IsNullOrEmpty(input.LastError))
                {
                    _logger.Warn(input.LastError);
                }

                if (_filesCount > 0)
                {
                    _logger.Success("Done");
                    return(true);
                }
                else
                {
                    _logger.Debug("No Files Found on: " + searchPath);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                context.Error = ex.Message;
                _logger.Error(ex);
                return(false);
            }
            finally
            {
                if (input != null)
                {
                    input.Dispose();
                }
            }
        }