Пример #1
0
        public async Task Execute(PerformContext context)
        {
            _logger.HangfireContext = context;

            _logger.LogDebug("Starting job...");

            var prefixes = new string[] { "Fugg", "Dog", "Cheek", "Moo", "Bob", "Choo", "Zee", "Wagh", "Chomp" };
            var suffixes = new string[] { "ed", "er", "ington", "ssssss", "oes", "choo", "lah", "gh", "alot" };

            var name = $"{prefixes[_random.Next(prefixes.Length)]}{suffixes[_random.Next(suffixes.Length)]}";

            var item = new Widget()
            {
                Name        = name,
                Processing  = true,
                DateCreated = DateTime.Now
            };

            _logger.LogDebug("Creating Widget #{0} {1}...", item.Id, item.Name);

            for (int i = 0; i < 10; i++)
            {
                _logger.LogDebug("Thinking...");
                Thread.Sleep(1000);
            }

            var widget = await _service.CreateAsync(item);

            _logger.LogDebug("Created Widget #{0} {1}", widget.Id, widget.Name);

            context.WriteLine("");
        }
Пример #2
0
        public async Task Execute(PerformContext context, int id)
        {
            _logger.LogDebug("Starting job.");

            var widget = await _service.GetAsync(id);

            _logger.LogDebug("Processing Widget #{0} {1}...", widget.Id, widget.Name);

            for (int i = 0; i < 10; i++)
            {
                _logger.LogDebug("Doing Stuff...");
                Thread.Sleep(1000);
            }

            widget.Processing = false;

            await _service.UpdateAsync(widget);

            _logger.LogDebug("Processed Widget #{0} {1}.", widget.Id, widget.Name);

            context.WriteLine("");
        }