Skip to content

Latest commit

 

History

History
239 lines (182 loc) · 13.1 KB

README.md

File metadata and controls

239 lines (182 loc) · 13.1 KB

ssTs: Small & Simple Task Scheduler for C++17

ssTs is a time-based Task Scheduler, written in modern C++.
Header only, with no external dependencies.

Try ssTs out on Wandbox!

ssTs

License contributions welcome Try online

Total alerts Language grade: C/C++ Codacy Badge

Build Status Azure DevOps tests codecov Codacy Badge

Documentation Status Documentation

GitHub top language GitHub code size in bytes GitHub repo size GitHub Issues

GitHub last commit GitHub release (latest by date) GitHub Release Date

Integration

Header only

Copy the include folder, that contains the 3 header files task.hpp, task_pool.hpp and task_scheduler.hpp within your project sources or set your include path to it and just build your code.
ssTs requires a C++17 compiler.

CMake

It is possible to install the library using:

$ git clone https://github.com/stefanolusardi/task_scheduler.git
$ cd ssts && mkdir build && cd build
$ cmake -G<GENERATOR> -DCMAKE_BUILD_TYPE=<Debug|Release> -DSSTS_INSTALL_LIBRARY=True -DCMAKE_INSTALL_PREFIX=</install/folder/path> ..
$ cmake --build . --config <Debug|Release> --target install 

Supported OS and Compilers

Development platforms

  • Windows 10 - Visual Studio 2019
  • Windows 10 - Clang 10.0
  • Windows 10 - Clang 9.0
  • Ubuntu 20.04 - GCC 9.3
  • Ubuntu 20.04 - Clang 9.0
  • Ubuntu 20.04 - Clang 10.0

CI platforms

Linux

  • Build Status Ubuntu 20.04 - GCC 9.3

  • Build Status Ubuntu 18.04 - GCC 9.3

  • Build Status Ubuntu 18.04 - GCC 7.5

  • Build Status Ubuntu 18.04 - GCC 8.4

  • Build Status Ubuntu 20.04 - GCC 7.5

  • Build Status Ubuntu 20.04 - GCC 8.4

  • Build Status Ubuntu 18.04 - Clang 8.0

  • Build Status Ubuntu 18.04 - Clang 9.0

  • Build Status Ubuntu 20.04 - Clang 8.0

  • Build Status Ubuntu 20.04 - Clang 9.0

  • Build Status Ubuntu 20.04 - Clang 10.0

Windows

  • Build Status Windows Server 2019 - Visual Studio 2019

  • Build Status Windows Server 2016 - Visual Studio 2017

  • Build Status Windows Server 2019 - Clang 10.0

  • Build Status Windows Server 2016 - Clang 10.0

MacOS

  • Build Status MacOS X Mojave 10.14 - Clang 10.0

  • Build Status MacOS X Mojave 10.14 - GCC 8.4

  • Build Status MacOS X Mojave 10.14 - GCC 9.3

  • Build Status MacOS X Catalina 10.15 - Clang 10.0

  • Build Status MacOS X Catalina 10.15 - GCC 8.4

  • Build Status MacOS X Catalina 10.15 - GCC 9.3

Basic Usage

  • Running a task is as simple as:
// Create a Task Scheduler instance
ts::task_scheduler s(2);

// Start Task Scheduler
s.start()

// Spawn a one-shot task in 5 seconds
s.in(5s, []{std::cout << "Hello!" << std::endl;});
  • To retrieve a task result you can do:
// Launch a task with parameters and wait for its return value
std::future f = s.at(std::chrono::steady_clock::now() + 2s, 
[](auto x, auto y){ 
    std::cout << "Input parameters: " << x << y << std::endl;
    return x+1; 
}, 42, "fourty-two");

std::cout << "Task result: " << f.get() << std::endl; // prints 43
  • It's possible to start a task giving it a task id to be able to manipulate it later:
// Check if a task is currently scheduled 
// (i.e. already inserted in the scheduler)
s.is_scheduled("my_task_id"); // false

// Check if a task is currently enabled
// (i.e. inserted and allowed to execute, by default any task is enabled)
s.is_enabled("my_task_id"); // false

// Start a recursive task with a task id that is scheduled every second
s.every("my_task_id", 1s, [](auto p){std::cout << "Hello! " << p << std::endl;}, "some_task_parameter");
s.is_scheduled("my_task_id"); // true
s.is_enabled("my_task_id"); // true

// Disable "my_task_id"
s.set_enabled("my_task_id", false);
s.is_scheduled("my_task_id"); // true
s.is_enabled("my_task_id"); // false

// Remove "my_task_id"
s.remove_task("my_task_id"s);
s.is_scheduled("my_task_id"); // false
s.is_enabled("my_task_id"); // false

// Stop Task Scheduler (by default it's always properly stopped when it goes out of scope)
s.stop();
  • Nested task creation and execution is also supported:
s.every("parent_task_id", 1s, 
    [&s]{ 
        std::cout << "Parent Task!" << std::endl;
        s.in("inner_task_id", 100ms, []{ std::cout << "Child Task!" << std::endl; });
    });

Documentation

Documentation sources are located in the docs folder. An online version of the latest docs can be found here.
Docs are automatically generated from source code at every commit using Doxygen, Breathe and Sphinx and are hosted on Read The Docs. It is possible to build the docs from CMake (Doxygen, Breathe and Sphinx are required) using:

$ git clone https://github.com/stefanolusardi/task_scheduler.git
$ cd ssts && mkdir build && cd build
$ cmake -G<GENERATOR> -DSSTS_BUILD_DOCS=True ..
$ cmake --build . 

Examples

Examples are located within the examples folder.
It is possible to build and install the examples using:

$ git clone https://github.com/stefanolusardi/task_scheduler.git
$ cd ssts && mkdir build && cd build
$ cmake -G<GENERATOR> -DCMAKE_BUILD_TYPE=<Debug|Release> -DSSTS_BUILD_EXAMPLES=True -DSSTS_INSTALL_LIBRARY=True -DSSTS_INSTALL_EXAMPLES=True ..
$ cmake --build . --config <Debug|Release>

Tests

Tests are located within the tests folder.
GoogleTest is the only 3rd party library used and it is required only to build the tests target. It is integrated using DownloadGoogleTest.cmake script. It is possible to build the tests using:

$ git clone https://github.com/stefanolusardi/task_scheduler.git
$ cd ssts && mkdir build && cd build
$ cmake -G<GENERATOR> -DCMAKE_BUILD_TYPE=<Debug|Release> -DSSTS_BUILD_TESTS=True ..
$ cmake --build . --config <Debug|Release>