C. job scheduling fluent scheduler learning notes

I. Introduction

Fluent scheduler is a simple task scheduling framework, timing task manager.

GitHub address: https://github.com/fluentscheduler/FluentScheduler

II. Example procedure

2.1 interface

Create a new WinForm program FluentSchedulerClient, right-click the project - > properties - > Application - > output type, and select console application.

    

2.2 reference

Right click the project - > manage NuGet packages - > fluent scheduler.

2.3 operation

Create a new class DataSyncJob and inherit ijob, which means it is a job, and implement IJob.Execute method.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentScheduler;

namespace LinkTo.Test.FluentSchedulerClient
{
    public class DataSyncJob : IJob
    {
        void IJob.Execute()
        {
            Console.WriteLine($"This is DataSyncService submmit...:{Guid.NewGuid().ToString("N")}");
        }
    }
}

As above, create another task TestJob:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentScheduler;

namespace LinkTo.Test.FluentSchedulerClient
{
    public class TestJob : IJob
    {
        void IJob.Execute()
        {
            Console.WriteLine($"This is TestService submmit...:{Guid.NewGuid().ToString("N")}");
        }
    }
}

2.4 dispatching plant

Create a new factory class, FluentSchedulerFactory, and inherit the Registry:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentScheduler;

namespace LinkTo.Test.FluentSchedulerClient
{
    public class FluentSchedulerFactory : Registry
    {
        public FluentSchedulerFactory()
        {
            //Give Way Job Carry out single track run to avoid repeated execution when not finished.(overall situation)
            NonReentrantAsDefault();
            //Give Way Job Carry out single track run to avoid repeated execution when not finished.(Single task)
            //Schedule<DataSyncJob>().NonReentrant().ToRunNow().AndEvery(5).Seconds();

            //Perform scheduled tasks every 5 seconds immediately. (specify a time interval to run, which can be seconds, minutes, hours, days, months, years, etc. according to your own needs.)
            Schedule<DataSyncJob>().ToRunNow().AndEvery(5).Seconds();

            ////Perform a scheduled task at 18:00 on the first Monday of each month immediately
            //Schedule<DataSyncJob>().ToRunNow().AndEvery(1).Months().OnTheFirst(DayOfWeek.Monday).At(18, 0);

            ////A scheduled task that is delayed by 5 seconds. (specify a time interval to run, which can be seconds, minutes, hours, days, months, years, etc. according to your own needs.)
            //Schedule<DataSyncJob>().ToRunOnceIn(5).Seconds();

            ////Specify a time to perform the scheduled task (most commonly, at 18:00 every day.)
            //Schedule(() => Console.WriteLine("It's 18:00 now.")).ToRunEvery(1).Days().At(18, 0);

            ////Perform multiple tasks in the same plan
            //Schedule<DataSyncJob>().AndThen<TestJob>().ToRunNow().AndEvery(5).Seconds();
        }
    }
}

The fluent scheduler scheduling cycle is similar to Quartz.NET The natural language translation of Cron expression is easier to understand. In addition, the fluent scheduler can perform multiple tasks in the same plan, which I think is also one of the features.

2.5 dispatching

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FluentScheduler;

namespace LinkTo.Test.FluentSchedulerClient
{
    public partial class Main : Form
    {

        public Main()
        {
            InitializeComponent();
            //Button status
            btnStart.Enabled = true;
            btnStop.Enabled = false;
        }

        /// <summary>
        /// start
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, EventArgs e)
        {
            JobManager.Initialize(new FluentSchedulerFactory());

            //Button status
            btnStart.Enabled = false;
            btnStop.Enabled = true;
        }

        /// <summary>
        /// stop it
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStop_Click(object sender, EventArgs e)
        {
            JobManager.Stop();

            //Button status
            btnStart.Enabled = true;
            btnStop.Enabled = false;
        }
    }
}

2.6 results

Tags: C# github Windows

Posted on Wed, 20 May 2020 10:04:27 -0400 by jerryroy