ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/zoe/trunk/Publisher.cpp
(Generate patch)

Comparing trunk/Publisher.cpp (file contents):
Revision 34 by douglas, 2004-07-20T16:49:06-07:00 vs.
Revision 37 by douglas, 2004-07-22T16:00:52-07:00

# Line 6 | Line 6
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)
# Line 15 | Line 16 | Publisher::Publisher(const std::set<Budd
16  
17   int Publisher::publish()
18   {
19 <        cerr << bright << green << "Publisher::publish()\n" << reset;
19 <
20 <        // publish
19 >        cerr << bright << green << "Started publisher daemon.\n" << reset;
20  
21          while (true)
22          {
23 <                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 <                do
31 >                while (now < next - Minute(1))
32                  {
33                          sleep(Minute(1));
34  
35 <                        now = api::GetWallTimerSeconds();
35 >                        now = Stamp();
36                  }
37 <                while (now < next);
37 >
38 >                while (now < next)
39 >                {
40 >                        sleep(1);
41 >
42 >                        now = Stamp();
43 >                }
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()) + "'"));
# Line 55 | Line 67 | void Publisher::update()
67                          messages->GetString("stamp")));
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines