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