Skip to content

not support hangfire.console? I need use it for WriteProgressBar, but not work #2

Description

@JiChao99

thanks for your work on this project.

I’ve been using Hangfire with a custom attribute to dynamically schedule and invoke jobs, and I pass specific parameters to them.

Handler

var x = scope.ServiceProvider.GetRequiredService<IPerformContextAccessor>();
var result = !method.GetParameters().Any(t => t.ParameterType == typeof(PerformContext)) ? (Task?)method.Invoke(obj, new object[] { 
tenants }) :
    (Task?)method.Invoke(obj, new object?[] { tenants, x.PerformingContext });

And here is the job method that is intended to display progress:

[CustomArrtibute("0 14 * * *")]
public Task ScheduleJob(IEnumerable<long> tenants, PerformContext performContext)
{
    var bar = performContext.WriteProgressBar(10);

    for (var i = 0; i <= 100; i += 10)
    {
        bar.SetValue(i); 
        System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(200));
    }
    Console.WriteLine("do " + DateTime.Now);

    return Task.CompletedTask;
}

However, the bar.SetValue(i) method does not seem to be functioning as expected. The progress bar does not reflect the current progress state during the job execution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions