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 37 by douglas, 2004-07-22T16:00:52-07:00 vs.
Revision 49 by douglas, 2004-08-19T16:44:47-07:00

# Line 11 | Line 11
11   Publisher::Publisher(const std::set<Buddy>& buddies, const Database& database, bool start) : buddies(buddies),
12          database(database), start(start)
13   {
14 <        if (start) publisher.Spawn(etl::Bind<0>(&Publisher::publish, this));
14 >        if (start) publish();
15   }
16  
17 < int Publisher::publish()
17 > void Publisher::publish()
18   {
19 <        cerr << bright << green << "Started publisher daemon.\n" << reset;
20 <
21 <        while (true)
22 <        {
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 <                if (Zoe::debug) cerr << "now = " << now << "\nnext = " << next << '\n';
30 <
31 <                while (now < next - Minute(1))
32 <                {
33 <                        sleep(Minute(1));
34 <
35 <                        now = Stamp();
36 <                }
37 <
38 <                while (now < next)
39 <                {
40 <                        sleep(1);
41 <
42 <                        now = Stamp();
43 <                }
44 <
45 <                thread.Join();
46 <        }
47 < }
48 <
49 < int Publisher::update()
50 < {
51 <        cerr << bright << yellow << "Started updating feeds.\n" << reset;
19 >        cerr << bright << yellow << "Started updating feeds at " << Stamp()
20 >                << ".\n" << reset;
21  
22          Stamp stamp;
23          ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host,
24                  database.user, database.password, database.db));
25  
26 <        db->Execute("DELETE FROM messages WHERE stamp<'" + ext::String(stamp - Day(30)) + "'");
26 >        db->Execute("DELETE FROM messages WHERE stamp<'"
27 >                + ext::String(stamp - Day(30)) + "'");
28  
29          for (std::set<Buddy>::const_iterator buddy(buddies.begin());
30                  buddy != buddies.end(); ++buddy)
31          {
32 <                ext::Handle<dbi::ResultSet> messages(db->Execute("SELECT stamp, message FROM messages WHERE id='"
32 >                ext::Handle<dbi::ResultSet> messages(db->Execute("SELECT stamp, message"
33 >                        " FROM messages WHERE id='"
34                          + lexical_cast<ext::String>(buddy->getId()) + "'"));
35                  std::vector<AwayMessage> messages_;
36  
37 <                while (messages->MoveNext()) messages_.push_back(AwayMessage(messages->GetString("message"),
37 >                while (messages->MoveNext())
38 >                        messages_.push_back(AwayMessage(messages->GetString("message"),
39                          messages->GetString("stamp")));
40  
41 <                Rss rss(*buddy, messages_, stamp);
42 <                Atom atom(*buddy, messages_, stamp);
41 >                ext::String display(buddy->getDisplay(database));
42 >                Rss rss(*buddy, display, messages_, stamp);
43 >                Atom atom(*buddy, display, messages_, stamp);
44  
45                  cerr << bright << yellow << "Updated feeds for " << blue << *buddy
46                          << yellow << ".\n" << reset;
47          }
48  
49 <        cerr << bright << yellow << "Finished updating feeds.\n" << reset;
49 >        cerr << bright << yellow << "Finished updating feeds at " << Stamp()
50 >                << ".\n" << reset;
51   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines