Hangfire.RecurringJobAdmin icon indicating copy to clipboard operation
Hangfire.RecurringJobAdmin copied to clipboard

Last Execution and Next Execution shows "Invalid Date" after successfull execution of job

Open Cnecne59 opened this issue 4 years ago • 2 comments

Both button show the text "Invalid date", but the recurring job is executed serveral times without any error. I am using TZ UTC and West european Standard time. Any ideas what is going wrong?

Cnecne59 avatar Feb 26 '21 14:02 Cnecne59

I am able to reproduce your issue when the date format is other than en-us. For example 4/13/2021 2:19 PM works, but 13.4.2021 14:19 not.

I didn't investigate deeply, but the error will likely be in JobExtension.html

raskajan avatar Apr 14 '21 07:04 raskajan

Quick and dirty fix for datetime format issue this is clearly not the right place since it is an UI issue and should not be sorted out in the backend

File: Hangfire.RecurringJobAdmin\Pages\GetJobDispatcher.cs ` using Hangfire.Annotations; using Hangfire.Common; using Hangfire.RecurringJobAdmin.Core; using Hangfire.RecurringJobAdmin.Models; using Hangfire.Storage; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Globalization; using System.Linq.Expressions; using System.Net; using System.Text; using System.Threading.Tasks;

namespace Hangfire.RecurringJobAdmin.Pages { internal sealed class GetJobDispatcher : Dashboard.IDashboardDispatcher { private readonly IStorageConnection _connection; public GetJobDispatcher() { _connection = JobStorage.Current.GetConnection(); } public async Task Dispatch([NotNull] Dashboard.DashboardContext context) { if (!"GET".Equals(context.Request.Method, StringComparison.InvariantCultureIgnoreCase)) { context.Response.StatusCode = 405; return; }

        var recurringJob = _connection.GetRecurringJobs();
        var periodicJob = new List<PeriodicJob>();

        CultureInfo US_TimeFormat = new CultureInfo("en-US");

        if (recurringJob.Count >  0)
        {
            recurringJob.ForEach((x) =>
            {
                periodicJob.Add(new PeriodicJob
                {
                    Id = x.Id,
                    Cron = x.Cron,
                    CreatedAt = x.CreatedAt.HasValue ? x.CreatedAt.Value.ChangeTimeZone(x.TimeZoneId) : new DateTime(),
                    Error = x.Error,
                    LastExecution = x.LastExecution.HasValue ? x.LastExecution.Value.ChangeTimeZone(x.TimeZoneId).ToString("G", US_TimeFormat) : "N/A",
                    Method = x.Job?.Method.Name,
                    JobState = "Running",
                    Class = x.Job?.Type.Name,
                    Queue = x.Queue,
                    LastJobId = x.LastJobId,
                    LastJobState = x.LastJobState,
                    NextExecution = x.NextExecution.HasValue ? x.NextExecution.Value.ChangeTimeZone(x.TimeZoneId).ToString("G", US_TimeFormat) : "N/A",
                    Removed = x.Removed,
                    TimeZoneId = x.TimeZoneId
                });
            });
        }

        //Add job was stopped:
        periodicJob.AddRange(JobAgent.GetAllJobStopped());

        await context.Response.WriteAsync(JsonConvert.SerializeObject(periodicJob));
    }
}

}

`

vipasane avatar Feb 24 '22 09:02 vipasane

Hello. Any chance that this will be fixed? BTW, this bug is even visible in Readme.MD of the project

FixRM avatar Dec 09 '22 15:12 FixRM

Hi guys, I have just accepted the PR that solves this issue, thank you!

bamotav avatar Feb 13 '23 21:02 bamotav