this should be called worker
This commit is contained in:
parent
bdba4bb60c
commit
4abe9b8ba3
|
@ -49,7 +49,7 @@ proc fromDBRow*(r: Row): Tweet =
|
|||
proc getTweetsFrom*(url: string, username: string): seq[Tweet] =
|
||||
var res = newSeq[Tweet]()
|
||||
|
||||
let body = url.getContent()
|
||||
let body = url.getContent(timeout=20_000)
|
||||
|
||||
for line in body.splitLines().items():
|
||||
if line.len > 0:
|
||||
|
@ -57,7 +57,7 @@ proc getTweetsFrom*(url: string, username: string): seq[Tweet] =
|
|||
|
||||
return res
|
||||
|
||||
proc updateTweetsOnce*() =
|
||||
proc updateTweetsOnce*() {. gcsafe .} =
|
||||
var db = open("./data/twtxt.db", nil, nil, nil)
|
||||
|
||||
var users = db.getAllRows sql"select * from users"
|
||||
|
@ -65,6 +65,7 @@ proc updateTweetsOnce*() =
|
|||
for user in users.items():
|
||||
echo "updating " & $user
|
||||
|
||||
try:
|
||||
let
|
||||
username = user[1]
|
||||
url = user[2]
|
||||
|
@ -74,11 +75,4 @@ proc updateTweetsOnce*() =
|
|||
try:
|
||||
db.exec(sql"insert into tweets values(null, ?, ?, ?);", username, tweet.date.timeInfoToTime().toSeconds().int(), tweet.message)
|
||||
except: discard
|
||||
|
||||
when isMainModule:
|
||||
while true:
|
||||
try:
|
||||
updateTweetsOnce()
|
||||
except: discard
|
||||
|
||||
sleep 300_000 # 5 minutes
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
--define:ssl
|
||||
--threads:on
|
||||
--threadAnalysis:off
|
||||
|
|
|
@ -95,8 +95,6 @@ routes:
|
|||
|
||||
db.exec(sql"insert into users values (null, ?, ?)", username, url)
|
||||
|
||||
updateTweetsOnce()
|
||||
|
||||
redirect "/users/" & username & "/0"
|
||||
except: fail()
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
import os, threadpool, twtxt
|
||||
|
||||
when isMainModule:
|
||||
while true:
|
||||
try:
|
||||
spawn updateTweetsOnce()
|
||||
except: discard
|
||||
|
||||
sleep 300_000 # 5 minutes
|
|
@ -0,0 +1,3 @@
|
|||
--define:ssl
|
||||
--threads:on
|
||||
--threadAnalysis:off
|
|
@ -5,7 +5,7 @@ author = "Christine Dodrill"
|
|||
description = "a list of twtxt hacker feeds"
|
||||
license = "MIT"
|
||||
srcDir = "src"
|
||||
bin = @["twtxtlist", "twtxt"]
|
||||
bin = @["twtxtlist", "worker"]
|
||||
|
||||
# Dependencies
|
||||
|
||||
|
@ -18,6 +18,4 @@ task db, "SQLite database prompt":
|
|||
|
||||
task run, "Run app":
|
||||
exec "nimble build"
|
||||
exec "./twtxt &"
|
||||
exec "./twtxtlist"
|
||||
exec "killall twtxt"
|
||||
|
|
Loading…
Reference in New Issue