diff --git a/docs/Marmot.html b/docs/Marmot.html index 808cdf0..d2c2a93 100644 --- a/docs/Marmot.html +++ b/docs/Marmot.html @@ -187,6 +187,27 @@

Defined in:

+ + + log.cr + + +
+ + + + marmot.cr + + +
+ + + + tasks.cr + + +
+ @@ -319,6 +340,8 @@


+ [View source] +
@@ -338,6 +361,8 @@


+ [View source] +
@@ -360,6 +385,8 @@


+ [View source] +
@@ -384,6 +411,8 @@


+ [View source] +
@@ -409,6 +438,8 @@


+ [View source] +
@@ -430,6 +461,8 @@


+ [View source] +
@@ -449,6 +482,8 @@


+ [View source] +
diff --git a/docs/Marmot/AtTask.html b/docs/Marmot/AtTask.html index a7bbc9c..78d7442 100644 --- a/docs/Marmot/AtTask.html +++ b/docs/Marmot/AtTask.html @@ -132,6 +132,13 @@

Defined in:

+ + + tasks.cr + + +
+ @@ -250,6 +257,8 @@


+ [View source] +
diff --git a/docs/Marmot/Callback.html b/docs/Marmot/Callback.html index 934173a..2939701 100644 --- a/docs/Marmot/Callback.html +++ b/docs/Marmot/Callback.html @@ -140,6 +140,13 @@

Defined in:

+ + + marmot.cr + + +
+ diff --git a/docs/Marmot/CronTask.html b/docs/Marmot/CronTask.html index cd3608d..692dcd2 100644 --- a/docs/Marmot/CronTask.html +++ b/docs/Marmot/CronTask.html @@ -132,6 +132,13 @@

Defined in:

+ + + tasks.cr + + +
+ @@ -231,6 +238,8 @@


+ [View source] +
diff --git a/docs/Marmot/OnChannelTask.html b/docs/Marmot/OnChannelTask.html index d25011c..71c696c 100644 --- a/docs/Marmot/OnChannelTask.html +++ b/docs/Marmot/OnChannelTask.html @@ -132,6 +132,13 @@

Defined in:

+ + + tasks.cr + + +
+ @@ -250,6 +257,8 @@


+ [View source] +
@@ -279,13 +288,15 @@

Gets the value received on the channel.

-

If the channel is closed while waiting, a nil value will saved here, and -the task will run one last time.

+

If the channel is closed a nil value will saved here, and the task will +run one last time.


+ [View source] +
diff --git a/docs/Marmot/RepeatTask.html b/docs/Marmot/RepeatTask.html index 5f059e8..201d4b5 100644 --- a/docs/Marmot/RepeatTask.html +++ b/docs/Marmot/RepeatTask.html @@ -132,6 +132,13 @@

Defined in:

+ + + tasks.cr + + +
+ @@ -250,6 +257,8 @@


+ [View source] +
diff --git a/docs/Marmot/Task.html b/docs/Marmot/Task.html index 52d4c02..6176b49 100644 --- a/docs/Marmot/Task.html +++ b/docs/Marmot/Task.html @@ -152,6 +152,13 @@

Defined in:

+ + + tasks.cr + + +
+ @@ -266,6 +273,8 @@


+ [View source] +
@@ -285,6 +294,8 @@


+ [View source] +
diff --git a/docs/index.html b/docs/index.html index 6ac85cc..8ee5994 100644 --- a/docs/index.html +++ b/docs/index.html @@ -134,22 +134,32 @@

require "marmot"
 
-repetitions
-
 # This task will repeat every 15 minutes.
-repeat_task = Marmot.repeat(15.minutes) { puts Time.local }
+repeat_task = Marmot.every(15.minutes) { puts Time.local }
 # This task will run every day at 15:28:43, and will cancel the previous task.
-Marmot.cron(hour: 15, minute: 28, second: 43) do
+Marmot.every(:day, hour: 15, minute: 28, second: 43) do
   puts "It is 15:28:43: #{Time.local}"
   repeat_task.cancel
 end
 
 times = 0
+channel = Channel(String).new
 # This task will run every 10 seconds and will cancel itself after 10 runs.
-Marmot.repeat(10.seconds) do |task|
+Marmot.every(10.seconds) do |task|
   times += 1
-  puts "#{times} times"
-  task.cancel if times = 10
+  channel.send("#{times} times")
+  if times == 10
+    task.cancel
+    channel.close
+  end
+end
+
+Marmot.on(channel) do |task|
+  if value = task.as(Marmot::OnChannelTask).value
+    puts value
+  else
+    puts "The task was canceled"
+  end
 end
 
 # Start the scheduler.
diff --git a/docs/index.json b/docs/index.json
index f0cfe98..19b06fa 100644
--- a/docs/index.json
+++ b/docs/index.json
@@ -1 +1 @@
-{"repository_name":"marmot","body":"# marmot\n\nMarmot is a scheduler, use it to schedule tasks.\n\nThe most detailled documentation is [the api doc](https://erdnaxeli.github.io/marmot/Marmot.html).\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     marmot:\n       github: erdnaxeli/marmot\n   ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"marmot\"\n\nrepetitions\n\n# This task will repeat every 15 minutes.\nrepeat_task = Marmot.repeat(15.minutes) { puts Time.local }\n# This task will run every day at 15:28:43, and will cancel the previous task.\nMarmot.cron(hour: 15, minute: 28, second: 43) do\n  puts \"It is 15:28:43: #{Time.local}\"\n  repeat_task.cancel\nend\n\ntimes = 0\n# This task will run every 10 seconds and will cancel itself after 10 runs.\nMarmot.repeat(10.seconds) do |task|\n  times += 1\n  puts \"#{times} times\"\n  task.cancel if times = 10\nend\n\n# Start the scheduler.\nMarmot.run\n```\n\n### Debug\n\nYou can set the env var `MARMOT_DEBUG` to any value to make marmot outputs debug logs.\n\n## Development\n\nDon't forget to run the test.\n\nAs they deal with timing, they could fail if your computer is busy.\nDo not hesitate to run then many times if that happens.\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [erdnaxeli](https://github.com/erdnaxeli) - creator and maintainer\n","program":{"html_id":"marmot/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"marmot","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"marmot/Marmot","path":"Marmot.html","kind":"module","full_name":"Marmot","name":"Marmot","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"::Log.for(self)","doc":null,"summary":null},{"id":"VERSION","name":"VERSION","value":"\"0.3.0\"","doc":null,"summary":null}],"included_modules":[],"extended_modules":[{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"}],"subclasses":[],"including_types":[],"namespace":null,"doc":"Marmot is a non concurrent scheduler.\n\nMarmot schedules tasks on three possibles ways:\n* on a periodic span (`Marmot.repeat`)\n* every day at a given time (`Marmot.cron`)\n* when a value is available on a channel (`Marmot.on`)\n\nTasks are all executed on the same fiber.\nThis means two things: first, you don't have to worry about concurrency\n(your tasks can share objects which does not support concurrency, like\n`HTTP::Client`), and second, they must not block (too much).\nIf you want to execute jobs concurrently, you must spawn a new fiber inside your\ntasks.\n\nA task receive a unique parameter which is an object representing itself.\nIt can be canceled with `Marmot::Task#cancel`, from inside or outside the task.\nA canceled task can never be started again.\n\nTasks do not start when created.\nInstead, the main entrypoint is `Marmot.run`, which blocks while there are tasks\nto run. If there is no tasks to run, or they are all canceled, it stops.\n\nThe blocking behavior can also be stopped by calling `Marmot.stop`.\nAs `Marmot.run` is blocking, you probably want to call `Marmot.stop` from a task\nor from another fiber.\n\nWhen stopped, the tasks are not canceled and they will run again if `Marmot.run`\nis called again.\nTo cancel all the tasks there is `Marmot.cancel_all_tasks`.\n\nIf the computer's clock changes, the tasks scheduled on a specific time will\n*not* be scheduled again.\nTheir next runs will be triggered at the time before the clock changes, but the\nnext ones will be correctly scheduled.","summary":"

Marmot is a non concurrent scheduler.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"at(time:Time,&block:Callback):Task-instance-method","html_id":"at(time:Time,&block:Callback):Task-instance-method","name":"at","doc":"Runs a task once at a given time.","summary":"

Runs a task once at a given time.

","abstract":false,"args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"}],"args_string":"(time : Time, &block : Callback) : Task","source_link":null,"def":{"name":"at","args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to run once at #{time}\"\nend\nadd_task(AtTask.new(time, block))\n"}},{"id":"cancel_all_tasks:Nil-instance-method","html_id":"cancel_all_tasks:Nil-instance-method","name":"cancel_all_tasks","doc":"Cancels all the tasks.","summary":"

Cancels all the tasks.

","abstract":false,"args":[],"args_string":" : Nil","source_link":null,"def":{"name":"cancel_all_tasks","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"@@tasks.each do |t|\n t.cancel\nend"}},{"id":"every(span:Time::Span,first_run=false,&block:Callback):Task-instance-method","html_id":"every(span:Time::Span,first_run=false,&block:Callback):Task-instance-method","name":"every","doc":"Runs a task every given *span*.\n\nIf first run is true, it will run as soon as the scheduler runs.\nElse it will wait *span* time before running for first time.","summary":"

Runs a task every given span.

","abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"false","external_name":"first_run","restriction":""}],"args_string":"(span : Time::Span, first_run = false, &block : Callback) : Task","source_link":null,"def":{"name":"every","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"false","external_name":"first_run","restriction":""}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to repeat every #{span}\"\nend\nadd_task(RepeatTask.new(span, first_run, block))\n"}},{"id":"every(span:Symbol,*,day=1,hour=0,minute=0,second=0,&block:Callback):Task-instance-method","html_id":"every(span:Symbol,*,day=1,hour=0,minute=0,second=0,&block:Callback):Task-instance-method","name":"every","doc":"Runs a task every *span* at the given *day*, *hour*, *minute* and *second*.\n\n```\nMarmot.every(:hour, hour: 16, minute: 30, second: 30) # will run every hour at 30:30 (the hour parameter is ignored)\nMarmot.every(:day, hour: 15) { ... } # will run every day at 15:00:00\nMarmot.every(:month, day: 15) { ... } # will run every month at midnight\nMarmot.every(:month, day: 31) { ... } # will run every month THAT HAVE a 31th day at midnight\n```","summary":"

Runs a task every span at the given day, hour, minute and second.

","abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"day","doc":null,"default_value":"1","external_name":"day","restriction":""},{"name":"hour","doc":null,"default_value":"0","external_name":"hour","restriction":""},{"name":"minute","doc":null,"default_value":"0","external_name":"minute","restriction":""},{"name":"second","doc":null,"default_value":"0","external_name":"second","restriction":""}],"args_string":"(span : Symbol, *, day = 1, hour = 0, minute = 0, second = 0, &block : Callback) : Task","source_link":null,"def":{"name":"every","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"day","doc":null,"default_value":"1","external_name":"day","restriction":""},{"name":"hour","doc":null,"default_value":"0","external_name":"hour","restriction":""},{"name":"minute","doc":null,"default_value":"0","external_name":"minute","restriction":""},{"name":"second","doc":null,"default_value":"0","external_name":"second","restriction":""}],"double_splat":null,"splat_index":1,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to run every day at #{hour}:#{minute}:#{second}\"\nend\nadd_task(CronTask.new(span, day, hour, minute, second, block))\n"}},{"id":"on(channel,&block:Callback):Task-instance-method","html_id":"on(channel,&block:Callback):Task-instance-method","name":"on","doc":"Runs a task when a value is received on a channel.\n\nTo access the value, you need to restrict the type of the task, and use\n`OnChannelTask#value`.\n\n```\nchannel = Channel(Int32).new\nMarmot.on(channel) { |task| puts task.as(OnChannelTask).value }\n```","summary":"

Runs a task when a value is received on a channel.

","abstract":false,"args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":""}],"args_string":"(channel, &block : Callback) : Task","source_link":null,"def":{"name":"on","args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":""}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to run on message on #{channel}\"\nend\nadd_task(OnChannelTask.new(channel, block))\n"}},{"id":"run:Nil-instance-method","html_id":"run:Nil-instance-method","name":"run","doc":"Starts scheduling the tasks.\n\nThis blocks until `#stop` is called or all tasks are cancelled.","summary":"

Starts scheduling the tasks.

","abstract":false,"args":[],"args_string":" : Nil","source_link":null,"def":{"name":"run","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"Log.debug do\n \"Marmot running\"\nend\n@@running = true\n@@stop_channel = Channel(Nil).new\nremove_canceled_tasks\nif @@tasks.size == 0\n Log.debug do\n \"No task to run! Stopping.\"\n end\n return\nend\n@@tasks.map(&.start)\nwhile @@running\n Log.debug do\n \"Waiting for a task to run among #{@@tasks.size} tasks\"\n end\n begin\n task = Channel.receive_first([@@stop_channel] + @@tasks.map(&.tick))\n rescue Channel::ClosedError\n end\n if task.is_a?(Task)\n Log.debug do\n \"Running task #{task}\"\n end\n task.run\n end\n remove_canceled_tasks\n if @@tasks.size == 0\n Log.debug do\n \"No remaining task to run, stopping\"\n end\n break\n end\nend\n@@running = false\n"}},{"id":"stop-instance-method","html_id":"stop-instance-method","name":"stop","doc":"Stops scheduling the tasks.","summary":"

Stops scheduling the tasks.

","abstract":false,"args":[],"args_string":"","source_link":null,"def":{"name":"stop","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @@running\n Log.debug do\n \"Marmot stopped\"\n end\n @@running = false\n @@stop_channel.close\nend"}}],"macros":[],"types":[{"html_id":"marmot/Marmot/AtTask","path":"Marmot/AtTask.html","kind":"class","full_name":"Marmot::AtTask","name":"AtTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"Task::Log.for(self, Task::Log.level)","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(time:Time,callback:Callback)-class-method","html_id":"new(time:Time,callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(time : Time, callback : Callback)","source_link":null,"def":{"name":"new","args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(time, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/Callback","path":"Marmot/Callback.html","kind":"alias","full_name":"Marmot::Callback","name":"Callback","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":true,"aliased":"Proc(Marmot::Task, Nil)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/CronTask","path":"Marmot/CronTask.html","kind":"class","full_name":"Marmot::CronTask","name":"CronTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(span:Symbol,day:Int32,hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method","html_id":"new(span:Symbol,day:Int32,hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"day","doc":null,"default_value":"","external_name":"day","restriction":"Int32"},{"name":"hour","doc":null,"default_value":"","external_name":"hour","restriction":"Int32"},{"name":"minute","doc":null,"default_value":"","external_name":"minute","restriction":"Int32"},{"name":"second","doc":null,"default_value":"","external_name":"second","restriction":"Int32"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(span : Symbol, day : Int32, hour : Int32, minute : Int32, second : Int32, callback : Callback)","source_link":null,"def":{"name":"new","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"day","doc":null,"default_value":"","external_name":"day","restriction":"Int32"},{"name":"hour","doc":null,"default_value":"","external_name":"hour","restriction":"Int32"},{"name":"minute","doc":null,"default_value":"","external_name":"minute","restriction":"Int32"},{"name":"second","doc":null,"default_value":"","external_name":"second","restriction":"Int32"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(span, day, hour, minute, second, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/OnChannelTask","path":"Marmot/OnChannelTask.html","kind":"class","full_name":"Marmot::OnChannelTask(T)","name":"OnChannelTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(channel:Channel(T),callback:Callback)-class-method","html_id":"new(channel:Channel(T),callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":"Channel(T)"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(channel : Channel(T), callback : Callback)","source_link":null,"def":{"name":"new","args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":"Channel(T)"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = OnChannelTask(T).allocate\n_.initialize(channel, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"value:T?-instance-method","html_id":"value:T?-instance-method","name":"value","doc":"Gets the value received on the channel.\n\nIf the channel is closed while waiting, a `nil` value will saved here, and\nthe task will run one last time.","summary":"

Gets the value received on the channel.

","abstract":false,"args":[],"args_string":" : T?","source_link":null,"def":{"name":"value","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"T | ::Nil","visibility":"Public","body":"@value"}}],"macros":[],"types":[]},{"html_id":"marmot/Marmot/RepeatTask","path":"Marmot/RepeatTask.html","kind":"class","full_name":"Marmot::RepeatTask","name":"RepeatTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"Task::Log.for(self, Task::Log.level)","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(span:Time::Span,first_run:Bool,callback:Callback)-class-method","html_id":"new(span:Time::Span,first_run:Bool,callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"","external_name":"first_run","restriction":"Bool"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(span : Time::Span, first_run : Bool, callback : Callback)","source_link":null,"def":{"name":"new","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"","external_name":"first_run","restriction":"Bool"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(span, first_run, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/Task","path":"Marmot/Task.html","kind":"class","full_name":"Marmot::Task","name":"Task","abstract":true,"superclass":{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"Marmot::Log.for(self, Marmot::Log.level)","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"marmot/Marmot/AtTask","kind":"class","full_name":"Marmot::AtTask","name":"AtTask"},{"html_id":"marmot/Marmot/CronTask","kind":"class","full_name":"Marmot::CronTask","name":"CronTask"},{"html_id":"marmot/Marmot/OnChannelTask","kind":"class","full_name":"Marmot::OnChannelTask(T)","name":"OnChannelTask"},{"html_id":"marmot/Marmot/RepeatTask","kind":"class","full_name":"Marmot::RepeatTask","name":"RepeatTask"}],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[{"id":"cancel-instance-method","html_id":"cancel-instance-method","name":"cancel","doc":"Cancels the task.\n\nA canceled task cannot be uncanceled.","summary":"

Cancels the task.

","abstract":false,"args":[],"args_string":"","source_link":null,"def":{"name":"cancel","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Log.debug do\n \"Task #{self} canceled\"\nend\n@canceled = true\n"}},{"id":"canceled?:Bool-instance-method","html_id":"canceled?:Bool-instance-method","name":"canceled?","doc":"Returns true if the task is canceled.","summary":"

Returns true if the task is canceled.

","abstract":false,"args":[],"args_string":" : Bool","source_link":null,"def":{"name":"canceled?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@canceled"}}],"macros":[],"types":[]}]}]}} \ No newline at end of file +{"repository_name":"marmot","body":"# marmot\n\nMarmot is a scheduler, use it to schedule tasks.\n\nThe most detailled documentation is [the api doc](https://erdnaxeli.github.io/marmot/Marmot.html).\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n ```yaml\n dependencies:\n marmot:\n github: erdnaxeli/marmot\n ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"marmot\"\n\n# This task will repeat every 15 minutes.\nrepeat_task = Marmot.every(15.minutes) { puts Time.local }\n# This task will run every day at 15:28:43, and will cancel the previous task.\nMarmot.every(:day, hour: 15, minute: 28, second: 43) do\n puts \"It is 15:28:43: #{Time.local}\"\n repeat_task.cancel\nend\n\ntimes = 0\nchannel = Channel(String).new\n# This task will run every 10 seconds and will cancel itself after 10 runs.\nMarmot.every(10.seconds) do |task|\n times += 1\n channel.send(\"#{times} times\")\n if times == 10\n task.cancel\n channel.close\n end\nend\n\nMarmot.on(channel) do |task|\n if value = task.as(Marmot::OnChannelTask).value\n puts value\n else\n puts \"The task was canceled\"\n end\nend\n\n# Start the scheduler.\nMarmot.run\n```\n\n### Debug\n\nYou can set the env var `MARMOT_DEBUG` to any value to make marmot outputs debug logs.\n\n## Development\n\nDon't forget to run the test.\n\nAs they deal with timing, they could fail if your computer is busy.\nDo not hesitate to run then many times if that happens.\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [erdnaxeli](https://github.com/erdnaxeli) - creator and maintainer\n","program":{"html_id":"marmot/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"marmot","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"marmot/Marmot","path":"Marmot.html","kind":"module","full_name":"Marmot","name":"Marmot","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/log.cr","line_number":1,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/log.cr#L1"},{"filename":"src/marmot.cr","line_number":40,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L40"},{"filename":"src/tasks.cr","line_number":3,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L3"}],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"::Log.for(self)","doc":null,"summary":null},{"id":"VERSION","name":"VERSION","value":"\"0.3.0\"","doc":null,"summary":null}],"included_modules":[],"extended_modules":[{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"}],"subclasses":[],"including_types":[],"namespace":null,"doc":"Marmot is a non concurrent scheduler.\n\nMarmot schedules tasks on three possibles ways:\n* on a periodic span (`Marmot.repeat`)\n* every day at a given time (`Marmot.cron`)\n* when a value is available on a channel (`Marmot.on`)\n\nTasks are all executed on the same fiber.\nThis means two things: first, you don't have to worry about concurrency\n(your tasks can share objects which does not support concurrency, like\n`HTTP::Client`), and second, they must not block (too much).\nIf you want to execute jobs concurrently, you must spawn a new fiber inside your\ntasks.\n\nA task receive a unique parameter which is an object representing itself.\nIt can be canceled with `Marmot::Task#cancel`, from inside or outside the task.\nA canceled task can never be started again.\n\nTasks do not start when created.\nInstead, the main entrypoint is `Marmot.run`, which blocks while there are tasks\nto run. If there is no tasks to run, or they are all canceled, it stops.\n\nThe blocking behavior can also be stopped by calling `Marmot.stop`.\nAs `Marmot.run` is blocking, you probably want to call `Marmot.stop` from a task\nor from another fiber.\n\nWhen stopped, the tasks are not canceled and they will run again if `Marmot.run`\nis called again.\nTo cancel all the tasks there is `Marmot.cancel_all_tasks`.\n\nIf the computer's clock changes, the tasks scheduled on a specific time will\n*not* be scheduled again.\nTheir next runs will be triggered at the time before the clock changes, but the\nnext ones will be correctly scheduled.","summary":"

Marmot is a non concurrent scheduler.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"at(time:Time,&block:Callback):Task-instance-method","html_id":"at(time:Time,&block:Callback):Task-instance-method","name":"at","doc":"Runs a task once at a given time.","summary":"

Runs a task once at a given time.

","abstract":false,"args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"}],"args_string":"(time : Time, &block : Callback) : Task","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L61","def":{"name":"at","args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to run once at #{time}\"\nend\nadd_task(AtTask.new(time, block))\n"}},{"id":"cancel_all_tasks:Nil-instance-method","html_id":"cancel_all_tasks:Nil-instance-method","name":"cancel_all_tasks","doc":"Cancels all the tasks.","summary":"

Cancels all the tasks.

","abstract":false,"args":[],"args_string":" : Nil","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L103","def":{"name":"cancel_all_tasks","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"@@tasks.each do |t|\n t.cancel\nend"}},{"id":"every(span:Time::Span,first_run=false,&block:Callback):Task-instance-method","html_id":"every(span:Time::Span,first_run=false,&block:Callback):Task-instance-method","name":"every","doc":"Runs a task every given *span*.\n\nIf first run is true, it will run as soon as the scheduler runs.\nElse it will wait *span* time before running for first time.","summary":"

Runs a task every given span.

","abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"false","external_name":"first_run","restriction":""}],"args_string":"(span : Time::Span, first_run = false, &block : Callback) : Task","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L70","def":{"name":"every","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"false","external_name":"first_run","restriction":""}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to repeat every #{span}\"\nend\nadd_task(RepeatTask.new(span, first_run, block))\n"}},{"id":"every(span:Symbol,*,day=1,hour=0,minute=0,second=0,&block:Callback):Task-instance-method","html_id":"every(span:Symbol,*,day=1,hour=0,minute=0,second=0,&block:Callback):Task-instance-method","name":"every","doc":"Runs a task every *span* at the given *day*, *hour*, *minute* and *second*.\n\n```\nMarmot.every(:hour, hour: 16, minute: 30, second: 30) # will run every hour at 30:30 (the hour parameter is ignored)\nMarmot.every(:day, hour: 15) { ... } # will run every day at 15:00:00\nMarmot.every(:month, day: 15) { ... } # will run every month at midnight\nMarmot.every(:month, day: 31) { ... } # will run every month THAT HAVE a 31th day at midnight\n```","summary":"

Runs a task every span at the given day, hour, minute and second.

","abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"day","doc":null,"default_value":"1","external_name":"day","restriction":""},{"name":"hour","doc":null,"default_value":"0","external_name":"hour","restriction":""},{"name":"minute","doc":null,"default_value":"0","external_name":"minute","restriction":""},{"name":"second","doc":null,"default_value":"0","external_name":"second","restriction":""}],"args_string":"(span : Symbol, *, day = 1, hour = 0, minute = 0, second = 0, &block : Callback) : Task","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L83","def":{"name":"every","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"day","doc":null,"default_value":"1","external_name":"day","restriction":""},{"name":"hour","doc":null,"default_value":"0","external_name":"hour","restriction":""},{"name":"minute","doc":null,"default_value":"0","external_name":"minute","restriction":""},{"name":"second","doc":null,"default_value":"0","external_name":"second","restriction":""}],"double_splat":null,"splat_index":1,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to run every #{span} at #{hour}:#{minute}:#{second}\"\nend\nadd_task(CronTask.new(span, day, hour, minute, second, block))\n"}},{"id":"on(channel,&block:Callback):Task-instance-method","html_id":"on(channel,&block:Callback):Task-instance-method","name":"on","doc":"Runs a task when a value is received on a channel.\n\nTo access the value, you need to restrict the type of the task, and use\n`OnChannelTask#value`.\n\n```\nchannel = Channel(Int32).new\nMarmot.on(channel) { |task| puts task.as(OnChannelTask).value }\n```","summary":"

Runs a task when a value is received on a channel.

","abstract":false,"args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":""}],"args_string":"(channel, &block : Callback) : Task","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L97","def":{"name":"on","args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":""}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to run on message on #{channel}\"\nend\nadd_task(OnChannelTask.new(channel, block))\n"}},{"id":"run:Nil-instance-method","html_id":"run:Nil-instance-method","name":"run","doc":"Starts scheduling the tasks.\n\nThis blocks until `#stop` is called or all tasks are cancelled.","summary":"

Starts scheduling the tasks.

","abstract":false,"args":[],"args_string":" : Nil","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L110","def":{"name":"run","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"Log.debug do\n \"Marmot running\"\nend\n@@running = true\n@@stop_channel = Channel(Nil).new\nremove_canceled_tasks\nif @@tasks.size == 0\n Log.debug do\n \"No task to run! Stopping.\"\n end\n return\nend\n@@tasks.map(&.start)\nwhile @@running\n Log.debug do\n \"Waiting for a task to run among #{@@tasks.size} tasks\"\n end\n begin\n task = Channel.receive_first([@@stop_channel] + @@tasks.map(&.tick))\n rescue Channel::ClosedError\n remove_canceled_tasks\n next\n end\n if task.is_a?(Task)\n Log.debug do\n \"Running task #{task}\"\n end\n task.run\n end\n remove_canceled_tasks\n if @@tasks.size == 0\n Log.debug do\n \"No remaining task to run, stopping\"\n end\n break\n end\nend\n@@running = false\n"}},{"id":"stop-instance-method","html_id":"stop-instance-method","name":"stop","doc":"Stops scheduling the tasks.","summary":"

Stops scheduling the tasks.

","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L149","def":{"name":"stop","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @@running\n Log.debug do\n \"Marmot stopped\"\n end\n @@running = false\n @@stop_channel.close\nend"}}],"macros":[],"types":[{"html_id":"marmot/Marmot/AtTask","path":"Marmot/AtTask.html","kind":"class","full_name":"Marmot::AtTask","name":"AtTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/tasks.cr","line_number":50,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L50"}],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"Task::Log.for(self, Task::Log.level)","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(time:Time,callback:Callback)-class-method","html_id":"new(time:Time,callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(time : Time, callback : Callback)","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L53","def":{"name":"new","args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(time, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/Callback","path":"Marmot/Callback.html","kind":"alias","full_name":"Marmot::Callback","name":"Callback","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/marmot.cr","line_number":43,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L43"}],"repository_name":"marmot","program":false,"enum":false,"alias":true,"aliased":"Proc(Marmot::Task, Nil)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/CronTask","path":"Marmot/CronTask.html","kind":"class","full_name":"Marmot::CronTask","name":"CronTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/tasks.cr","line_number":67,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L67"}],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(span:Symbol,day:Int32,hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method","html_id":"new(span:Symbol,day:Int32,hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"day","doc":null,"default_value":"","external_name":"day","restriction":"Int32"},{"name":"hour","doc":null,"default_value":"","external_name":"hour","restriction":"Int32"},{"name":"minute","doc":null,"default_value":"","external_name":"minute","restriction":"Int32"},{"name":"second","doc":null,"default_value":"","external_name":"second","restriction":"Int32"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(span : Symbol, day : Int32, hour : Int32, minute : Int32, second : Int32, callback : Callback)","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L68","def":{"name":"new","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"day","doc":null,"default_value":"","external_name":"day","restriction":"Int32"},{"name":"hour","doc":null,"default_value":"","external_name":"hour","restriction":"Int32"},{"name":"minute","doc":null,"default_value":"","external_name":"minute","restriction":"Int32"},{"name":"second","doc":null,"default_value":"","external_name":"second","restriction":"Int32"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(span, day, hour, minute, second, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/OnChannelTask","path":"Marmot/OnChannelTask.html","kind":"class","full_name":"Marmot::OnChannelTask(T)","name":"OnChannelTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/tasks.cr","line_number":145,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L145"}],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(channel:Channel(T),callback:Callback)-class-method","html_id":"new(channel:Channel(T),callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":"Channel(T)"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(channel : Channel(T), callback : Callback)","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L155","def":{"name":"new","args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":"Channel(T)"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = OnChannelTask(T).allocate\n_.initialize(channel, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"value:T?-instance-method","html_id":"value:T?-instance-method","name":"value","doc":"Gets the value received on the channel.\n\nIf the channel is closed a `nil` value will saved here, and the task will\nrun one last time.","summary":"

Gets the value received on the channel.

","abstract":false,"args":[],"args_string":" : T?","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L153","def":{"name":"value","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"T | ::Nil","visibility":"Public","body":"@value"}}],"macros":[],"types":[]},{"html_id":"marmot/Marmot/RepeatTask","path":"Marmot/RepeatTask.html","kind":"class","full_name":"Marmot::RepeatTask","name":"RepeatTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/tasks.cr","line_number":186,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L186"}],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"Task::Log.for(self, Task::Log.level)","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(span:Time::Span,first_run:Bool,callback:Callback)-class-method","html_id":"new(span:Time::Span,first_run:Bool,callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"","external_name":"first_run","restriction":"Bool"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(span : Time::Span, first_run : Bool, callback : Callback)","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L189","def":{"name":"new","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"","external_name":"first_run","restriction":"Bool"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(span, first_run, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/Task","path":"Marmot/Task.html","kind":"class","full_name":"Marmot::Task","name":"Task","abstract":true,"superclass":{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/tasks.cr","line_number":4,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L4"}],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"Marmot::Log.for(self, Marmot::Log.level)","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"marmot/Marmot/AtTask","kind":"class","full_name":"Marmot::AtTask","name":"AtTask"},{"html_id":"marmot/Marmot/CronTask","kind":"class","full_name":"Marmot::CronTask","name":"CronTask"},{"html_id":"marmot/Marmot/OnChannelTask","kind":"class","full_name":"Marmot::OnChannelTask(T)","name":"OnChannelTask"},{"html_id":"marmot/Marmot/RepeatTask","kind":"class","full_name":"Marmot::RepeatTask","name":"RepeatTask"}],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[{"id":"cancel-instance-method","html_id":"cancel-instance-method","name":"cancel","doc":"Cancels the task.\n\nA canceled task cannot be uncanceled.","summary":"

Cancels the task.

","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L15","def":{"name":"cancel","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Log.debug do\n \"Task #{self} canceled\"\nend\n@canceled = true\n"}},{"id":"canceled?:Bool-instance-method","html_id":"canceled?:Bool-instance-method","name":"canceled?","doc":"Returns true if the task is canceled.","summary":"

Returns true if the task is canceled.

","abstract":false,"args":[],"args_string":" : Bool","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L21","def":{"name":"canceled?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@canceled"}}],"macros":[],"types":[]}]}]}} \ No newline at end of file diff --git a/docs/search-index.js b/docs/search-index.js index 99e5311..d3e9141 100644 --- a/docs/search-index.js +++ b/docs/search-index.js @@ -1 +1 @@ -crystal_doc_search_index_callback({"repository_name":"marmot","body":"# marmot\n\nMarmot is a scheduler, use it to schedule tasks.\n\nThe most detailled documentation is [the api doc](https://erdnaxeli.github.io/marmot/Marmot.html).\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n ```yaml\n dependencies:\n marmot:\n github: erdnaxeli/marmot\n ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"marmot\"\n\nrepetitions\n\n# This task will repeat every 15 minutes.\nrepeat_task = Marmot.repeat(15.minutes) { puts Time.local }\n# This task will run every day at 15:28:43, and will cancel the previous task.\nMarmot.cron(hour: 15, minute: 28, second: 43) do\n puts \"It is 15:28:43: #{Time.local}\"\n repeat_task.cancel\nend\n\ntimes = 0\n# This task will run every 10 seconds and will cancel itself after 10 runs.\nMarmot.repeat(10.seconds) do |task|\n times += 1\n puts \"#{times} times\"\n task.cancel if times = 10\nend\n\n# Start the scheduler.\nMarmot.run\n```\n\n### Debug\n\nYou can set the env var `MARMOT_DEBUG` to any value to make marmot outputs debug logs.\n\n## Development\n\nDon't forget to run the test.\n\nAs they deal with timing, they could fail if your computer is busy.\nDo not hesitate to run then many times if that happens.\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [erdnaxeli](https://github.com/erdnaxeli) - creator and maintainer\n","program":{"html_id":"marmot/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"marmot","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"marmot/Marmot","path":"Marmot.html","kind":"module","full_name":"Marmot","name":"Marmot","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"::Log.for(self)","doc":null,"summary":null},{"id":"VERSION","name":"VERSION","value":"\"0.3.0\"","doc":null,"summary":null}],"included_modules":[],"extended_modules":[{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"}],"subclasses":[],"including_types":[],"namespace":null,"doc":"Marmot is a non concurrent scheduler.\n\nMarmot schedules tasks on three possibles ways:\n* on a periodic span (`Marmot.repeat`)\n* every day at a given time (`Marmot.cron`)\n* when a value is available on a channel (`Marmot.on`)\n\nTasks are all executed on the same fiber.\nThis means two things: first, you don't have to worry about concurrency\n(your tasks can share objects which does not support concurrency, like\n`HTTP::Client`), and second, they must not block (too much).\nIf you want to execute jobs concurrently, you must spawn a new fiber inside your\ntasks.\n\nA task receive a unique parameter which is an object representing itself.\nIt can be canceled with `Marmot::Task#cancel`, from inside or outside the task.\nA canceled task can never be started again.\n\nTasks do not start when created.\nInstead, the main entrypoint is `Marmot.run`, which blocks while there are tasks\nto run. If there is no tasks to run, or they are all canceled, it stops.\n\nThe blocking behavior can also be stopped by calling `Marmot.stop`.\nAs `Marmot.run` is blocking, you probably want to call `Marmot.stop` from a task\nor from another fiber.\n\nWhen stopped, the tasks are not canceled and they will run again if `Marmot.run`\nis called again.\nTo cancel all the tasks there is `Marmot.cancel_all_tasks`.\n\nIf the computer's clock changes, the tasks scheduled on a specific time will\n*not* be scheduled again.\nTheir next runs will be triggered at the time before the clock changes, but the\nnext ones will be correctly scheduled.","summary":"

Marmot is a non concurrent scheduler.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"at(time:Time,&block:Callback):Task-instance-method","html_id":"at(time:Time,&block:Callback):Task-instance-method","name":"at","doc":"Runs a task once at a given time.","summary":"

Runs a task once at a given time.

","abstract":false,"args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"}],"args_string":"(time : Time, &block : Callback) : Task","source_link":null,"def":{"name":"at","args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to run once at #{time}\"\nend\nadd_task(AtTask.new(time, block))\n"}},{"id":"cancel_all_tasks:Nil-instance-method","html_id":"cancel_all_tasks:Nil-instance-method","name":"cancel_all_tasks","doc":"Cancels all the tasks.","summary":"

Cancels all the tasks.

","abstract":false,"args":[],"args_string":" : Nil","source_link":null,"def":{"name":"cancel_all_tasks","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"@@tasks.each do |t|\n t.cancel\nend"}},{"id":"every(span:Time::Span,first_run=false,&block:Callback):Task-instance-method","html_id":"every(span:Time::Span,first_run=false,&block:Callback):Task-instance-method","name":"every","doc":"Runs a task every given *span*.\n\nIf first run is true, it will run as soon as the scheduler runs.\nElse it will wait *span* time before running for first time.","summary":"

Runs a task every given span.

","abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"false","external_name":"first_run","restriction":""}],"args_string":"(span : Time::Span, first_run = false, &block : Callback) : Task","source_link":null,"def":{"name":"every","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"false","external_name":"first_run","restriction":""}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to repeat every #{span}\"\nend\nadd_task(RepeatTask.new(span, first_run, block))\n"}},{"id":"every(span:Symbol,*,day=1,hour=0,minute=0,second=0,&block:Callback):Task-instance-method","html_id":"every(span:Symbol,*,day=1,hour=0,minute=0,second=0,&block:Callback):Task-instance-method","name":"every","doc":"Runs a task every *span* at the given *day*, *hour*, *minute* and *second*.\n\n```\nMarmot.every(:hour, hour: 16, minute: 30, second: 30) # will run every hour at 30:30 (the hour parameter is ignored)\nMarmot.every(:day, hour: 15) { ... } # will run every day at 15:00:00\nMarmot.every(:month, day: 15) { ... } # will run every month at midnight\nMarmot.every(:month, day: 31) { ... } # will run every month THAT HAVE a 31th day at midnight\n```","summary":"

Runs a task every span at the given day, hour, minute and second.

","abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"day","doc":null,"default_value":"1","external_name":"day","restriction":""},{"name":"hour","doc":null,"default_value":"0","external_name":"hour","restriction":""},{"name":"minute","doc":null,"default_value":"0","external_name":"minute","restriction":""},{"name":"second","doc":null,"default_value":"0","external_name":"second","restriction":""}],"args_string":"(span : Symbol, *, day = 1, hour = 0, minute = 0, second = 0, &block : Callback) : Task","source_link":null,"def":{"name":"every","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"day","doc":null,"default_value":"1","external_name":"day","restriction":""},{"name":"hour","doc":null,"default_value":"0","external_name":"hour","restriction":""},{"name":"minute","doc":null,"default_value":"0","external_name":"minute","restriction":""},{"name":"second","doc":null,"default_value":"0","external_name":"second","restriction":""}],"double_splat":null,"splat_index":1,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to run every day at #{hour}:#{minute}:#{second}\"\nend\nadd_task(CronTask.new(span, day, hour, minute, second, block))\n"}},{"id":"on(channel,&block:Callback):Task-instance-method","html_id":"on(channel,&block:Callback):Task-instance-method","name":"on","doc":"Runs a task when a value is received on a channel.\n\nTo access the value, you need to restrict the type of the task, and use\n`OnChannelTask#value`.\n\n```\nchannel = Channel(Int32).new\nMarmot.on(channel) { |task| puts task.as(OnChannelTask).value }\n```","summary":"

Runs a task when a value is received on a channel.

","abstract":false,"args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":""}],"args_string":"(channel, &block : Callback) : Task","source_link":null,"def":{"name":"on","args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":""}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to run on message on #{channel}\"\nend\nadd_task(OnChannelTask.new(channel, block))\n"}},{"id":"run:Nil-instance-method","html_id":"run:Nil-instance-method","name":"run","doc":"Starts scheduling the tasks.\n\nThis blocks until `#stop` is called or all tasks are cancelled.","summary":"

Starts scheduling the tasks.

","abstract":false,"args":[],"args_string":" : Nil","source_link":null,"def":{"name":"run","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"Log.debug do\n \"Marmot running\"\nend\n@@running = true\n@@stop_channel = Channel(Nil).new\nremove_canceled_tasks\nif @@tasks.size == 0\n Log.debug do\n \"No task to run! Stopping.\"\n end\n return\nend\n@@tasks.map(&.start)\nwhile @@running\n Log.debug do\n \"Waiting for a task to run among #{@@tasks.size} tasks\"\n end\n begin\n task = Channel.receive_first([@@stop_channel] + @@tasks.map(&.tick))\n rescue Channel::ClosedError\n end\n if task.is_a?(Task)\n Log.debug do\n \"Running task #{task}\"\n end\n task.run\n end\n remove_canceled_tasks\n if @@tasks.size == 0\n Log.debug do\n \"No remaining task to run, stopping\"\n end\n break\n end\nend\n@@running = false\n"}},{"id":"stop-instance-method","html_id":"stop-instance-method","name":"stop","doc":"Stops scheduling the tasks.","summary":"

Stops scheduling the tasks.

","abstract":false,"args":[],"args_string":"","source_link":null,"def":{"name":"stop","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @@running\n Log.debug do\n \"Marmot stopped\"\n end\n @@running = false\n @@stop_channel.close\nend"}}],"macros":[],"types":[{"html_id":"marmot/Marmot/AtTask","path":"Marmot/AtTask.html","kind":"class","full_name":"Marmot::AtTask","name":"AtTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"Task::Log.for(self, Task::Log.level)","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(time:Time,callback:Callback)-class-method","html_id":"new(time:Time,callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(time : Time, callback : Callback)","source_link":null,"def":{"name":"new","args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(time, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/Callback","path":"Marmot/Callback.html","kind":"alias","full_name":"Marmot::Callback","name":"Callback","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":true,"aliased":"Proc(Marmot::Task, Nil)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/CronTask","path":"Marmot/CronTask.html","kind":"class","full_name":"Marmot::CronTask","name":"CronTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(span:Symbol,day:Int32,hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method","html_id":"new(span:Symbol,day:Int32,hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"day","doc":null,"default_value":"","external_name":"day","restriction":"Int32"},{"name":"hour","doc":null,"default_value":"","external_name":"hour","restriction":"Int32"},{"name":"minute","doc":null,"default_value":"","external_name":"minute","restriction":"Int32"},{"name":"second","doc":null,"default_value":"","external_name":"second","restriction":"Int32"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(span : Symbol, day : Int32, hour : Int32, minute : Int32, second : Int32, callback : Callback)","source_link":null,"def":{"name":"new","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"day","doc":null,"default_value":"","external_name":"day","restriction":"Int32"},{"name":"hour","doc":null,"default_value":"","external_name":"hour","restriction":"Int32"},{"name":"minute","doc":null,"default_value":"","external_name":"minute","restriction":"Int32"},{"name":"second","doc":null,"default_value":"","external_name":"second","restriction":"Int32"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(span, day, hour, minute, second, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/OnChannelTask","path":"Marmot/OnChannelTask.html","kind":"class","full_name":"Marmot::OnChannelTask(T)","name":"OnChannelTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(channel:Channel(T),callback:Callback)-class-method","html_id":"new(channel:Channel(T),callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":"Channel(T)"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(channel : Channel(T), callback : Callback)","source_link":null,"def":{"name":"new","args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":"Channel(T)"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = OnChannelTask(T).allocate\n_.initialize(channel, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"value:T?-instance-method","html_id":"value:T?-instance-method","name":"value","doc":"Gets the value received on the channel.\n\nIf the channel is closed while waiting, a `nil` value will saved here, and\nthe task will run one last time.","summary":"

Gets the value received on the channel.

","abstract":false,"args":[],"args_string":" : T?","source_link":null,"def":{"name":"value","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"T | ::Nil","visibility":"Public","body":"@value"}}],"macros":[],"types":[]},{"html_id":"marmot/Marmot/RepeatTask","path":"Marmot/RepeatTask.html","kind":"class","full_name":"Marmot::RepeatTask","name":"RepeatTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"Task::Log.for(self, Task::Log.level)","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(span:Time::Span,first_run:Bool,callback:Callback)-class-method","html_id":"new(span:Time::Span,first_run:Bool,callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"","external_name":"first_run","restriction":"Bool"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(span : Time::Span, first_run : Bool, callback : Callback)","source_link":null,"def":{"name":"new","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"","external_name":"first_run","restriction":"Bool"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(span, first_run, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/Task","path":"Marmot/Task.html","kind":"class","full_name":"Marmot::Task","name":"Task","abstract":true,"superclass":{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"Marmot::Log.for(self, Marmot::Log.level)","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"marmot/Marmot/AtTask","kind":"class","full_name":"Marmot::AtTask","name":"AtTask"},{"html_id":"marmot/Marmot/CronTask","kind":"class","full_name":"Marmot::CronTask","name":"CronTask"},{"html_id":"marmot/Marmot/OnChannelTask","kind":"class","full_name":"Marmot::OnChannelTask(T)","name":"OnChannelTask"},{"html_id":"marmot/Marmot/RepeatTask","kind":"class","full_name":"Marmot::RepeatTask","name":"RepeatTask"}],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[{"id":"cancel-instance-method","html_id":"cancel-instance-method","name":"cancel","doc":"Cancels the task.\n\nA canceled task cannot be uncanceled.","summary":"

Cancels the task.

","abstract":false,"args":[],"args_string":"","source_link":null,"def":{"name":"cancel","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Log.debug do\n \"Task #{self} canceled\"\nend\n@canceled = true\n"}},{"id":"canceled?:Bool-instance-method","html_id":"canceled?:Bool-instance-method","name":"canceled?","doc":"Returns true if the task is canceled.","summary":"

Returns true if the task is canceled.

","abstract":false,"args":[],"args_string":" : Bool","source_link":null,"def":{"name":"canceled?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@canceled"}}],"macros":[],"types":[]}]}]}}) \ No newline at end of file +crystal_doc_search_index_callback({"repository_name":"marmot","body":"# marmot\n\nMarmot is a scheduler, use it to schedule tasks.\n\nThe most detailled documentation is [the api doc](https://erdnaxeli.github.io/marmot/Marmot.html).\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n ```yaml\n dependencies:\n marmot:\n github: erdnaxeli/marmot\n ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"marmot\"\n\n# This task will repeat every 15 minutes.\nrepeat_task = Marmot.every(15.minutes) { puts Time.local }\n# This task will run every day at 15:28:43, and will cancel the previous task.\nMarmot.every(:day, hour: 15, minute: 28, second: 43) do\n puts \"It is 15:28:43: #{Time.local}\"\n repeat_task.cancel\nend\n\ntimes = 0\nchannel = Channel(String).new\n# This task will run every 10 seconds and will cancel itself after 10 runs.\nMarmot.every(10.seconds) do |task|\n times += 1\n channel.send(\"#{times} times\")\n if times == 10\n task.cancel\n channel.close\n end\nend\n\nMarmot.on(channel) do |task|\n if value = task.as(Marmot::OnChannelTask).value\n puts value\n else\n puts \"The task was canceled\"\n end\nend\n\n# Start the scheduler.\nMarmot.run\n```\n\n### Debug\n\nYou can set the env var `MARMOT_DEBUG` to any value to make marmot outputs debug logs.\n\n## Development\n\nDon't forget to run the test.\n\nAs they deal with timing, they could fail if your computer is busy.\nDo not hesitate to run then many times if that happens.\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [erdnaxeli](https://github.com/erdnaxeli) - creator and maintainer\n","program":{"html_id":"marmot/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"marmot","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"marmot/Marmot","path":"Marmot.html","kind":"module","full_name":"Marmot","name":"Marmot","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/log.cr","line_number":1,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/log.cr#L1"},{"filename":"src/marmot.cr","line_number":40,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L40"},{"filename":"src/tasks.cr","line_number":3,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L3"}],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"::Log.for(self)","doc":null,"summary":null},{"id":"VERSION","name":"VERSION","value":"\"0.3.0\"","doc":null,"summary":null}],"included_modules":[],"extended_modules":[{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"}],"subclasses":[],"including_types":[],"namespace":null,"doc":"Marmot is a non concurrent scheduler.\n\nMarmot schedules tasks on three possibles ways:\n* on a periodic span (`Marmot.repeat`)\n* every day at a given time (`Marmot.cron`)\n* when a value is available on a channel (`Marmot.on`)\n\nTasks are all executed on the same fiber.\nThis means two things: first, you don't have to worry about concurrency\n(your tasks can share objects which does not support concurrency, like\n`HTTP::Client`), and second, they must not block (too much).\nIf you want to execute jobs concurrently, you must spawn a new fiber inside your\ntasks.\n\nA task receive a unique parameter which is an object representing itself.\nIt can be canceled with `Marmot::Task#cancel`, from inside or outside the task.\nA canceled task can never be started again.\n\nTasks do not start when created.\nInstead, the main entrypoint is `Marmot.run`, which blocks while there are tasks\nto run. If there is no tasks to run, or they are all canceled, it stops.\n\nThe blocking behavior can also be stopped by calling `Marmot.stop`.\nAs `Marmot.run` is blocking, you probably want to call `Marmot.stop` from a task\nor from another fiber.\n\nWhen stopped, the tasks are not canceled and they will run again if `Marmot.run`\nis called again.\nTo cancel all the tasks there is `Marmot.cancel_all_tasks`.\n\nIf the computer's clock changes, the tasks scheduled on a specific time will\n*not* be scheduled again.\nTheir next runs will be triggered at the time before the clock changes, but the\nnext ones will be correctly scheduled.","summary":"

Marmot is a non concurrent scheduler.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"at(time:Time,&block:Callback):Task-instance-method","html_id":"at(time:Time,&block:Callback):Task-instance-method","name":"at","doc":"Runs a task once at a given time.","summary":"

Runs a task once at a given time.

","abstract":false,"args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"}],"args_string":"(time : Time, &block : Callback) : Task","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L61","def":{"name":"at","args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to run once at #{time}\"\nend\nadd_task(AtTask.new(time, block))\n"}},{"id":"cancel_all_tasks:Nil-instance-method","html_id":"cancel_all_tasks:Nil-instance-method","name":"cancel_all_tasks","doc":"Cancels all the tasks.","summary":"

Cancels all the tasks.

","abstract":false,"args":[],"args_string":" : Nil","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L103","def":{"name":"cancel_all_tasks","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"@@tasks.each do |t|\n t.cancel\nend"}},{"id":"every(span:Time::Span,first_run=false,&block:Callback):Task-instance-method","html_id":"every(span:Time::Span,first_run=false,&block:Callback):Task-instance-method","name":"every","doc":"Runs a task every given *span*.\n\nIf first run is true, it will run as soon as the scheduler runs.\nElse it will wait *span* time before running for first time.","summary":"

Runs a task every given span.

","abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"false","external_name":"first_run","restriction":""}],"args_string":"(span : Time::Span, first_run = false, &block : Callback) : Task","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L70","def":{"name":"every","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"false","external_name":"first_run","restriction":""}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to repeat every #{span}\"\nend\nadd_task(RepeatTask.new(span, first_run, block))\n"}},{"id":"every(span:Symbol,*,day=1,hour=0,minute=0,second=0,&block:Callback):Task-instance-method","html_id":"every(span:Symbol,*,day=1,hour=0,minute=0,second=0,&block:Callback):Task-instance-method","name":"every","doc":"Runs a task every *span* at the given *day*, *hour*, *minute* and *second*.\n\n```\nMarmot.every(:hour, hour: 16, minute: 30, second: 30) # will run every hour at 30:30 (the hour parameter is ignored)\nMarmot.every(:day, hour: 15) { ... } # will run every day at 15:00:00\nMarmot.every(:month, day: 15) { ... } # will run every month at midnight\nMarmot.every(:month, day: 31) { ... } # will run every month THAT HAVE a 31th day at midnight\n```","summary":"

Runs a task every span at the given day, hour, minute and second.

","abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"day","doc":null,"default_value":"1","external_name":"day","restriction":""},{"name":"hour","doc":null,"default_value":"0","external_name":"hour","restriction":""},{"name":"minute","doc":null,"default_value":"0","external_name":"minute","restriction":""},{"name":"second","doc":null,"default_value":"0","external_name":"second","restriction":""}],"args_string":"(span : Symbol, *, day = 1, hour = 0, minute = 0, second = 0, &block : Callback) : Task","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L83","def":{"name":"every","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"day","doc":null,"default_value":"1","external_name":"day","restriction":""},{"name":"hour","doc":null,"default_value":"0","external_name":"hour","restriction":""},{"name":"minute","doc":null,"default_value":"0","external_name":"minute","restriction":""},{"name":"second","doc":null,"default_value":"0","external_name":"second","restriction":""}],"double_splat":null,"splat_index":1,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to run every #{span} at #{hour}:#{minute}:#{second}\"\nend\nadd_task(CronTask.new(span, day, hour, minute, second, block))\n"}},{"id":"on(channel,&block:Callback):Task-instance-method","html_id":"on(channel,&block:Callback):Task-instance-method","name":"on","doc":"Runs a task when a value is received on a channel.\n\nTo access the value, you need to restrict the type of the task, and use\n`OnChannelTask#value`.\n\n```\nchannel = Channel(Int32).new\nMarmot.on(channel) { |task| puts task.as(OnChannelTask).value }\n```","summary":"

Runs a task when a value is received on a channel.

","abstract":false,"args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":""}],"args_string":"(channel, &block : Callback) : Task","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L97","def":{"name":"on","args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":""}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"Callback"},"return_type":"Task","visibility":"Public","body":"Log.debug do\n \"New task to run on message on #{channel}\"\nend\nadd_task(OnChannelTask.new(channel, block))\n"}},{"id":"run:Nil-instance-method","html_id":"run:Nil-instance-method","name":"run","doc":"Starts scheduling the tasks.\n\nThis blocks until `#stop` is called or all tasks are cancelled.","summary":"

Starts scheduling the tasks.

","abstract":false,"args":[],"args_string":" : Nil","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L110","def":{"name":"run","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"Log.debug do\n \"Marmot running\"\nend\n@@running = true\n@@stop_channel = Channel(Nil).new\nremove_canceled_tasks\nif @@tasks.size == 0\n Log.debug do\n \"No task to run! Stopping.\"\n end\n return\nend\n@@tasks.map(&.start)\nwhile @@running\n Log.debug do\n \"Waiting for a task to run among #{@@tasks.size} tasks\"\n end\n begin\n task = Channel.receive_first([@@stop_channel] + @@tasks.map(&.tick))\n rescue Channel::ClosedError\n remove_canceled_tasks\n next\n end\n if task.is_a?(Task)\n Log.debug do\n \"Running task #{task}\"\n end\n task.run\n end\n remove_canceled_tasks\n if @@tasks.size == 0\n Log.debug do\n \"No remaining task to run, stopping\"\n end\n break\n end\nend\n@@running = false\n"}},{"id":"stop-instance-method","html_id":"stop-instance-method","name":"stop","doc":"Stops scheduling the tasks.","summary":"

Stops scheduling the tasks.

","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L149","def":{"name":"stop","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @@running\n Log.debug do\n \"Marmot stopped\"\n end\n @@running = false\n @@stop_channel.close\nend"}}],"macros":[],"types":[{"html_id":"marmot/Marmot/AtTask","path":"Marmot/AtTask.html","kind":"class","full_name":"Marmot::AtTask","name":"AtTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/tasks.cr","line_number":50,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L50"}],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"Task::Log.for(self, Task::Log.level)","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(time:Time,callback:Callback)-class-method","html_id":"new(time:Time,callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(time : Time, callback : Callback)","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L53","def":{"name":"new","args":[{"name":"time","doc":null,"default_value":"","external_name":"time","restriction":"Time"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(time, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/Callback","path":"Marmot/Callback.html","kind":"alias","full_name":"Marmot::Callback","name":"Callback","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/marmot.cr","line_number":43,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/marmot.cr#L43"}],"repository_name":"marmot","program":false,"enum":false,"alias":true,"aliased":"Proc(Marmot::Task, Nil)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/CronTask","path":"Marmot/CronTask.html","kind":"class","full_name":"Marmot::CronTask","name":"CronTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/tasks.cr","line_number":67,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L67"}],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(span:Symbol,day:Int32,hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method","html_id":"new(span:Symbol,day:Int32,hour:Int32,minute:Int32,second:Int32,callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"day","doc":null,"default_value":"","external_name":"day","restriction":"Int32"},{"name":"hour","doc":null,"default_value":"","external_name":"hour","restriction":"Int32"},{"name":"minute","doc":null,"default_value":"","external_name":"minute","restriction":"Int32"},{"name":"second","doc":null,"default_value":"","external_name":"second","restriction":"Int32"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(span : Symbol, day : Int32, hour : Int32, minute : Int32, second : Int32, callback : Callback)","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L68","def":{"name":"new","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Symbol"},{"name":"day","doc":null,"default_value":"","external_name":"day","restriction":"Int32"},{"name":"hour","doc":null,"default_value":"","external_name":"hour","restriction":"Int32"},{"name":"minute","doc":null,"default_value":"","external_name":"minute","restriction":"Int32"},{"name":"second","doc":null,"default_value":"","external_name":"second","restriction":"Int32"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(span, day, hour, minute, second, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/OnChannelTask","path":"Marmot/OnChannelTask.html","kind":"class","full_name":"Marmot::OnChannelTask(T)","name":"OnChannelTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/tasks.cr","line_number":145,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L145"}],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(channel:Channel(T),callback:Callback)-class-method","html_id":"new(channel:Channel(T),callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":"Channel(T)"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(channel : Channel(T), callback : Callback)","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L155","def":{"name":"new","args":[{"name":"channel","doc":null,"default_value":"","external_name":"channel","restriction":"Channel(T)"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = OnChannelTask(T).allocate\n_.initialize(channel, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"value:T?-instance-method","html_id":"value:T?-instance-method","name":"value","doc":"Gets the value received on the channel.\n\nIf the channel is closed a `nil` value will saved here, and the task will\nrun one last time.","summary":"

Gets the value received on the channel.

","abstract":false,"args":[],"args_string":" : T?","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L153","def":{"name":"value","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"T | ::Nil","visibility":"Public","body":"@value"}}],"macros":[],"types":[]},{"html_id":"marmot/Marmot/RepeatTask","path":"Marmot/RepeatTask.html","kind":"class","full_name":"Marmot::RepeatTask","name":"RepeatTask","abstract":false,"superclass":{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},"ancestors":[{"html_id":"marmot/Marmot/Task","kind":"class","full_name":"Marmot::Task","name":"Task"},{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/tasks.cr","line_number":186,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L186"}],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"Task::Log.for(self, Task::Log.level)","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(span:Time::Span,first_run:Bool,callback:Callback)-class-method","html_id":"new(span:Time::Span,first_run:Bool,callback:Callback)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"","external_name":"first_run","restriction":"Bool"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"args_string":"(span : Time::Span, first_run : Bool, callback : Callback)","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L189","def":{"name":"new","args":[{"name":"span","doc":null,"default_value":"","external_name":"span","restriction":"Time::Span"},{"name":"first_run","doc":null,"default_value":"","external_name":"first_run","restriction":"Bool"},{"name":"callback","doc":null,"default_value":"","external_name":"callback","restriction":"Callback"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(span, first_run, callback)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"marmot/Marmot/Task","path":"Marmot/Task.html","kind":"class","full_name":"Marmot::Task","name":"Task","abstract":true,"superclass":{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"marmot/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"marmot/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/tasks.cr","line_number":4,"url":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L4"}],"repository_name":"marmot","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"Log","name":"Log","value":"Marmot::Log.for(self, Marmot::Log.level)","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"marmot/Marmot/AtTask","kind":"class","full_name":"Marmot::AtTask","name":"AtTask"},{"html_id":"marmot/Marmot/CronTask","kind":"class","full_name":"Marmot::CronTask","name":"CronTask"},{"html_id":"marmot/Marmot/OnChannelTask","kind":"class","full_name":"Marmot::OnChannelTask(T)","name":"OnChannelTask"},{"html_id":"marmot/Marmot/RepeatTask","kind":"class","full_name":"Marmot::RepeatTask","name":"RepeatTask"}],"including_types":[],"namespace":{"html_id":"marmot/Marmot","kind":"module","full_name":"Marmot","name":"Marmot"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[{"id":"cancel-instance-method","html_id":"cancel-instance-method","name":"cancel","doc":"Cancels the task.\n\nA canceled task cannot be uncanceled.","summary":"

Cancels the task.

","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L15","def":{"name":"cancel","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Log.debug do\n \"Task #{self} canceled\"\nend\n@canceled = true\n"}},{"id":"canceled?:Bool-instance-method","html_id":"canceled?:Bool-instance-method","name":"canceled?","doc":"Returns true if the task is canceled.","summary":"

Returns true if the task is canceled.

","abstract":false,"args":[],"args_string":" : Bool","source_link":"https://github.com/erdnaxeli/marmot/blob/e08827ec5a6846f953410a8fc36ac3534d89d2ab/src/tasks.cr#L21","def":{"name":"canceled?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@canceled"}}],"macros":[],"types":[]}]}]}}) \ No newline at end of file diff --git a/shard.yml b/shard.yml index 3fc1474..4d81bda 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: marmot -version: 0.3.0 +version: 0.3.1 authors: - Alexandre Morignot diff --git a/src/marmot.cr b/src/marmot.cr index c53a474..f9e0b14 100644 --- a/src/marmot.cr +++ b/src/marmot.cr @@ -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.3.0" + VERSION = "0.3.1" alias Callback = Proc(Task, Nil)