soasme / nim-schedules

A Nim scheduler library that lets you kick off jobs at regular intervals.

Home Page:https://soasme.com/nim-schedules/schedules.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: ambiguous call; both scheduler.newSettings

d0rksh opened this issue · comments

hii when i try to use nim-schedules with jester it gives the below error

code

import times, asyncdispatch, schedules
import jester
scheduler mySched:
  every(seconds=1, id="sync tick"):
    echo("sync tick, seconds=1 ", now())
router myRouter:
   post "/api/deletedomain":
        resp "test"
proc main() =
  asyncCheck mySched.start()
  var jester = initJester(myrouter)
  jester.serve()

when isMainModule:
  main()

error:

ambiguous call; both scheduler.newSettings(appName: string, errorHandler: proc (fut: Future[system.void]){.closure, gcsafe.}) [proc declared in /home/user/.nimble/pkgs/schedules-0.2.0/schedules/scheduler.nim(235, 6)] and jester.newSettings(port: Port, staticDir: string, appName: string, bindAddr: string, reusePort: bool, futureErrorHandler: proc (fut: Future[system.void]){.closure, gcsafe.}) [proc declared in /home/user/.nimble/pkgs/jester-0.5.0/jester.nim(407, 6)] match for: ()

i tried to use prologue but the mySched is never called, its not printing anything

Prologue code



import prologue
import httpclient
import schedules, times, asyncdispatch

scheduler mySched:
  every(seconds=5, id="sync tick"):
    echo("hello world", now())


proc  hello*(ctx: Context) {.async.} =
  resp "<h1>Hello, Prologue!</h1>"

proc main()=
  asyncCheck mySched.start()
  let app = newApp()
  app.get("/", hello)
  app.run()

when isMainModule:
  main()

output

DEBUG Prologue is serving at http://0.0.0.0:8080 
DEBUG Starting 12 threads
commented

I think jester has introduced newSettings since the nim-schedules doc was written. Since scheduler mySched: implicitly requires newSettings from nim-schedules, not one from jester, nim compiler complains.

Re Prologue, I haven't used it. I'll test it out.

commented

I've been fighting with something like this for hours, yesterday. The initial reason being that this example is garbage.

nim-schedules/README.md

Lines 99 to 124 in ce1fe58

```nim
import times, asyncdispatch, schedules, jester
scheduler mySched:
every(seconds=1, id="sync tick"):
echo("sync tick, seconds=1 ", now())
router myRouter:
get "/":
resp "It's alive!"
proc main():
# start schedules
asyncCheck mySched.start()
# start jester
let port = paramStr(1).parseInt().Port
let settings = newSettings(port=port)
var jester = initJester(myrouter, settings=settings)
# run
jester.serve()
when isMainModule:
main()
```

Not even the syntax is correct; notice line 110.

So, after debugging jester for what seemed like forever, I found the magic line that makes schedules work, even when something else is running mainly:

  while true:
    stderr.writeLine "Master Thread"
    sleep 1_000
    try:
      asyncdispatch.poll(0) # Must be in a loop, every couple of seconds. Otherwise, scheduler won't work properly.
    except ValueError:
      continue

@d0rksh This will solve your issue with prologue.