Skip to content

Commit

Permalink
Bump to v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
erdnaxeli committed Dec 27, 2020
1 parent e63ab25 commit d0df905
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 36 deletions.
95 changes: 68 additions & 27 deletions docs/Marmot.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ <h1 class="project-name">

<ul>

<li class=" " data-id="marmot/Marmot/AtTask" data-name="marmot::attask">
<a href="Marmot/AtTask.html">AtTask</a>

</li>

<li class=" " data-id="marmot/Marmot/Callback" data-name="marmot::callback">
<a href="Marmot/Callback.html">Callback</a>

Expand Down Expand Up @@ -116,7 +121,7 @@ <h2>

<p>Marmot schedules tasks on three possibles ways:</p>

<ul><li>on a periodic span (<code><a href="Marmot.html#repeat(span:Time::Span,first_run=false,&block:Callback):Task-instance-method">Marmot.repeat</a></code>)</li><li>every day at a given time (<code><a href="Marmot.html#cron(hour,minute,second=0,&block:Callback):Task-instance-method">Marmot.cron</a></code>)</li><li>when a value is available on a channel (<code><a href="Marmot.html#on(channel,&block:Callback):Task-instance-method">Marmot.on</a></code>)</li></ul>
<ul><li>on a periodic span (<code>Marmot.repeat</code>)</li><li>every day at a given time (<code>Marmot.cron</code>)</li><li>when a value is available on a channel (<code><a href="Marmot.html#on(channel,&block:Callback):Task-instance-method">Marmot.on</a></code>)</li></ul>

<p>Tasks are all executed on the same fiber.
This means two things: first, you don't have to worry about concurrency
Expand All @@ -141,6 +146,11 @@ <h2>
is called again.
To cancel all the tasks there is <code><a href="Marmot.html#cancel_all_tasks:Nil-instance-method">Marmot.cancel_all_tasks</a></code>.</p>

<p>If the computer's clock changes, the tasks scheduled on a specific time will
<em>not</em> be scheduled again.
Their next runs will be triggered at the time before the clock changes, but the
next ones will be correctly scheduled.</p>




Expand Down Expand Up @@ -198,7 +208,7 @@ <h2>


<dt class="entry-const" id="VERSION">
<strong>VERSION</strong> = <code><span class="s">&quot;0.2.2&quot;</span></code>
<strong>VERSION</strong> = <code><span class="s">&quot;0.3.0&quot;</span></code>
</dt>


Expand All @@ -220,6 +230,13 @@ <h2>
</h2>
<ul class="list-summary">

<li class="entry-summary">
<a href="#at(time:Time,&block:Callback):Task-instance-method" class="signature"><strong>#at</strong>(time : Time, &block : Callback) : Task</a>

<div class="summary"><p>Runs a task once at a given time.</p></div>

</li>

<li class="entry-summary">
<a href="#cancel_all_tasks:Nil-instance-method" class="signature"><strong>#cancel_all_tasks</strong> : Nil</a>

Expand All @@ -228,23 +245,23 @@ <h2>
</li>

<li class="entry-summary">
<a href="#cron(hour,minute,second=0,&block:Callback):Task-instance-method" class="signature"><strong>#cron</strong>(hour, minute, second = <span class="n">0</span>, &block : Callback) : Task</a>
<a href="#every(span:Time::Span,first_run=false,&block:Callback):Task-instance-method" class="signature"><strong>#every</strong>(span : Time::Span, first_run = <span class="n">false</span>, &block : Callback) : Task</a>

<div class="summary"><p>Runs a task every day at <em>hour</em> and <em>minute</em>.</p></div>
<div class="summary"><p>Runs a task every given <em>span</em>.</p></div>

</li>

<li class="entry-summary">
<a href="#on(channel,&block:Callback):Task-instance-method" class="signature"><strong>#on</strong>(channel, &block : Callback) : Task</a>
<a href="#every(span:Symbol,*,day=1,hour=0,minute=0,second=0,&block:Callback):Task-instance-method" class="signature"><strong>#every</strong>(span : Symbol, *, day = <span class="n">1</span>, hour = <span class="n">0</span>, minute = <span class="n">0</span>, second = <span class="n">0</span>, &block : Callback) : Task</a>

<div class="summary"><p>Runs a task when a value is received on a channel.</p></div>
<div class="summary"><p>Runs a task every <em>span</em> at the given <em>day</em>, <em>hour</em>, <em>minute</em> and <em>second</em>.</p></div>

</li>

<li class="entry-summary">
<a href="#repeat(span:Time::Span,first_run=false,&block:Callback):Task-instance-method" class="signature"><strong>#repeat</strong>(span : Time::Span, first_run = <span class="n">false</span>, &block : Callback) : Task</a>
<a href="#on(channel,&block:Callback):Task-instance-method" class="signature"><strong>#on</strong>(channel, &block : Callback) : Task</a>

<div class="summary"><p>Runs a task every given <em>span</em>.</p></div>
<div class="summary"><p>Runs a task when a value is received on a channel.</p></div>

</li>

Expand Down Expand Up @@ -286,6 +303,25 @@ <h2>
Instance Method Detail
</h2>

<div class="entry-detail" id="at(time:Time,&block:Callback):Task-instance-method">
<div class="signature">

def <strong>at</strong>(time : Time, &block : <a href="Marmot/Callback.html">Callback</a>) : <a href="Marmot/Task.html">Task</a>

<a class="method-permalink" href="#at(time:Time,&block:Callback):Task-instance-method">#</a>
</div>

<div class="doc">

<p>Runs a task once at a given time.</p>
</div>

<br/>
<div>

</div>
</div>

<div class="entry-detail" id="cancel_all_tasks:Nil-instance-method">
<div class="signature">

Expand All @@ -305,17 +341,20 @@ <h2>
</div>
</div>

<div class="entry-detail" id="cron(hour,minute,second=0,&block:Callback):Task-instance-method">
<div class="entry-detail" id="every(span:Time::Span,first_run=false,&block:Callback):Task-instance-method">
<div class="signature">

def <strong>cron</strong>(hour, minute, second = <span class="n">0</span>, &block : <a href="Marmot/Callback.html">Callback</a>) : <a href="Marmot/Task.html">Task</a>
def <strong>every</strong>(span : Time::Span, first_run = <span class="n">false</span>, &block : <a href="Marmot/Callback.html">Callback</a>) : <a href="Marmot/Task.html">Task</a>

<a class="method-permalink" href="#cron(hour,minute,second=0,&block:Callback):Task-instance-method">#</a>
<a class="method-permalink" href="#every(span:Time::Span,first_run=false,&block:Callback):Task-instance-method">#</a>
</div>

<div class="doc">

<p>Runs a task every day at <em>hour</em> and <em>minute</em>.</p>
<p>Runs a task every given <em>span</em>.</p>

<p>If first run is true, it will run as soon as the scheduler runs.
Else it will wait <em>span</em> time before running for first time.</p>
</div>

<br/>
Expand All @@ -324,23 +363,22 @@ <h2>
</div>
</div>

<div class="entry-detail" id="on(channel,&block:Callback):Task-instance-method">
<div class="entry-detail" id="every(span:Symbol,*,day=1,hour=0,minute=0,second=0,&block:Callback):Task-instance-method">
<div class="signature">

def <strong>on</strong>(channel, &block : <a href="Marmot/Callback.html">Callback</a>) : <a href="Marmot/Task.html">Task</a>
def <strong>every</strong>(span : Symbol, *, day = <span class="n">1</span>, hour = <span class="n">0</span>, minute = <span class="n">0</span>, second = <span class="n">0</span>, &block : <a href="Marmot/Callback.html">Callback</a>) : <a href="Marmot/Task.html">Task</a>

<a class="method-permalink" href="#on(channel,&block:Callback):Task-instance-method">#</a>
<a class="method-permalink" href="#every(span:Symbol,*,day=1,hour=0,minute=0,second=0,&block:Callback):Task-instance-method">#</a>
</div>

<div class="doc">

<p>Runs a task when a value is received on a channel.</p>
<p>Runs a task every <em>span</em> at the given <em>day</em>, <em>hour</em>, <em>minute</em> and <em>second</em>.</p>

<p>To access the value, you need to restrict the type of the task, and use
<code><a href="Marmot/OnChannelTask.html#value:T?-instance-method">OnChannelTask#value</a></code>.</p>

<pre><code>channel <span class="o">=</span> <span class="t">Channel</span>(<span class="t">Int32</span>).<span class="k">new</span>
<span class="t">Marmot</span>.on(channel) { <span class="o">|</span>task<span class="o">|</span> puts task.<span class="k">as</span>(<span class="t">OnChannelTask</span>).value }</code></pre>
<pre><code><span class="t">Marmot</span>.every(<span class="n">:hour</span>, hour: <span class="n">16</span>, minute: <span class="n">30</span>, second: <span class="n">30</span>) <span class="c"># will run every hour at 30:30 (the hour parameter is ignored)</span>
<span class="t">Marmot</span>.every(<span class="n">:day</span>, hour: <span class="n">15</span>) { ... } <span class="c"># will run every day at 15:00:00</span>
<span class="t">Marmot</span>.every(<span class="n">:month</span>, day: <span class="n">15</span>) { ... } <span class="c"># will run every month at midnight</span>
<span class="t">Marmot</span>.every(<span class="n">:month</span>, day: <span class="n">31</span>) { ... } <span class="c"># will run every month THAT HAVE a 31th day at midnight</span></code></pre>
</div>

<br/>
Expand All @@ -349,20 +387,23 @@ <h2>
</div>
</div>

<div class="entry-detail" id="repeat(span:Time::Span,first_run=false,&block:Callback):Task-instance-method">
<div class="entry-detail" id="on(channel,&block:Callback):Task-instance-method">
<div class="signature">

def <strong>repeat</strong>(span : Time::Span, first_run = <span class="n">false</span>, &block : <a href="Marmot/Callback.html">Callback</a>) : <a href="Marmot/Task.html">Task</a>
def <strong>on</strong>(channel, &block : <a href="Marmot/Callback.html">Callback</a>) : <a href="Marmot/Task.html">Task</a>

<a class="method-permalink" href="#repeat(span:Time::Span,first_run=false,&block:Callback):Task-instance-method">#</a>
<a class="method-permalink" href="#on(channel,&block:Callback):Task-instance-method">#</a>
</div>

<div class="doc">

<p>Runs a task every given <em>span</em>.</p>
<p>Runs a task when a value is received on a channel.</p>

<p>If first run is true, it will run as soon as the scheduler runs.
Else it will wait <em>span</em> time before running for first time.</p>
<p>To access the value, you need to restrict the type of the task, and use
<code><a href="Marmot/OnChannelTask.html#value:T?-instance-method">OnChannelTask#value</a></code>.</p>

<pre><code>channel <span class="o">=</span> <span class="t">Channel</span>(<span class="t">Int32</span>).<span class="k">new</span>
<span class="t">Marmot</span>.on(channel) { <span class="o">|</span>task<span class="o">|</span> puts task.<span class="k">as</span>(<span class="t">OnChannelTask</span>).value }</code></pre>
</div>

<br/>
Expand Down
5 changes: 5 additions & 0 deletions docs/Marmot/Callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ <h1 class="project-name">

<ul>

<li class=" " data-id="marmot/Marmot/AtTask" data-name="marmot::attask">
<a href="../Marmot/AtTask.html">AtTask</a>

</li>

<li class=" current" data-id="marmot/Marmot/Callback" data-name="marmot::callback">
<a href="../Marmot/Callback.html">Callback</a>

Expand Down
13 changes: 9 additions & 4 deletions docs/Marmot/CronTask.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ <h1 class="project-name">

<ul>

<li class=" " data-id="marmot/Marmot/AtTask" data-name="marmot::attask">
<a href="../Marmot/AtTask.html">AtTask</a>

</li>

<li class=" " data-id="marmot/Marmot/Callback" data-name="marmot::callback">
<a href="../Marmot/Callback.html">Callback</a>

Expand Down Expand Up @@ -143,7 +148,7 @@ <h2>
<ul class="list-summary">

<li class="entry-summary">
<a href="#new(hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method" class="signature"><strong>.new</strong>(hour : Int32, minute : Int32, second : Int32, callback : Callback)</a>
<a href="#new(span:Symbol,day:Int32,hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method" class="signature"><strong>.new</strong>(span : Symbol, day : Int32, hour : Int32, minute : Int32, second : Int32, callback : Callback)</a>

</li>

Expand Down Expand Up @@ -215,12 +220,12 @@ <h2>
Constructor Detail
</h2>

<div class="entry-detail" id="new(hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method">
<div class="entry-detail" id="new(span:Symbol,day:Int32,hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method">
<div class="signature">

def self.<strong>new</strong>(hour : Int32, minute : Int32, second : Int32, callback : <a href="../Marmot/Callback.html">Callback</a>)
def self.<strong>new</strong>(span : Symbol, day : Int32, hour : Int32, minute : Int32, second : Int32, callback : <a href="../Marmot/Callback.html">Callback</a>)

<a class="method-permalink" href="#new(hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method">#</a>
<a class="method-permalink" href="#new(span:Symbol,day:Int32,hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method">#</a>
</div>

<br/>
Expand Down
5 changes: 5 additions & 0 deletions docs/Marmot/OnChannelTask.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ <h1 class="project-name">

<ul>

<li class=" " data-id="marmot/Marmot/AtTask" data-name="marmot::attask">
<a href="../Marmot/AtTask.html">AtTask</a>

</li>

<li class=" " data-id="marmot/Marmot/Callback" data-name="marmot::callback">
<a href="../Marmot/Callback.html">Callback</a>

Expand Down
5 changes: 5 additions & 0 deletions docs/Marmot/RepeatTask.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ <h1 class="project-name">

<ul>

<li class=" " data-id="marmot/Marmot/AtTask" data-name="marmot::attask">
<a href="../Marmot/AtTask.html">AtTask</a>

</li>

<li class=" " data-id="marmot/Marmot/Callback" data-name="marmot::callback">
<a href="../Marmot/Callback.html">Callback</a>

Expand Down
7 changes: 7 additions & 0 deletions docs/Marmot/Task.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ <h1 class="project-name">

<ul>

<li class=" " data-id="marmot/Marmot/AtTask" data-name="marmot::attask">
<a href="../Marmot/AtTask.html">AtTask</a>

</li>

<li class=" " data-id="marmot/Marmot/Callback" data-name="marmot::callback">
<a href="../Marmot/Callback.html">Callback</a>

Expand Down Expand Up @@ -123,6 +128,8 @@ <h2>
</h2>
<ul class="other-types-list">

<li class="other-type"><a href="../Marmot/AtTask.html">Marmot::AtTask</a></li>

<li class="other-type"><a href="../Marmot/CronTask.html">Marmot::CronTask</a></li>

<li class="other-type"><a href="../Marmot/OnChannelTask.html">Marmot::OnChannelTask(T)</a></li>
Expand Down
5 changes: 5 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ <h1 class="project-name">

<ul>

<li class=" " data-id="marmot/Marmot/AtTask" data-name="marmot::attask">
<a href="Marmot/AtTask.html">AtTask</a>

</li>

<li class=" " data-id="marmot/Marmot/Callback" data-name="marmot::callback">
<a href="Marmot/Callback.html">Callback</a>

Expand Down
2 changes: 1 addition & 1 deletion docs/index.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/search-index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: marmot
version: 0.2.2
version: 0.3.0

authors:
- Alexandre Morignot <erdnaxeli@cervoi.se>
Expand Down
5 changes: 3 additions & 2 deletions src/marmot.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require "./tasks"
# Their next runs will be triggered at the time before the clock changes, but the
# next ones will be correctly scheduled.
module Marmot
VERSION = "0.2.2"
VERSION = "0.3.0"

alias Callback = Proc(Task, Nil)

Expand Down Expand Up @@ -72,9 +72,10 @@ module Marmot
add_task RepeatTask.new(span, first_run, block)
end

# Runs a task every *span* at *hour* and *minute*.
# Runs a task every *span* at the given *day*, *hour*, *minute* and *second*.
#
# ```
# Marmot.every(:hour, hour: 16, minute: 30, second: 30) # will run every hour at 30:30 (the hour parameter is ignored)
# Marmot.every(:day, hour: 15) { ... } # will run every day at 15:00:00
# Marmot.every(:month, day: 15) { ... } # will run every month at midnight
# Marmot.every(:month, day: 31) { ... } # will run every month THAT HAVE a 31th day at midnight
Expand Down

0 comments on commit d0df905

Please sign in to comment.