예제 #1
0
    def post(self):

        valid = Validate().validate()

        if valid:
            owner_id = valid['owner_id']
            type = valid['type']
            graph_id = valid['_id']

            filterTrans = FilterTransformation()
            filters = filterTrans.transformation(valid)

            try:
                if filterTrans.is_("apps"):
                    entry_id = task_graphlookup.delay(owner_id=owner_id,
                                                      graph_id=graph_id,
                                                      entries=filters,
                                                      typed=type)
                else:
                    entry_id = task_entry.delay(filters=filters,
                                                graph_id=graph_id,
                                                owner_id=owner_id,
                                                typed=type)

                logger.info(entry_id)
                return str(entry_id), 201

            except Exception as error:
                task_notification.delay(graph_id=graph_id,
                                        msg=str(error),
                                        status='error')
                logger.error(error)
                return {'message': str(error)}, 501

        return valid, 502
예제 #2
0
    def caller(task, args):
        tasks = {
            'connections': task_connections,
            'webhook': task_webhook,
            'reports': task_reports
        }

        if task in tasks:

            task_id = tasks[task].delay(**args)
            counter_id = task_counter.delay(_id=args.get('_id'))
            logger.info('Scheduler: Task executed %s (%s)', task_id,
                        counter_id)
    def raiseError(self):
        msg = ''

        if self.get_status() < 400:
            return False

        if self.get_status() >= 400:
            msg = self.__context.text

        if self.get_status() in [0]:
            msg = "Service not found"

        logger.info("Error %s", msg)
        raise ClientMaestroError(msg)
예제 #4
0
    def spawn(self, queue, scheduler):
        for spawn in queue:
            spawnId = spawn.get('_id')

            if spawnId:
                exist = scheduler.get_job(spawnId)
                sjob = SpawnJobs.mapp(spawn)
                if not exist:
                    jobs = self.create(spawnId, scheduler, sjob,
                                       SpawnJobs.is_disabled(spawn))
                    logger.info('Scheduler: Create Job [%s]', str(jobs))
                else:
                    self.update(spawnId, scheduler, sjob,
                                SpawnJobs.is_disabled(spawn))
                    logger.info('Scheduler: Update Job [%s]', spawnId)

                if spawn.get('run_immediately', False):
                    self.run_now(spawnId, scheduler, sjob,
                                 SpawnJobs.is_disabled(spawn))
                    logger.info(
                        '--------------->>>>>> Scheduler: Run immediaty [%s]',
                        spawn.get('name'))

                logger.info('Scheduler: Crawler Job [%s]', spawn.get('name'))
    def get_json(self):

        if self.__context:
            logger.info("Request[CODE %s] - %s", self.get_status(),
                        self.__path)
            return self.__context.json()
예제 #6
0
# -*- encoding: utf-8 -*-
"""
Python Aplication Template
Licence: GPLv3
"""

import pymongo
from flask import Flask
from pymongo import MongoClient
from app.libs.logger import logger

app = Flask(__name__)
app.config.from_object('instance.config.Config')

client = MongoClient(app.config['DATABASE_URI'], serverSelectionTimeoutMS=1)
db = client[app.config['DATABASE_NAME']]

if __name__ != '__main__':
    gunicorn_logger = logger.getLogger('gunicorn.error')
    app.logger.handlers = gunicorn_logger.handlers
    app.logger.setLevel(gunicorn_logger.level)

try:
    client.server_info()
    logger.info("Mongo Online")
except pymongo.errors.ServerSelectionTimeoutError as err:
    logger.error("==================================> MongoDB is down %s", err)
예제 #7
0
 def tick(self):
     self.sync_jobs()
     logger.info('Scheduler: Tick[%s] ----> %s', self.__resource,
                 len(self.__jobs))