示例#1
0
 def sendFrameworkCommand(self, command, daemonArgs):
     frameworkResponse = None
     aliases = Aliases()
     try:
         fwkBus = Bus.createConfigurableBus(self.logger, self.config, 'cli')
         fwkBus.openFwChannel()
         dispatcher = CommandDispatcher(fwkBus, self.logger, daemonArgs, self.config, False)
         frameworkResponse = dispatcher.dispatch(command, aliases)
     except BusException, e:
         self.logger.error("Cannot connect to HSN2 Bus because '%s'" % e)
         raise Exception
示例#2
0
    def run(self):
        self.logger.info('Started scheduler')

        # add active schedules to scheduler
        split_re  = re.compile("\s+")
        scheduledJobs = Schedule.objects.filter( status=Schedule.ACTIVE_STATUS )

        for scheduledJob in scheduledJobs:

            if scheduledJob.scheduled_start is not None:
                schedule = { 'kwargs': { 'unScheduledJob': scheduledJob }, 'name': scheduledJob.job_name }
                
                try:
                    newJob = self.scheduler.add_date_job(self.submitJobToFramework, scheduledJob.scheduled_start, **schedule)
                except Exception as e:
                    self.logger.error("Unknown error while submitting jobs to framework: %s" % str(e))
                    raise Exception
            else:
                cronList = split_re.split(scheduledJob.cron_expression)
                schedule = dict(itertools.izip(self.cronScheduleSequence, cronList))
                
                schedule['kwargs'] = { 'unScheduledJob': scheduledJob }
                schedule['name'] = scheduledJob.job_name
               
                try:
                    newJob = self.scheduler.add_cron_job(self.submitJobToFramework, **schedule)
                except Exception as e:
                    self.logger.error("Unknown error while submitting jobs to framework: %s" % str(e))
                    raise Exception

        # add job scheduling mechanism and cleanup to scheduler and start scheduler 
        try:
            self.scheduler.add_interval_job(self.checkJobs, seconds=self.jobSubmitInterval)
            self.scheduler.add_interval_job(self.cleanup, minutes=self.jobCleanupInterval)
            self.scheduler.start()
        except Exception as e:
            self.logger.error("Unknown error while initializing scheduler: %s" % str(e))
            raise Exception

        # initialize bus instance for receiving job notifications
        try:
            notificationBus = Bus.createConfigurableBus(self.logger, self.config, 'notifications')
            notificationBus.openFwChannel()
            notificationBus.attachToMonitoring(self.onNotification)
            notificationBus.close()
        except BusException, e:
            self.logger.error("Cannot connect to HSN2 Bus because '%s'" % e)
            raise Exception