示例#1
0
def init_schedule_task(app):
    # Now check the application config to see if scheduled reports is enabled
    if not app.config.get('ANALYTICS_ENABLE_SCHEDULED_REPORTS', False):
        return

    # First check to see if highcharts-export-server is installed and globally accessible
    if not is_highcharts_installed():
        superdesk.logger.warn('Highcharts export server is not installed')
        return

    # Make sure the TASK_ROUTES are set
    if not app.config['CELERY_TASK_ROUTES']:
        app.config['CELERY_TASK_ROUTES'] = {}

    # If the celery task is not configured, then set the default now
    if not app.config['CELERY_TASK_ROUTES'].get(
            'analytics.send_scheduled_reports'):
        app.config['CELERY_TASK_ROUTES'][
            'analytics.send_scheduled_reports'] = {
                'queue': celery_queue('default'),
                'routing_key': 'analytics.schedules'
            }

    # Make sure the BEAT_SCHEDULE are set
    if not app.config['CELERY_BEAT_SCHEDULE']:
        app.config['CELERY_BEAT_SCHEDULE'] = {}

    # If the celery schedule is not configured, then set the default now
    if not app.config['CELERY_BEAT_SCHEDULE'].get(
            'analytics:send_scheduled_reports'):
        app.config['CELERY_BEAT_SCHEDULE'][
            'analytics:send_scheduled_reports'] = {
                'task': 'analytics.send_scheduled_reports',
                'schedule': crontab(minute='0')  # Runs once every hour
            }
 def __init__(self, url, exchange_name=None):
     self.url = url
     self.connect()
     self.exchange_name = exchange_name if exchange_name else celery_queue('socket_notification')
     self.channel = self.connection.channel()
     self.socket_exchange = Exchange(self.exchange_name, type='fanout', channel=self.channel)
     self.socket_exchange.declare()
def init_scheduled_exports_task(app):
    # If the celery task is not configured, then set the default now
    if not app.config['CELERY_BEAT_SCHEDULE'].get('planning.export_scheduled_filters'):
        app.config['CELERY_TASK_ROUTES']['planning.export_scheduled_filters'] = {
            'queue': celery_queue('default'),
            'routing_key': 'planning.exports'
        }

    # If the celery schedule is not configured, then set the default now
    if not app.config['CELERY_BEAT_SCHEDULE'].get('planning:export_scheduled_filters'):
        app.config['CELERY_BEAT_SCHEDULE']['planning:export_scheduled_filters'] = {
            'task': 'planning.export_scheduled_filters',
            'schedule': crontab(minute=0)
        }
示例#4
0
def init_app(app):
    if app.config.get('ENABLE_FULFILL_ASSIGNMENTS', False):
        if not app.config.get('CELERY_TASK_ROUTES').get(
                'aap.commands.fulfill_assignments'):
            app.config['CELERY_TASK_ROUTES'][
                'aap.commands.fulfill_assignments'] = {
                    'queue': celery_queue('expiry'),
                    'routing_key': 'expiry.fulfill_assignments'
                }

        if not app.config.get('CELERY_BEAT_SCHEDULE').get(
                'planning:fulfill_assignments'):
            app.config['CELERY_BEAT_SCHEDULE'][
                'planning:fulfill_assignments'] = {
                    'task': 'aap.commands.fulfill_assignments',
                    'schedule': timedelta(minutes=1)
                }
示例#5
0
# The default timeout that is used if no timeout is specified in sec
CACHE_DEFAULT_TIMEOUT = 3600
# Redis host (used only if CACHE_TYPE is redis)
CACHE_REDIS_URL = os.environ.get('REDIS_URL', 'redis://localhost:6379')

# Recaptcha Settings
RECAPTCHA_PUBLIC_KEY = os.environ.get('RECAPTCHA_PUBLIC_KEY')
RECAPTCHA_PRIVATE_KEY = os.environ.get('RECAPTCHA_PRIVATE_KEY')

# the lifetime of a permanent session in seconds
PERMANENT_SESSION_LIFETIME = 604800  # 7 days

# the time to live value in days for user notifications
NOTIFICATIONS_TTL = 1

WEBSOCKET_EXCHANGE = celery_queue('newsroom_notification')

SERVICES = [
    {
        "name": "Domestic Sport",
        "code": "t"
    },
    {
        "name": "Overseas Sport",
        "code": "s"
    },
    {
        "name": "Finance",
        "code": "f"
    },
    {
示例#6
0
def init_app(app):
    """Initialize planning plugin.

    :param app: superdesk app
    """
    agendas_service = AgendasService('agenda', backend=superdesk.get_backend())
    AgendasResource('agenda', app=app, service=agendas_service)

    locations_search_service = LocationsService(
        'locations', backend=superdesk.get_backend())
    LocationsResource('locations', app=app, service=locations_search_service)

    register_component(LockService(app))

    init_events_app(app)
    init_planning_app(app)
    init_assignments_app(app)
    init_search_app(app)
    init_validator_app(app)

    endpoint_name = 'published_planning'
    planning_published_service = PublishedPlanningService(
        endpoint_name, backend=superdesk.get_backend())
    PublishedPlanningResource(endpoint_name,
                              app=app,
                              service=planning_published_service)

    superdesk.privilege(
        name='planning',
        label='Planning',
        description=
        'Create, update, and delete  events, planning items, and coverages')

    superdesk.privilege(name='planning_agenda_management',
                        label='Planning - Agenda Management',
                        description='Ability to create and modify Agendas')

    superdesk.privilege(name='planning_agenda_delete',
                        label='Planning - Delete Agendas',
                        description='Ability to delete an Agenda')

    superdesk.privilege(
        name='planning_edit_expired',
        label='Planning - Edit Expired Items',
        description='Ability to edit expired Event and Planning items')

    superdesk.privilege(
        name='planning_create_past',
        label='Planning - Create Event/Planning in the past',
        description='Ability to create an Event or Planning item in the past')

    app.on_update_users += PlanningNotifications().user_update

    superdesk.register_default_user_preference(
        'slack:notification', {
            'type': 'bool',
            'enabled': True,
            'default': False,
            'label': 'Allow Notifications To Slack',
            'category': 'notifications'
        })

    superdesk.register_default_user_preference(
        'planning:calendar', {
            'type': 'dict',
            'label': 'Default Calendar',
            'category': 'planning',
            'calendar': {}
        })

    superdesk.register_default_user_preference(
        'planning:agenda', {
            'type': 'dict',
            'label': 'Default Agenda',
            'category': 'planning',
            'agenda': {},
            'default': None
        })

    superdesk.register_default_user_preference(
        'planning:default_coverage_desks', {
            'type': 'dict',
            'label': 'Default desk for coverage types',
            'category': 'planning',
            'desks': {},
            'default': None
        })

    app.client_config['max_recurrent_events'] = get_max_recurrent_events(app)
    app.client_config['street_map_url'] = get_street_map_url(app)
    app.client_config[
        'max_multi_day_event_duration'] = get_event_max_multi_day_duration(app)

    # Set up Celery task options
    if not app.config.get('CELERY_TASK_ROUTES'):
        app.config['CELERY_TASK_ROUTES'] = CTR

    if not app.config.get('CELERY_TASK_ROUTES').get('planning.flag_expired'):
        app.config['CELERY_TASK_ROUTES']['planning.flag_expired'] = {
            'queue': celery_queue('expiry'),
            'routing_key': 'expiry.planning'
        }

    if not app.config.get('CELERY_TASK_ROUTES').get('planning.delete_spiked'):
        app.config['CELERY_TASK_ROUTES']['planning.delete_spiked'] = {
            'queue': celery_queue('expiry'),
            'routing_key': 'expiry.delete'
        }

    if not app.config.get('CELERY_BEAT_SCHEDULE'):
        app.config['CELERY_BEAT_SCHEDULE'] = CBS

    if app.config.get('PLANNING_EXPIRY_MINUTES', 0) != 0 and \
            not app.config.get('CELERY_BEAT_SCHEDULE').get('planning:expiry'):
        app.config['CELERY_BEAT_SCHEDULE']['planning:expiry'] = {
            'task': 'planning.flag_expired',
            'schedule': crontab(minute='0')  # Runs once every hour
        }

    if app.config.get('PLANNING_DELETE_SPIKED_MINUTES', 0) != 0 and \
            not app.config.get('CELERY_BEAT_SCHEDULE').get('planning:delete'):
        app.config['CELERY_BEAT_SCHEDULE']['planning:delete'] = {
            'task': 'planning.delete_spiked',
            'schedule': crontab(minute='0')  # Runs once every hour
        }

    # Create 'type' required for planning module if not already preset
    with app.app_context():
        vocabulary_service = superdesk.get_resource_service('vocabularies')
        types = vocabulary_service.find_one(req=None, _id='type')
        if types:
            items = types.get('items') or []
            added_types = []
            type_names = [t['qcode'] for t in items]

            planning_type_list = [{
                "is_active": True,
                "name": "Planning item",
                "qcode": "planning"
            }, {
                "is_active": True,
                "name": "Event",
                "qcode": "event"
            }, {
                "is_active": True,
                "name": "Featured Stories",
                "qcode": "planning_featured"
            }]

            for item in planning_type_list:
                if item['qcode'] not in type_names:
                    added_types.append(item)

            if len(added_types) > 0:
                vocabulary_service.patch(types.get(config.ID_FIELD),
                                         {"items": (items + added_types)})
示例#7
0
def init_app(app):
    """Initialize planning plugin.

    :param app: superdesk app
    """
    agendas_service = AgendasService('agenda', backend=superdesk.get_backend())
    AgendasResource('agenda', app=app, service=agendas_service)

    locations_search_service = LocationsService('locations', backend=superdesk.get_backend())
    LocationsResource('locations', app=app, service=locations_search_service)

    export_template_service = PlanningExportTemplatesService(PlanningExportTemplatesResource.endpoint_name,
                                                             backend=superdesk.get_backend())
    PlanningExportTemplatesResource(PlanningExportTemplatesResource.endpoint_name,
                                    app=app,
                                    service=export_template_service)

    register_component(LockService(app))

    init_events_app(app)
    init_planning_app(app)
    init_assignments_app(app)
    init_search_app(app)
    init_validator_app(app)
    init_planning_download_app(app)

    superdesk.register_resource(
        'planning_article_export',
        PlanningArticleExportResource,
        PlanningArticleExportService,
        privilege='planning',
        _app=app
    )

    endpoint_name = 'published_planning'
    planning_published_service = PublishedPlanningService(endpoint_name, backend=superdesk.get_backend())
    PublishedPlanningResource(endpoint_name, app=app, service=planning_published_service)

    superdesk.privilege(
        name='planning',
        label='Planning',
        description='Create, update, and delete  events, planning items, and coverages'
    )

    superdesk.privilege(
        name='planning_agenda_management',
        label='Planning - Agenda Management',
        description='Ability to create and modify Agendas'
    )

    superdesk.privilege(
        name='planning_agenda_delete',
        label='Planning - Delete Agendas',
        description='Ability to delete an Agenda'
    )

    superdesk.privilege(
        name='planning_edit_expired',
        label='Planning - Edit Expired Items',
        description='Ability to edit expired Event and Planning items'
    )

    superdesk.privilege(
        name='planning_create_past',
        label='Planning - Create Event/Planning in the past',
        description='Ability to create an Event or Planning item in the past'
    )

    superdesk.privilege(
        name='planning_locations_management',
        label='Planning - Manage locations',
        decsription='Ability to create, edit and delete locations'
    )

    superdesk.privilege(
        name='planning_assignments_view',
        label='Planning - Assignments view',
        decsription='Ability to access assignments view'
    )

    app.on_update_users += PlanningNotifications().user_update

    superdesk.register_default_user_preference('slack:notification', {
        'type': 'bool',
        'enabled': True,
        'default': False,
        'label': 'Allow Notifications To Slack',
        'category': 'notifications'
    })

    superdesk.register_default_user_preference('planning:calendar', {
        'type': 'dict',
        'label': 'Default Calendar',
        'category': 'planning',
        'calendar': {}
    })

    superdesk.register_default_user_preference('planning:agenda', {
        'type': 'dict',
        'label': 'Default Agenda',
        'category': 'planning',
        'agenda': {},
        'default': None
    })

    superdesk.register_default_user_preference('planning:events_planning_filter', {
        'type': 'dict',
        'label': 'Default Events Planning Filter',
        'category': 'planning',
        'filter': {},
        'default': None
    })

    superdesk.register_default_user_preference('planning:default_coverage_desks', {
        'type': 'dict',
        'label': 'Default desk for coverage types',
        'category': 'planning',
        'desks': {},
        'default': None
    })

    superdesk.register_default_user_preference('planning:add_coverage_advanced_mode', {
        'type': 'bool',
        'enabled': False,
        'default': False,
        'label': 'Open advanced mode when adding coverages',
        'category': 'planning',
    })

    app.client_config['max_recurrent_events'] = get_max_recurrent_events(app)
    app.client_config['street_map_url'] = get_street_map_url(app)
    app.client_config['max_multi_day_event_duration'] = get_event_max_multi_day_duration(app)
    app.client_config['planning_auto_assign_to_workflow'] = planning_auto_assign_to_workflow(app)
    app.client_config['long_event_duration_threshold'] = get_long_event_duration_threshold(app)
    app.client_config['event_templates_enabled'] = event_templates_enabled(app)
    app.client_config['planning_allow_scheduled_updates'] = get_planning_allow_scheduled_updates(app)
    app.client_config['planning_link_updates_to_coverage'] = planning_link_updates_to_coverage(app)
    app.client_config['planning_use_xmp_for_pic_assignments'] = get_planning_use_xmp_for_pic_assignments(app)
    app.client_config['planning_use_xmp_for_pic_slugline'] = get_planning_use_xmp_for_pic_slugline(app)

    # Set up Celery task options
    if not app.config.get('CELERY_TASK_ROUTES'):
        app.config['CELERY_TASK_ROUTES'] = CTR

    if not app.config.get('CELERY_TASK_ROUTES').get('planning.flag_expired'):
        app.config['CELERY_TASK_ROUTES']['planning.flag_expired'] = {
            'queue': celery_queue('expiry'),
            'routing_key': 'expiry.planning'
        }

    if not app.config.get('CELERY_TASK_ROUTES').get('planning.delete_spiked'):
        app.config['CELERY_TASK_ROUTES']['planning.delete_spiked'] = {
            'queue': celery_queue('expiry'),
            'routing_key': 'expiry.delete'
        }

    if not app.config.get('CELERY_TASK_ROUTES').get('planning.delete_assignments'):
        app.config['CELERY_TASK_ROUTES']['planning.delete_assignments'] = {
            'queue': celery_queue('expiry'),
            'routing_key': 'expiry.delete_assignments'
        }

    if not app.config.get('CELERY_BEAT_SCHEDULE'):
        app.config['CELERY_BEAT_SCHEDULE'] = CBS

    if app.config.get('PLANNING_EXPIRY_MINUTES', 0) != 0 and \
            not app.config.get('CELERY_BEAT_SCHEDULE').get('planning:expiry'):
        app.config['CELERY_BEAT_SCHEDULE']['planning:expiry'] = {
            'task': 'planning.flag_expired',
            'schedule': crontab(minute='0')  # Runs once every hour
        }

    if app.config.get('PLANNING_DELETE_SPIKED_MINUTES', 0) != 0 and \
            not app.config.get('CELERY_BEAT_SCHEDULE').get('planning:delete'):
        app.config['CELERY_BEAT_SCHEDULE']['planning:delete'] = {
            'task': 'planning.delete_spiked',
            'schedule': crontab(minute='0')  # Runs once every hour
        }

    if not app.config['CELERY_BEAT_SCHEDULE'].get('planning:delete_assignments'):
        app.config['CELERY_BEAT_SCHEDULE']['planning:delete_assignments'] = {
            'task': 'planning.delete_assignments',
            'schedule': timedelta(seconds=60)  # Runs once every minute
        }

    # Create 'type' required for planning module if not already preset
    with app.app_context():
        vocabulary_service = superdesk.get_resource_service('vocabularies')
        types = vocabulary_service.find_one(req=None, _id='type')
        if types:
            items = types.get('items') or []
            added_types = []
            type_names = [t['qcode'] for t in items]

            planning_type_list = [
                {"is_active": True, "name": "Planning item", "qcode": "planning"},
                {"is_active": True, "name": "Event", "qcode": "event"},
                {"is_active": True, "name": "Featured Stories", "qcode": "planning_featured"}
            ]

            for item in planning_type_list:
                if item['qcode'] not in type_names:
                    added_types.append(item)

            if len(added_types) > 0:
                vocabulary_service.patch(types.get(config.ID_FIELD), {
                    "items": (items + added_types)
                })

        custom_loaders = jinja2.ChoiceLoader(app.jinja_loader.loaders + [jinja2.FileSystemLoader(
            os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates'))])
        app.jinja_loader = custom_loaders

        register_jinja_filter('formatted_address', get_formatted_address)
 def test_celery_queue(self):
     with patch('superdesk.default_settings.os.environ.get', return_value='') as env:
         self.assertEqual('foo', celery_queue('foo'))
         env.assert_called_with('SUPERDESK_CELERY_PREFIX', '')
     with patch('superdesk.default_settings.os.environ.get', return_value='prefix'):
         self.assertEqual('prefixfoo', celery_queue('foo'))
示例#9
0
    'coverage_types': COVERAGE_TYPES,
    'display_abstract': DISPLAY_ABSTRACT,
    'display_credits': False,
    'list_animations':
    True,  # Enables or disables the animations for list item select boxes,
    'display_news_only': True,  # Displays news only switch in wire,
    'default_timezone': DEFAULT_TIMEZONE
}

# Enable iframely support for item body_html
IFRAMELY = True

COMPANY_TYPES = []

#: celery config
WEBSOCKET_EXCHANGE = celery_queue('newsroom_notification')

CELERY_TASK_DEFAULT_QUEUE = celery_queue('newsroom')
CELERY_TASK_QUEUES = (Queue(celery_queue('newsroom'),
                            Exchange(celery_queue('newsroom'), type='topic'),
                            routing_key='newsroom.#'), )

CELERY_TASK_ROUTES = {
    'newsroom.*': {
        'queue': celery_queue('newsroom'),
        'routing_key': 'newsroom.task',
    }
}

#: celery beat config
CELERY_BEAT_SCHEDULE = {
示例#10
0
        }
    },
    {
        'match': {
            'source': 'PMF'
        }
    },
]

# the lifetime of a permanent session in seconds
PERMANENT_SESSION_LIFETIME = 604800  # 7 days

# the time to live value in days for user notifications
NOTIFICATIONS_TTL = 1

WEBSOCKET_EXCHANGE = celery_queue('newsroom_notification')

SERVICES = [
    {
        "name": "Domestic Sport",
        "code": "t"
    },
    {
        "name": "Overseas Sport",
        "code": "s"
    },
    {
        "name": "Finance",
        "code": "f"
    },
    {
示例#11
0
import asyncio
import websockets
import signal

from datetime import timedelta
from threading import Thread
from kombu import Queue, Exchange, Connection
from kombu.mixins import ConsumerMixin
from kombu.pools import producers
from superdesk.utc import utcnow
from superdesk.utils import get_random_string
from superdesk.default_settings import celery_queue
from flask import json

logger = logging.getLogger(__name__)
exchange_name = celery_queue('socket_notification')


class SocketBrokerClient:
    """
    Base class for web socket notification using broker (redis or rabbitmq)
    """

    connection = None

    def __init__(self, url):
        self.url = url
        self.connect()
        self.channel = self.connection.channel()
        self.socket_exchange = Exchange(exchange_name,
                                        type='fanout',