Git Product home page Git Product logo

chroniton's People

Contributors

leosperry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chroniton's Issues

Make Tutorial less superfical

Right now the example and tutorial gives little guidance on how to use this in a real world application.
You say:

Construct an IJob The library has a SimpleJob and SimpleParameterizedJob built for you which take Action in their constructors. You can also create your own IJob implementation.

but chances are those 2 jobs, SimpleJob and SimpleParameterizedJob, are not going to be of much use. Just saying "You can also create your own IJob implementation" doesn't help , the tutorial should show how to do this.

Same issue where you say :

Construct an ISchedule You can use one of the built in schedules or create your own ISchedule.

Again show us HOW to create your own ISchedule.

How to use JobExceptionHandler's

Hi there,

Thanks for the nice project!

I've got some troubles in using JobExceptionHandler.

I tried to use OnJobError and OnScheduleError

            _singularity.OnJobError += HandlerError;
            _singularity.OnScheduleError += HandlerError;

Whereas HandlerError is private class instance method or static class method. Neither works for me. Methods are not called.

I'm also using custom error reporting library to log exception to Sentry. So, there is some dependency I need to pass into HandlerError

It would be nice to have a sample of error handling.

A Little Suggestion About Singularity.jobEnd Method

origin codes below:

Task task = null;
            if (jobTask.Exception == null)
            {
                task=Task.Run(() => _onSuccess?.Invoke(new ScheduledJobEventArgs(job)));
            }
            else
            {
                task=Task.Run(() => _onJobError?.Invoke(new ScheduledJobEventArgs(job),
                    jobTask.Exception is AggregateException? jobTask.Exception.InnerException : jobTask.Exception));
            }
            task.ContinueWith(t =>
            {
                _tasks.Remove(jobTask);
                setNextExecution(job);
            });

suggestion codes below:

Task task = null;
            if (jobTask.Exception == null)
            {
                task=Task.Run(() => _onSuccess?.Invoke(new ScheduledJobEventArgs(job)));
            }
            else
            {
                task=Task.Run(() => _onJobError?.Invoke(new ScheduledJobEventArgs(job),
                    jobTask.Exception is AggregateException? jobTask.Exception.InnerException : jobTask.Exception));
            }
            task.ContinueWith(t =>
            {
                _tasks.Remove(jobTask);
                setNextExecution(job);
            });

Because Task is async,so when HandleError or HandleSuccess method complete after setNextExecution,
ScheduledJob.RunTime maybe next scheduleTime,but last ScheduledJob.RunTime works for me.
tank u for your attention.

Scheduling async jobs

Whilst the scheduling is working in an asynchronous fashion, often the jobs themselves are asynchronous. For example:

async (id, dt) =>
{
    await somethingAsync();
}

One of the serious dangers, is that the job will accept this lambda and then treat as fire-and-forget. By overloading the jobs to accept a Func it will be processed correctly through the scheduler.

Dependency Injection Problem - SignalR with Chroniton

I'm using chroniton to run my jobs. Also those jobs need to send message to SignalR clients which is grouped. But any how it is not sending.

Here is my job

namespace Logic.Logics
{
    public class JobLogic : IJobLogic
    {
        private readonly IUnitOfWork unitOfWork;
        IHubContext<MyHub> hubContext;

        public JobLogic(
            IUnitOfWork unitOfWork,
            IHubContext<MyHub> hubContext,
        )
        {
            this.unitOfWork = unitOfWork;
            this.hubContext = hubContext;
        }

        public void UpdateCredidJob()
        {
            this.unitOfWork.User.DecreaseCredit();
            this.NotifiyVehicles();
        }

        private void NotifiyVehicles() {

            var vehicles = this.unitOfWork.Vehicle.GetAll();
            foreach(Vehicle v in vehicles) {
                Vehicle vehicle = this.unitOfWork.Vehicle.GetByLicensePlate(v.LicensePlate);
                VehicleViewModel vm = Mapper.Map<VehicleViewModel>(vehicle);
                this.hubContext.Clients.Group("OwnVehicle"+vm.LicensePlate).SendAsync("ReceiveVehicle",vm).Wait();
            }
        }
    }
  }

scheduling the job with chroniton and adding signalR in Startup.cs

    public void ConfigureServices(IServiceCollection services)
     {
        ...
        services.AddSignalR(o=>{
            o.EnableDetailedErrors = true;
        });
    
        var serviceProvider = services.BuildServiceProvider();
        var singularity = Singularity.Instance;
        singularity.Start();
        singularity.ScheduleJob(
            new CronSchedule("0 0 0 * * * *"),
            new SimpleJob(
                dt=>{
                    IJobLogic jobRunner = (IJobLogic) serviceProvider.GetService<IJobLogic>();
                    jobRunner.DailyCredidJob();
                }
            ),
            false
            );
    ...
    }
    
    
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider serviceProvider, PostgreSqlContext postgreSqlContext)
   {
    ...
       app.UseEndpoints(endpoints =>
       {
           endpoints.MapHub<MyHub>("/my-hub");
       });
    ...
    }

As you see I'm sending message to a group which start with OwnVehicle and clients invokes JoinOwnVehicle in order to joint that group.

public class MyHub : Microsoft.AspNetCore.SignalR.Hub
{
        ...
        public async Task JoinOwnVehicle() {
            await Groups.AddToGroupAsync(Context.ConnectionId, "OwnVehicle"+this.RequestedVehicle.LicensePlate);
        }
        ...
}

But job can not send message to group clients. I'm sure that clients can join to groups because when I try to send message in a controller it works.

Probably DI doesn't work properly, I'm doing a mistake.

Can you help me about this issue?

Details

I'm using .NET Core 5.0 and Chroniton version is 1.0.3.3

Stopping in progress jobs

How does this library cater for jobs that are in progress when a Stop is initiated. It would be great to have a mechanism like Task StopAndWait() that stops all scheduled jobs allows all in progress jobs to finish. Is this possible here?

CronDateFinder - ArgumentOutOfRangeException if input second is 59

This line

DateTime retVal = new DateTime(

DateTime retVal = new DateTime( input.Year, input.Month, input.Day, input.Hour, input.Minute, input.Second + 1);

cause an Exception if the input DateTime has seconds set to 59,:

System.ArgumentOutOfRangeException: Hour, Minute, and Second parameters describe an un-representable DateTime. at System.DateTime.TimeToTicks(Int32 hour, Int32 minute, Int32 second)

I suggest you to use AddSecond() function instead

DateTime retVal = new DateTime( input.Year, input.Month, input.Day, input.Hour, input.Minute, input.Second ); retVal = retVal.AddSeconds(1);

ReaderWriterLockSlim requires disposing

ConcurrentHashSet uses ReaderWriterLockSlim which implements IDisposable. This and consumers like Singularity therefore needs to be marked as IDisposable, so this can be correctly cleaned up.

DotNet Core support?

Hello.
Can I use this package in DotNet Core 2?
If I can please tell me which package should I install?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.