Example #1
0
    def put(self):
        args = settings_parser.parse_args()
        # Get client id and secret from input fields stored in database
        client_id = GeneralSetting.where(name='client_id').first().value
        client_secret = GeneralSetting.where(
            name='client_secret').first().value

        # Gets value from the google_ads_authentication_code field
        ads_code = [
            d['value'] for d in args['settings']
            if d['name'] == 'google_ads_authentication_code'
        ][0]

        token = ads_auth_code.get_token(client_id, client_secret, ads_code)

        settings = []
        for arg in args['settings']:
            setting = GeneralSetting.where(name=arg['name']).first()
            if setting:
                if setting.name == 'google_ads_refresh_token':
                    setting.update(value=token)
                else:
                    setting.update(value=arg['value'])
            settings.append(setting)
        return settings
Example #2
0
 def recipients(self, other_recipients):
     from core.models import GeneralSetting
     gsetting = GeneralSetting.where(
         name='emails_for_notifications').first()
     if gsetting is None or gsetting.value is None:
         recipients = other_recipients
     else:
         recipients = list(set(gsetting.value.split() + other_recipients))
     return recipients
Example #3
0
 def put(self):
     args = settings_parser.parse_args()
     settings = []
     for arg in args['settings']:
         setting = GeneralSetting.where(name=arg['name']).first()
         if setting:
             setting.update(value=arg['value'])
             settings.append(setting)
     return settings
Example #4
0
    def get(self):
        urlfetch.set_default_fetch_deadline(300)
        params = Param.where(pipeline_id=None,
                             job_id=None).order_by(Param.name)
        settings = GeneralSetting.query.order_by(GeneralSetting.name)

        # Get client id and secret from input fields stored in database
        client_id = GeneralSetting.where(name='client_id').first().value
        # Url to redirect
        url = ads_auth_code.get_url(client_id)

        return {
            'sa_email': SA_DATA['client_email'],
            'variables': params,
            'settings': settings,
            # Added url to config
            'google_ads_auth_url': url,
        }
Example #5
0
  def post(self):
    """
    NB: you want retrieve the task name with this snippet

        task_name = request.headers.get('X-AppEngine-TaskName')[11:]

    """
    urlfetch.set_default_fetch_deadline(300)
    retries = int(request.headers.get('X-AppEngine-TaskExecutionCount'))
    args = parser.parse_args()
    logger.debug(args)
    task_name = args['task_name']
    job = Job.find(args['job_id'])
    worker_class = getattr(workers, args['worker_class'])
    worker_params = json.loads(args['worker_params'])

    for setting in worker_class.GLOBAL_SETTINGS:
        worker_params[setting] = GeneralSetting.where(name=setting).first().value

    worker = worker_class(worker_params, job.pipeline_id, job.id)
    if retries >= worker_class.MAX_ATTEMPTS:
      worker.log_error('Execution canceled after %i failed attempts', retries)
      job.task_failed(task_name)
    elif job.status == 'stopping':
      worker.log_warn('Execution canceled as parent job is going to stop')
      job.task_failed(task_name)
    else:
      try:
        workers_to_enqueue = worker.execute()
      except workers.WorkerException as e:
        worker.log_error('Execution failed: %s: %s', e.__class__.__name__, e)
        job.task_failed(task_name)
      except Exception as e:
        worker.log_error('Unexpected error: %s: %s', e.__class__.__name__, e)
        raise e
      else:
        for worker_class_name, worker_params, delay in workers_to_enqueue:
          job.enqueue(worker_class_name, worker_params, delay)
        job.task_succeeded(task_name)
    return 'OK', 200
Example #6
0
# Copyright 2018 Google Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import run_ibackend
from core.models import GeneralSetting

# SETUP SETTINGS
settings = ['emails_for_notifications']
for setting in settings:
    gsetting = GeneralSetting.where(name=setting).first()
    if not gsetting:
        gsetting = GeneralSetting()
        gsetting.name = setting
        gsetting.save()
        print 'Added setting', setting