16 |
|
|
17 |
|
int Publisher::publish() |
18 |
|
{ |
19 |
< |
cerr << bright << green << "Publisher::publish()\n" << reset; |
19 |
> |
cerr << bright << green << "Started publisher daemon.\n" << reset; |
20 |
|
|
21 |
< |
// publish |
22 |
< |
|
23 |
< |
// while (true) |
21 |
> |
while (true) |
22 |
|
{ |
23 |
< |
// Stamp stamp; |
24 |
< |
// double next(api::GetWallTimerSeconds() + Hour(1)), now; |
23 |
> |
Stamp now, next(now + Hour(1)); |
24 |
> |
api::Thread thread(etl::Bind<0>(&Publisher::update, this)); |
25 |
> |
|
26 |
> |
next.setSeconds(0); |
27 |
> |
next.setMinutes(0); |
28 |
|
|
29 |
< |
update(); |
29 |
> |
if (Zoe::debug) cerr << "now = " << now << "\nnext = " << next << '\n'; |
30 |
> |
|
31 |
> |
while (now < next - Minute(1)) |
32 |
> |
{ |
33 |
> |
sleep(Minute(1)); |
34 |
|
|
35 |
< |
// cerr << stamp << '\n'; |
35 |
> |
now = Stamp(); |
36 |
> |
} |
37 |
|
|
38 |
< |
// do |
38 |
> |
while (now < next) |
39 |
|
{ |
40 |
< |
// sleep(Minute(1)); |
40 |
> |
sleep(1); |
41 |
|
|
42 |
< |
// now = api::GetWallTimerSeconds(); |
42 |
> |
now = Stamp(); |
43 |
|
} |
44 |
< |
// while (now < next); |
44 |
> |
|
45 |
> |
thread.Join(); |
46 |
|
} |
47 |
|
} |
48 |
|
|
49 |
< |
void Publisher::update() |
49 |
> |
int Publisher::update() |
50 |
|
{ |
51 |
< |
cerr << bright << yellow << "Publisher::update()\n" << reset; |
51 |
> |
cerr << bright << yellow << "Started updating feeds.\n" << reset; |
52 |
|
|
53 |
|
Stamp stamp; |
54 |
< |
ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host, database.user, database.password, |
55 |
< |
database.db)); |
54 |
> |
ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host, |
55 |
> |
database.user, database.password, database.db)); |
56 |
|
|
57 |
|
db->Execute("DELETE FROM messages WHERE stamp<'" + ext::String(stamp - Day(30)) + "'"); |
58 |
|
|
59 |
< |
for (std::set<Buddy>::const_iterator buddy(buddies.begin()); buddy != buddies.end(); ++buddy) |
59 |
> |
for (std::set<Buddy>::const_iterator buddy(buddies.begin()); |
60 |
> |
buddy != buddies.end(); ++buddy) |
61 |
|
{ |
62 |
|
ext::Handle<dbi::ResultSet> messages(db->Execute("SELECT stamp, message FROM messages WHERE id='" |
63 |
|
+ lexical_cast<ext::String>(buddy->getId()) + "'")); |
68 |
|
|
69 |
|
Rss rss(*buddy, messages_, stamp); |
70 |
|
Atom atom(*buddy, messages_, stamp); |
71 |
+ |
|
72 |
+ |
cerr << bright << yellow << "Updated feeds for " << blue << *buddy |
73 |
+ |
<< yellow << ".\n" << reset; |
74 |
|
} |
75 |
+ |
|
76 |
+ |
cerr << bright << yellow << "Finished updating feeds.\n" << reset; |
77 |
|
} |