Coder Social home page Coder Social logo

agausachs / hangfire.dashboard.management Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mccj/hangfire.dashboard.management

0.0 1.0 0.0 1.26 MB

Hangfire.Dashboard.Management provides a Management page in the default dashboard. It allows for manually creating jobs.

License: MIT License

JavaScript 15.85% C# 54.52% HTML 29.63%

hangfire.dashboard.management's Introduction

Hangfire.Dashboard.Management

Build status MyGet NuGet MIT License

Hangfire.Dashboard.Management provides a Management page in the default dashboard. It allows for manually creating jobs.

management

Features

  • Automatic page and menu generation: Simple attributes on your job classes define management pages.
  • Automatic input generation: Simple attributes on your properties allows for auto generation of input fields. (bool, int, text, DateTime)
  • **Support for IJobCancellationToken and PerformContext **: These job properties are automatically ignored and set null on job creation.
  • Simple Fire-and-Forget: Directly from your Management dashboard you can fire any Job.
  • Set a Cron Job: Define your cron and set it for any Job.
  • Schedule a Job: Schedule your job to run in the future. (Currently 5, 10, 15, 30 and 60 min intervals)
  • Extensable: Use the framework to add your own additional pages. (takes so digging to figure this out)

Setup

ASP.NET Core Applications

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllersWithViews();

        services.AddHangfire(configuration => configuration
            .UseSimpleAssemblyNameTypeSerializer()
            .UseRecommendedSerializerSettings()
            .UseMemoryStorage()
            .UseManagementPages(config => {
                return config
                    .AddJobs(< assembly with IJob implementations >)
                    .SetCulture(new System.Globalization.CultureInfo("en-us"))
                    //.TranslateJson(< Custom language JSON >)
                    ////or
                    //.TranslateCulture(< Custom Language Object >)
                    ////or
                    //.TranslateStream(< Custom language Stream >);
                    ;
            })
        );

        // Add the processing server as IHostedService
        services.AddHangfireServer();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseHangfireDashboard();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}

ASP.NET Applications

GlobalConfiguration.Configuration
    .UseManagementPages(config => {
        return config
            .AddJobs(< assembly with IJob implementations >)
            .SetCulture(new System.Globalization.CultureInfo("en-us"))
            //.TranslateJson(< Custom language JSON >)
            ////or
            //.TranslateCulture(< Custom Language Object >)
            ////or
            //.TranslateStream(< Custom language Stream >);
            ;
    });    

Defining Pages

Pages are defined and based on your Job classes. A Job class needs to implement IJob. The class should also have the attribute ManagementPage defined. Everything within this class will be on it's own page and have a navigation item in the side menu.

Each function within the class is defined as a specific job. The function should be decorated with DisplayName and Description. Displayname will be in the header of the panel and description is part of the panel body.

Each input property, other than IJobCancellationToken and PerformContext, should be decorated with the DisplayData attribute. This defines the input label and placeholder text for better readability.

[ManagementPage("Misc Jobs", "Miscellaneous", "misc")]
public class MiscJobs : IJob
{   
    [DisplayName("Test")]    
    [Description("Test that jobs are running with simple console output.")]
    [AutomaticRetry(Attempts = 0)]
    [DisableConcurrentExecution(90)]
    public void Test(PerformContext context, IJobCancellationToken token,
            [DisplayData("Output Text", "Enter text to output.")] string outputText,
            [DisplayData("Repeat When Completed", "Repeat")] bool repeat,
            [DisplayData("Test Date", "Enter date")] DateTime testDate) 
            {
                 context.WriteLine(outputText);
                 Thread.Sleep(15000);

                 token.ThrowIfCancellationRequested();

                 if (repeat)
                 {
                      context.WriteLine("Enquing the job again from the job.");
                      BackgroundJob.Enqueue<MiscJobs>(m => m.Test(context, token, outputText, repeat));
                 }
            }
}

Caution

Things might not work as expected and could just not work. There has only been manual testing so far. If attributes are missing I'm not sure what will happen.

License

Copyright (c) 2017

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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.