コード例 #1
0
ファイル: job.py プロジェクト: yangleiqing0/MyVueFlask
def scheduler_job(job, scheduler=None, cron_change=None):
    if not scheduler:
        from app import scheduler
    scheduler_job_id = 'job_' + str(job.id)
    print('scheduler_job:', job.id, job.is_start, job.mail_id,
          scheduler.get_jobs())
    mail = None
    if scheduler.get_job(
            scheduler_job_id) and not cron_change and job.is_start == 1:
        print('此任务已在执行')
        return

    if job.cron and job.triggers:
        if job.mail_id:
            mail = Mail.query.get(job.mail_id)
        else:
            print('此任务没有配置邮件接收人')
        if job.is_start == 1:
            cron = job.cron.split(' ')
            print(cron)
            if len(cron) != 6:
                print('cron表达式不正确', job.name)
                return
            if cron_change:
                print('定时任务规则改变')

                try:
                    scheduler.remove_job(scheduler_job_id)
                except Exception as e:
                    print(e, '无此任务', job.name)
            scheduler.add_job(id=scheduler_job_id,
                              func=auto_send_mail,
                              trigger=job.triggers,
                              year=cron[5],
                              month=cron[4],
                              day=cron[3],
                              hour=cron[2],
                              minute=cron[1],
                              second=cron[0],
                              args=(job, mail))
            print('get_jobs:', scheduler.get_jobs(),
                  scheduler.get_job(scheduler_job_id))

            print(scheduler.get_job('scheduler_job_id'))

        elif job.is_start == 0:
            print('get_jobs is:', scheduler.get_jobs())
            try:
                scheduler.remove_job(scheduler_job_id)
            except Exception as e:
                print(e, '无此任务', job.name)
                return
            print('get_jobs is_after:', scheduler.get_jobs())
        print('现在有的任务:', scheduler.get_jobs())

    else:
        print('未输入cron表达式或trigger')
        return
コード例 #2
0
ファイル: views.py プロジェクト: hmmgit/ck-art
def index():
    if not demo_mode:
        ck_acct = CK_API.get('/v1/account/%s' % (ck_account))
        balance = ck_acct.account['balance']['decimal']
        pending = ck_acct.account['balance_pending']['decimal']
        currency = ck_acct.account['coin_type']
        ck_self = CK_API.get('/v1/my/self')
        limit = ck_self.api_key['funds_limit']['decimal']
    else:
        balance = '0'
        pending = ''
        currency = 'BTC'
        limit = '0.00'
    # Get active jobs from the scheduler
    jobs = scheduler.get_jobs()
    # Get the transaction history from the database
    try:
        transList = JobHistory.query.order_by('timestamp desc').limit(25)
    except:
        transList = ''
    addresses = get_addresses()
    return render_template('index.html',
                           jobs=jobs,
                           transList=transList,
                           addresses=addresses,
                           demo=demo_mode,
                           balance=balance,
                           pending=pending,
                           currency=currency,
                           limit=limit)
コード例 #3
0
ファイル: views.py プロジェクト: hmmgit/ck-art
def index():
    if not demo_mode:
        ck_acct = CK_API.get('/v1/account/%s' % (ck_account))
        balance = ck_acct.account['balance']['decimal']
        pending = ck_acct.account['balance_pending']['decimal']
        currency = ck_acct.account['coin_type']
        ck_self = CK_API.get('/v1/my/self')
        limit = ck_self.api_key['funds_limit']['decimal']
    else:
        balance = '0'
        pending = ''
        currency = 'BTC'
        limit = '0.00'
    # Get active jobs from the scheduler
    jobs = scheduler.get_jobs()
    # Get the transaction history from the database
    try:
        transList = JobHistory.query.order_by('timestamp desc').limit(25)
    except:
        transList = ''
    addresses = get_addresses()
    return render_template('index.html',
                           jobs=jobs,
                           transList=transList,
                           addresses=addresses,
                           demo=demo_mode,
                           balance=balance,
                           pending=pending,
                           currency=currency,
                           limit=limit)
コード例 #4
0
def re_cancel():
    jobs = scheduler.get_jobs()
    jobs_id = [(job.id, job.name) for job in jobs]
    if request.method == 'POST':
        job_id = request.form.get('cancel')
        scheduler.delete_job(job_id)  # delete the selected recurring job
        flash('Job deleted!', category='success')
        return redirect(url_for('views.home'))
    return render_template('re_cancel.html', user=current_user, jobs=jobs_id)
コード例 #5
0
ファイル: sync_manage.py プロジェクト: wemecan/School
def resume_next_job(job_id_prefix, current_job_id=None):
    """ Pause current job(if exists) and resume next job """
    from app import scheduler
    if current_job_id is not None:
        scheduler.pause_job(current_job_id)
    this_kind_of_job_ids = [
        job.id for job in scheduler.get_jobs()
        if job.id.startswith(job_id_prefix)
    ]
    next_job_id = reduce((lambda x, y: x if PREVIOUS_RUN_TIME.get(x, 0) < PREVIOUS_RUN_TIME.get(y, 0) else y),
                         this_kind_of_job_ids)
    scheduler.resume_job(next_job_id)
    PREVIOUS_RUN_TIME[next_job_id] = time.time()
コード例 #6
0
ファイル: common.py プロジェクト: zlcting/spider_keeper_beta
def reload_runnable_spider_job_execution():
    '''
    add periodic job to scheduler
    :return:
    '''
    running_job_ids = set([job.id for job in scheduler.get_jobs()])
    # app.logger.debug('[running_job_ids] %s' % ','.join(running_job_ids))
    available_job_ids = set()
    # add new job to schedule
    for job_instance in JobInstance.query.filter_by(enabled=0,
                                                    run_type="periodic").all():
        job_id = "spider_job_%s:%s" % (
            job_instance.id,
            int(time.mktime(job_instance.date_modified.timetuple())))
        available_job_ids.add(job_id)
        if job_id not in running_job_ids:
            try:
                scheduler.add_job(run_spider_job,
                                  args=(job_instance.id, ),
                                  trigger='cron',
                                  id=job_id,
                                  minute=job_instance.cron_minutes,
                                  hour=job_instance.cron_hour,
                                  day=job_instance.cron_day_of_month,
                                  day_of_week=job_instance.cron_day_of_week,
                                  month=job_instance.cron_month,
                                  second=0,
                                  max_instances=999,
                                  misfire_grace_time=60 * 60,
                                  coalesce=True)
            except Exception as e:
                app.logger.error(
                    '[load_spider_job] failed {} {},may be cron expression format error '
                    .format(job_id, str(e)))
            app.logger.info(
                '[load_spider_job][project:%s][spider_name:%s][job_instance_id:%s][job_id:%s]'
                % (job_instance.project_id, job_instance.spider_name,
                   job_instance.id, job_id))
    # remove invalid jobs
    for invalid_job_id in filter(
            lambda job_id: job_id.startswith("spider_job_"),
            running_job_ids.difference(available_job_ids)):
        scheduler.remove_job(invalid_job_id)
        app.logger.info('[drop_spider_job][job_id:%s]' % invalid_job_id)
コード例 #7
0
 def get_job(self):
     jobs = scheduler.get_jobs()
     return jobs
コード例 #8
0
                '''Remove any users that have been removed from an LDAP group'''
                '''Build list of objectGUIDs that belong in group according to LDAP'''
                users_in_group = []
                for user in ldap_users:
                    users_in_group.append(user.objectGUID.value)
                for user in users:
                    if user.ldap_guid and user.ldap_guid not in users_in_group:
                        if role in user.roles:
                            user.roles.remove(role)
                            sesh.add(user)
                            app.logger.info(
                                "LDAP Sync: Removing user {} from role {}".
                                format(user.username, role.name))
        sesh.commit()
        sesh.close()
        app.logger.info("LDAP Sync complete")


if config.ldap_enabled:
    scheduler.add_job(
        'LDAPSyncJob',
        func=sync_roles,
        trigger=IntervalTrigger(seconds=config.ldap_sync_interval_seconds),
        name='Sync Ldap every {} seconds'.format(
            config.ldap_sync_interval_seconds),
        replace_existing=True,
        max_instances=1)
    app.logger.info("Scheduler Jobs: {}".format(scheduler.get_jobs()))

if __name__ == '__main__':
    sync_roles()
コード例 #9
0
def update_online():
    """Обновление онлайна чита
        ---
        consumes:
          - application/json

        parameters:
          - in: body
            name: body
            type: object
            schema:
              properties:
                cheat_id:
                  type: string
                  description: ObjectId чита в строковом формате
                secret_data:
                  type: string
                  description: Секретный и уникальный ключ пользователя (например, HWID)

        responses:
          200:
            description: Успешный запрос
          400:
            schema:
              $ref: '#/definitions/Error'
    """
    try:
        data = request.get_json()
        cheat_id = data['cheat_id']
        secret_data = data['secret_data']
    except:
        return make_response({
            'status':
            'error',
            'message':
            'One of the parameters specified was missing or invalid'
        }), 400

    # схема тут такая:
    # 1. если пользователя в счётчике онлайна нет, то добавляем его.
    # Устанавливаем ему job на удаление из счётчика через 2 минуты
    # 2. если пользователь в счётчике онлайна есть, то обновляем ему
    # job на удаление из счётчика (откладываем на 2 минуты)
    # таким образом, если пользователь не будет подавать онлайн
    # сигнала 2 минуты, то он удалится из счётчика
    if cheat_id in subscribers_database.list_collection_names():
        if subscribers_database[cheat_id].find_one(
            {'secret_data': secret_data}) is not None:
            # атомарный доступ к переменной
            semaphore = threading.BoundedSemaphore()
            semaphore.acquire()
            if cheat_id not in online_counter_dict:
                online_counter_dict.update({cheat_id: [secret_data]})
            elif secret_data not in online_counter_dict[cheat_id]:
                online_counter_dict[cheat_id].append(secret_data)

            all_jobs = scheduler.get_jobs()
            if not is_job_in_job(all_jobs, secret_data):
                scheduler.add_job(id=secret_data,
                                  func=update_online_counter,
                                  trigger="date",
                                  run_date=datetime.now() +
                                  timedelta(minutes=2),
                                  kwargs={
                                      'cheat_id': cheat_id,
                                      'secret_data': secret_data
                                  })
            else:
                scheduler.modify_job(secret_data,
                                     next_run_time=datetime.now() +
                                     timedelta(minutes=2))
            semaphore.release()
    return ''