// PD_TRACE_DECLARE_FUNCTION ( SDB_PMDBGJOBENTPNT, "pmdBackgroundJobEntryPoint" ) INT32 pmdBackgroundJobEntryPoint( pmdEDUCB *cb, void *pData ) { SDB_ASSERT( NULL != pData, "impossible" ) ; PD_TRACE_ENTRY ( SDB_PMDBGJOBENTPNT ); rtnJobMgr *jobMgr = rtnGetJobMgr () ; pmdEDUMgr *pEDUMgr = pmdGetKRCB()->getEDUMgr() ; rtnBaseJob *job = (rtnBaseJob*)pData ; INT32 rc = SDB_OK ; BOOLEAN reuseEDU = job->reuseEDU() ; string expStr ; PD_LOG( PDINFO, "Start a background job[%s]", job->name() ) ; cb->setName( job->name() ) ; job->attachIn( cb ) ; try { pEDUMgr->activateEDU( cb ) ; rc = job->doit () ; if ( SDB_OK != rc ) { PD_LOG ( PDWARNING, "Background job[%s] do failed, rc = %d", job->name(), rc ) ; } else { PD_LOG ( PDINFO, "Background job[%s] finished", job->name() ) ; } } catch( std::exception &e ) { PD_LOG( PDERROR, "Occur exception: %s", e.what() ) ; rc = SDB_SYS ; expStr = e.what() ; } job->attachOut () ; jobMgr->_removeJob ( cb->getID(), rc ) ; if ( !reuseEDU ) { pEDUMgr->forceUserEDU( cb->getID() ) ; } if ( !expStr.empty() ) { throw pdGeneralException( rc, expStr ) ; } PD_TRACE_EXITRC ( SDB_PMDBGJOBENTPNT, rc ); return SDB_OK ; }
INT32 startOmagentJob ( OMA_TASK_TYPE taskType, INT64 taskID, const BSONObj &info, omaTaskPtr &taskPtr, void *ptr ) { INT32 rc = SDB_OK ; EDUID eduID = PMD_INVALID_EDUID ; BOOLEAN returnResult = FALSE ; _omagentJob *pJob = NULL ; _omaTask *pTask = NULL ; // get task pTask = getTaskByType( taskType, taskID ) ; if ( NULL == pTask ) { PD_LOG( PDERROR, "Unkown task type" ) ; rc = SDB_INVALIDARG ; goto error ; } { // new job omaTaskPtr myTaskPtr( pTask ) ; pJob = SDB_OSS_NEW _omagentJob( myTaskPtr, info, ptr ) ; if ( !pJob ) { PD_LOG ( PDERROR, "Failed to alloc memory for running task " "with the type[%d]", taskType ) ; rc = SDB_OOM ; goto error ; } // start job rc = rtnGetJobMgr()->startJob( pJob, RTN_JOB_MUTEX_NONE, &eduID, returnResult ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to start task with the type[%d], rc = %d", taskType, rc ) ; goto done ; } pTask->setJobInfo( eduID ) ; taskPtr = myTaskPtr ; } done: return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__PMDSTARTSYNCJOB, "pmdStartSyncJob" ) INT32 pmdStartSyncJob( EDUID *pEDUID, pmdSyncMgr *pMgr, INT32 timeout ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__PMDSTARTSYNCJOB ) ; pmdSyncJob *pJob = NULL ; pJob = SDB_OSS_NEW pmdSyncJob( pMgr, timeout ) ; if ( !pJob ) { rc = SDB_OOM ; PD_LOG( PDERROR, "Alloc cache job failed" ) ; goto error ; } rc = rtnGetJobMgr()->startJob( pJob, RTN_JOB_MUTEX_NONE, pEDUID ) ; done: PD_TRACE_EXITRC( SDB__PMDSTARTSYNCJOB, rc ) ; return rc ; error: goto done ; }