exec

Version, currently 1.0.01 version
  • 1.0.0latestJan 22, 2022

github.com/mgomes/exec

Periodically execute Crystal code blocks

0 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  exec:
    github: mgomes/exec
    version: ~> 1.0.0

Then run:

shards install

shard.yml

Crystal
~> 1.0
License
MIT
Author
Mauricio Gomes

Dependencies

This version declares no dependencies.

README

Exec

A lightweight library for executing blocks at specified intervals. This library aims to solve the following:

  • Reliably run blocks at specified intervals regardless of the runtime duration of the block.
  • Keep it light (avoid timezones and dependencies)

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      exec:
        github: mgomes/exec
  2. Run shards install

Usage

require "exec"

Specify the execution intervals for your code blocks:

Exec.every(1.second) do
  do_work
end
Exec.every(3.hours) do
  do_work
end

Caveats

  • In the usage examples above, if the do_work method takes longer to execute than the specified interval, the next interval will be executed before the existing code block has completed. Therefore, multiple versions of do_work will be executing concurrently. If this is a concern for your code block, ensure you have enough margin built into the interval or that you've built in other safety measures to prevent corruption.

  • You'll likely want to compile your applications with the -Dpreview_mt flag to take advantage of parallel execution. You can then run your binary with the CRYSTAL_WORKERS=N environment variable. Set N to the number of cores on your CPU.