Giter VIP home page Giter VIP logo

jobs's Introduction

UPDATE - This library has is moving to the Shiny Framework at https://github.com/shinyorg/shiny but will continue to offer support for now

ACR Background Jobs Plugin for Xamarin & Windows

Change Log - March 5, 2019

Plugin.Jobs|NuGet

BUILDS

Branch Status
Master Build status
Dev Build status

PLATFORMS

Platform Version
Android 5.0+
iOS 8+
Windows UWP 16299+
Any Other Platform Must Support .NET Standard 2.0

iOS, Android, & UWP implementations use Xamarin Essentials

FEATURES

  • Cross Platform Background Jobs Framework
  • Run adhoc jobs in the background (mainly for use on iOS)
  • Define jobs with runtime parameters to run at regular intervals
  • Internal logging to let you know how often jobs are running, if they complete successfully or error
  • Place criteria as to when jobs can run responsibly
    • device is charging
    • battery is not low
    • Internet connectivity via Mobile
    • Internet connectivity via WiFi

DOCS

SETUP

Install From NuGet

Follow the Setup Guids

HOW TO USE

Creating a One-Time Adhoc Job

// To issue an adhoc task that can continue to run in the background 
CrossJobs.Current.RunTask(async () => 
{
    // your code
});

Scheduling a background job

// first define your job
public class YourJob : IJob
{
    public async Task Run(JobInfo jobInfo, CancellationToken cancelToken)
    {
        var loops = jobInfo.GetValue("LoopCount", 25);

        for (var i = 0; i < loops; i++)
        {
            if (cancelToken.IsCancellationRequested)
                break;

            await Task.Delay(1000, cancelToken).ConfigureAwait(false);
        }
    }
}
var job = new JobInfo
{
    Name = "YourJobName",
    Type = typeof(YourJob),

    // these are criteria that must be met in order for your job to run
    BatteryNotLow = this.BatteryNotLow,
    DeviceCharging = this.DeviceCharging
    NetworkType = NetworkType.Any,
    Repeat = true; //defaults to true, set to false to run once OR set it inside a job to cancel further execution
};

// you can pass variables to your job
job.SetValue("LoopCount", 10);


// lastly, schedule it to go - don't worry about scheduling something more than once, we just update if your job name matches an existing one
CrossJobs.Current.Schedule(job);

Cancelling Jobs

// Cancelling A Job
CrossJobs.Current.Cancel("YourJobName");

// Cancelling All Jobs
CrossJobs.Current.CancelAll();

Running Jobs On-Demand

// Run All Jobs On-Demand
var results = await CrossJobs.Current.RunAll();

// Run A Specific Job On-Demand
var result = await CrossJobs.Current.Run("YourJobName");

jobs's People

Contributors

aritchie avatar danielcauser avatar

Watchers

James Cloos 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.