Giter Site home page Giter Site logo

hangfire.scripting's Introduction

Hangfire.Scripting

Hangfire.Scripting lets you run CScharp scripts with Roslyn using Microsoft.CodeAnalysis.CSharp.Scripting nuget package. This hangfire extension uses a modified version of the https://github.com/pjrharley/Hangfire.Core.Dashboard.Management extension to enable scheduling and manual execution of your scripts.

How to use

Initialize scripting by calling UseScripting() on Hangfire.GlobalConfiguration.Configuration. The extension supports call chaining.

GlobalConfiguration.Configuration
	.UseSqlServerStorage(@"Server=.\SQLEXPRESS; Database=Hangfire.Sample; Integrated Security=True")
	.UseScripting();

The extension requires a folder named Scripts to exists in the working directory. Alternatively a path can be provided as ScriptingOptions when calling UseScripts()

var options = new ScriptingOptions(){
	Path = "C:\\PathToYourScriptDir"
};
GlobalConfiguration.Configuration.UseScripting(options);

Writing scripts

Scripts should be placed in the Scripts folder of your sollution (or in the path provided in ScriptingOptions) and need to have csx as file extension. A FileSystemWatcher is tracking the folder for changes, and if detected, recompiles the script file. Compilation is done as a Hangfire job so you can track the status in your Hangfire Dashboard.

Example script file:

test.csx

using System;

Console.WriteLine("TEST2");

int TestFunction()
{
    Console.WriteLine("This is a test");
 	return 42;
}

var retVal = TestFunction();

Context.WriteLine("PerformContext output");

Make sure your scripts are set to "Copy Allways" or "Copy if newer" if you're deploying from Visual Studio.

A PerformContext object with the Hangfire.Console extension methods is provided as a global variable named Context which lets your print output to your Hangfire job.

hangfire.scripting's People

Contributors

dc-jc avatar jc-85 avatar

Watchers

James Cloos avatar  avatar

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.