<div dir="ltr">FWIW, the KVDB project [1] implemented both priority queues and timers (which quite flexible scheduling options), with persistence.<div><br></div><div>Example, from an Erlang Factory presentation 2013 [2]:</div><div><br></div><div>12>      kvdb_cron:create_crontab(db,    timers).</div><div>ok</div><div>13>  kvdb_cron:add(
                                                                db,timers,"{in     3       secs;   3       times}",[],kvdb_cron,testf,[]).</div><div>{ok,{q_key,<<>>,105729091563262,105729094536167}}</div><div>14></div><div>CRON!!      {{{2013,3,19},{21,38,14}},658320}</div><div>CRON!!  {{{2013,3,19},{21,38,17}},655700}</div><div>CRON!!  {{{2013,3,19},{21,38,20}},642523}<br></div><div><br></div><div>I haven't touched the code in a long time, but if there is sufficient interest, I could be persuaded to lend support. :)</div><div><br></div><div>BR,</div><div>Ulf W</div><div><br></div><div>[1] <a href="https://github.com/Feuerlabs/kvdb">https://github.com/Feuerlabs/kvdb</a></div><div>[2] <a href="http://www.erlang-factory.com/conference/SFBay2013/speakers/UlfWiger">http://www.erlang-factory.com/conference/SFBay2013/speakers/UlfWiger</a></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Den mån 13 jan. 2020 kl 16:33 skrev <a href="mailto:ludovic@demblans.com">ludovic@demblans.com</a> <<a href="mailto:ludovic@demblans.com">ludovic@demblans.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br><br>I'm looking for advice about implementing a timer queue in erlang or elixir.<br><br>Basically what I need is a queue where I can write a timestamp, a key, and a value. When the local time reaches the timestamp, I want to handle the key/value (I guess receiving a message with the key and fetch, or receiving the key/value).<br>The timer must be cancelable as the value is very small but will lead to heavy computation. I want to be able to fetch a key from outside of the process at any time and run the computation (and then cancel the scheduled computation).<br><br>This is a subset of the `timer` module. But I need to persist the data to disk and reload on application start.<br><br>I will have a tiny amount of entries : around 1000.<br><br>At the moment I have an ordered_set with `{Timestamp, UserKey} = Key` as keys, I lookup for the first key and send_after to self the `Key` with `erlang:<span style="color:rgb(51,51,51)">start_timer</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(51,51,51)">max</span><span style="color:rgb(119,119,119)">(TimeStamp</span><span style="color:rgb(119,119,119)">,</span><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(156,93,39)">1</span><span style="color:rgb(119,119,119)">),</span><span style="color:rgb(51,51,51)"> self</span><span style="color:rgb(119,119,119)">(),</span><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(119,119,119)">{</span><span style="color:rgb(156,93,39)">run_deletion</span><span style="color:rgb(119,119,119)">,</span><span style="color:rgb(51,51,51)"> Key</span><span style="color:rgb(119,119,119)">})</span>`, which returns a ref that I keep in state so I can ignore timer messages with an older ref. Everything is done inside a gen_server where I load the table from disk after init. Also I have to write the table to disk after each update because it is very important that all events are handled.<br><br>I'm about to implement cancellation but the code becomes messy as I do both table management and data management in the same module.<br><br>I wonder if there are implementations of this pattern in the community ? I could use a priority queue, but it seems to me that the implementations use a fixed list of priorities, and not arbitrary priorities (like a timestamp).<br><br>Thank you
</blockquote></div>