[server] send a message when events happen

Currently we send msg on repo-update
This commit is contained in:
lins05 2012-09-24 20:58:40 +08:00
parent 705a73acae
commit 903724f947
4 changed files with 67 additions and 13 deletions

View File

@ -78,8 +78,20 @@ struct _SeafBranchManagerPriv {
#ifndef SEAFILE_SERVER
pthread_mutex_t db_lock;
#endif
#if defined( SEAFILE_SERVER ) && !defined( HTTP_SERVER ) && !defined( SEAFILE_MONITOR )
uint32_t cevent_id;
#endif
};
#if defined( SEAFILE_SERVER ) && !defined( HTTP_SERVER ) && !defined( SEAFILE_MONITOR )
#include "mq-mgr.h"
#include <ccnet/cevent.h>
static void publish_repo_update_event (CEvent *event, void *data);
#endif
static int open_db (SeafBranchManager *mgr);
SeafBranchManager *
@ -101,6 +113,12 @@ seaf_branch_manager_new (struct _SeafileSession *seaf)
int
seaf_branch_manager_init (SeafBranchManager *mgr)
{
#if defined( SEAFILE_SERVER ) && !defined( HTTP_SERVER ) && !defined( SEAFILE_MONITOR )
mgr->priv->cevent_id = cevent_manager_register (seaf->ev_mgr,
(cevent_handler)publish_repo_update_event,
NULL);
#endif
return open_db (mgr);
}
@ -228,7 +246,7 @@ seaf_branch_manager_update_branch (SeafBranchManager *mgr, SeafBranch *branch)
#endif
}
#ifdef SEAFILE_SERVER
#if defined( SEAFILE_SERVER ) && !defined( HTTP_SERVER ) && !defined( SEAFILE_MONITOR )
static gboolean
get_commit_id (SeafDBRow *row, void *data)
@ -242,6 +260,38 @@ get_commit_id (SeafDBRow *row, void *data)
return FALSE;
}
typedef struct {
char *repo_id;
char *commit_id;
} RepoUpdateEventData;
static void
publish_repo_update_event (CEvent *event, void *data)
{
RepoUpdateEventData *rdata = event->data;
char buf[128];
snprintf (buf, sizeof(buf), "repo-update\t%s\t%s",
rdata->repo_id, rdata->commit_id);
seaf_mq_manager_publish_event (seaf->mq_mgr, buf);
g_free (rdata->repo_id);
g_free (rdata->commit_id);
g_free (rdata);
}
static void
on_branch_updated (SeafBranchManager *mgr, SeafBranch *branch)
{
RepoUpdateEventData *rdata = g_new0 (RepoUpdateEventData, 1);
rdata->repo_id = g_strdup (branch->repo_id);
rdata->commit_id = g_strdup (branch->commit_id);
cevent_manager_add_event (seaf->ev_mgr, mgr->priv->cevent_id, rdata);
}
int
seaf_branch_manager_test_and_update_branch (SeafBranchManager *mgr,
SeafBranch *branch,
@ -278,6 +328,8 @@ seaf_branch_manager_test_and_update_branch (SeafBranchManager *mgr,
}
seaf_db_commit (trans);
on_branch_updated (mgr, branch);
return 0;
}

View File

@ -152,6 +152,17 @@ seaf_mq_manager_publish_notification (SeafMqManager *mgr,
ccnet_message_free (msg);
}
void
seaf_mq_manager_publish_event (SeafMqManager *mgr, const char *content)
{
static const char *app = "seaf_server.event";
CcnetMessage *msg = create_message (mgr, app, content, 0);
_send_message (mgr, msg);
ccnet_message_free (msg);
}
static int
heartbeat_pulse (void *vmanager)
{

View File

@ -55,4 +55,7 @@ seaf_mq_manager_publish_notification (SeafMqManager *mgr,
const char *type,
const char *content);
void
seaf_mq_manager_publish_event (SeafMqManager *mgr, const char *content);
#endif

View File

@ -502,18 +502,6 @@ seaf_repo_manager_del_repo (SeafRepoManager *mgr,
if (remove_repo_ondisk (mgr, repo->id) < 0)
return -1;
#if 0
if (pthread_rwlock_wrlock (&mgr->priv->lock) < 0) {
seaf_warning ("[repo mgr] failed to lock repo cache.\n");
return -1;
}
avl_delete (mgr->priv->repo_tree, repo);
seaf_repo_unref (repo);
pthread_rwlock_unlock (&mgr->priv->lock);
#endif
return 0;
}