Exemple #1
0
async def delete_job(job_id: int, token: str = Header(None)):
    authenticated_user = verify_token(token)
    if not authenticated_user:
        response = {'detail': 'UNAUTHORIZED ACCESS', 'status': 401}
        return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED,
                            content=response)

    query = Job.select().where(Job.c.id == job_id)
    is_exist = await database.fetch_one(query)
    if not is_exist:
        response = {'detail': 'JOB NOT FOUND', 'status': 404}
        return JSONResponse(status_code=status.HTTP_404_NOT_FOUND,
                            content=response)

    if is_exist.created_by != authenticated_user['user_id']:
        response = {
            'detail': 'UNAUTHORIZED ACCESS(YOU CAN DELETE YOUR JOB ONLY)',
            'status': 401
        }
        return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED,
                            content=response)

    query = Job.update().where(Job.c.id == job_id).values(status='d')
    await database.execute(query)
    response = {
        'detail': "JOB ID: {} DELETED SUCCESSFULLY".format(job_id),
        'status': 200
    }
    return JSONResponse(status_code=status.HTTP_200_OK, content=response)
Exemple #2
0
    def run_job(self):
        """
        Validates the settings of the GUI and makes sure that they are valid
        Ensures that the video path given is a valid video and can be opened by the application
        Returns a tuple: (bool, msg) where bool is True if everything is valid and a Job was started and False otherwise,
        and msg is a success or error message
        """
        settings = self.settings
        path = self.video_path

        msg = ""

        condition1 = self.set_settings(settings, path)
        if condition1 is False:
            msg += "One or more of your settings parameters are invalid. Please double check your settings and try again\n"
            #maybe which settings are off?

        condition2 = os.path.isfile(path)
        if condition2 is False and not "youtube.com" in path:
            msg += "You entered an invalid file path. Please double check your input video and try again\n"

        if not condition1 or not condition2:
            return (False, msg)

        self.job = Job(self.get_settings())
        return (True, "Success")
Exemple #3
0
def add_job():
    if request.method == 'POST':
        payload = request.json
        print(payload)
        if payload:
            try:
                if (len(payload['club']) is not 0):
                    template = Template.query.filter_by(
                        id=int(payload['template'])).first()
                    new_data = Job()
                    new_data.template.append(template)
                    meta = {'type': payload['type']}
                    new_data.meta = json.dumps(meta)
                    for item in payload['club']:
                        print(item)
                        data = Club.query.filter_by(id=item['id']).first()
                        new_data.club.append(data)

                        db.session.add(new_data)
                        db.session.commit()
                        return jsonify({'success': 'Data Added'})

            except Exception as e:
                print(str(e))
                db.session.rollback()
                db.session.close()
                return jsonify({
                    'message': 'Something unexpected happened. Check logs',
                    'log': str(e)
                })
        else:
            return jsonify({'message': 'Empty Data.'})

    else:
        return jsonify({'message': 'Invalid HTTP method . Use POST instead.'})
Exemple #4
0
 def pop_next_job(self, max_gpu_available: int, labels: Sequence[str] = []):
     with db_lock:
         labels = set(labels)
         found = False
         self.db.begin()
         try:
             with self.db.cursor() as cur:
                 sql = 'SELECT * FROM jobs WHERE status = %s ORDER BY priority DESC, num_gpu DESC limit 1'
                 cur.execute(sql, (JobStatus.Queue.value))
                 row = cur.fetchone()
                 if row:
                     job = Job(**row)
                 if row is None or job.num_gpu > max_gpu_available:
                     rows = []
                 else:
                     sql = 'SELECT * FROM jobs WHERE status = %s AND num_gpu <= %s ORDER BY priority DESC, created_at ASC FOR UPDATE'
                     cur.execute(sql,
                                 (JobStatus.Queue.value, max_gpu_available))
                     rows = cur.fetchall()
             for row in rows:
                 job = Job(**row)
                 required_labels = set(
                     job.required_labels.
                     split(',') if len(job.required_labels) > 0 else [])
                 if required_labels.intersection(labels) != required_labels:
                     continue
                 self._update(job.id, status=JobStatus.Running)
                 found = True
                 break
             self.db.commit()
         except (Exception, KeyboardInterrupt) as e:
             self.db.rollback()
             raise e
     return job if found else None
Exemple #5
0
def addJobs(node):

    for index in range(3):
        jobName = "job{0}".format(index)
        job = Job(jobName, {"name": jobName})
        job.addCommands(
            ['echo "start: {name}"', "sleep 10", 'echo "end: {name}"'])
        node.pushJob(job)
Exemple #6
0
def register_guest():
    from model import Job
    input_data_path = request.json['input_data_path']
    input_N = request.json['input_N']
    input_K = request.json['input_K']
    message = request.json['message']

    job = Job(input_data_path, input_N, input_K, message)
    db.session.add(job)
    db.session.commit()

    return Response(json.dumps(job.serialize()), mimetype='application/json')
Exemple #7
0
def crawling(task):
    payload = {
        'first': False,
        'kd': task[0],
        'pn': task[2],
    }
    params = {
        'city': task[1]
    }

    print str(os.getpid())+' Crawling '+task[0]+' '+task[1]+' '+str(task[2])
    response = requests_post(
        'http://www.lagou.com/jobs/positionAjax.json',
        params=params,
        payload=payload)

    result = response.json()['content']['result']

    if result:
        try:
            with mysql_db.atomic():
                for res in result:
                    job = Job.select().where(Job.position_id == res['positionId']).exists()
                    if not job:
                        item = {}
                        item['position_id'] = res['positionId']
                        item['city'] = params['city']
                        item['company_name'] = res['companyName']
                        item['company_short_name'] = res['companyShortName']
                        item['company_size'] = res['companySize']
                        item['create_time'] = res['createTime']
                        item['education'] = res['education']
                        item['finance_stage'] = res['financeStage']
                        item['industry_field'] = res['industryField']
                        item['position_name'] = payload['kd']
                        item['position_first_type'] = res['positionFirstType']
                        item['position_type'] = res['positionType']
                        item['job_nature'] = res['jobNature']
                        item['salary'] = res['salary']
                        item['work_year'] = res['workYear']

                        Job.create(**item)
        except:
            print str(os.getpid())+' mysql insert exception'
        for i in range(1, 5):

            queue.put((task[0], task[1], task[2]+i))
        return
    else:
        return
Exemple #8
0
 def getJob(self, name):
     if name in self.jobs:
         return self.jobs[name]
     job = Job(name)
     if name.startswith('^'):
         # This is a meta-job
         regex = re.compile(name)
         self.metajobs[regex] = job
     else:
         # Apply attributes from matching meta-jobs
         for regex, metajob in self.metajobs.items():
             if regex.match(name):
                 job.copy(metajob)
         self.jobs[name] = job
     return job
Exemple #9
0
def add_salary_to_job():
    """Looks up salary in salaries and adds to job"""

    # create job and add to database table
    job = Job(title="Software Engineer", company_id=1, active_status=True)
    db.session.add(job)
    db.session.commit()

    salary = Salary.query.filter(metro="San Francisco", job_title="Software Engineer").avg_salary.one()
    avg_salary = salary.avg_salary

    job.avg_salary = avg_salary
    db.session.commit()

    return f"The average salary for {job.title} in {salary.metro} is {job.avg_salary}"
Exemple #10
0
 def getJob(self, name):
     if name in self.jobs:
         return self.jobs[name]
     job = Job(name)
     if name.startswith('^'):
         # This is a meta-job
         regex = re.compile(name)
         self.metajobs[regex] = job
     else:
         # Apply attributes from matching meta-jobs
         for regex, metajob in self.metajobs.items():
             if regex.match(name):
                 job.copy(metajob)
         self.jobs[name] = job
     return job
Exemple #11
0
def job_setup():

    if request.method == 'POST':

        phone = request.form['phone']
        msg_txt = request.form['msg_txt']
        frequency = request.form['frequency']
        time = request.form['time']
        active = request.form['active']
        error = None

        if not time:
            error = 'Time Preference is Required!'

        if error is not None:
            flash(error)
        else:
            new_job = Job(phone=phone,
                          msg_txt=msg_txt,
                          frequency=frequency,
                          time=time,
                          active=active)

            db.session.add(new_job)
            db.session.commit()

        flash(f'Job for {username} added.')

    return render_template('jobs.html',
                           user=user,
                           frequency_list=frequency_list,
                           msg_txt_list=msg_txt_list)
Exemple #12
0
async def create_job(job: JobValidator, token: str = Header(None)):
    authenticated_user = verify_token_with_role(token,
                                                expected_role='recruiter')
    if not authenticated_user:
        response = {'detail': 'UNAUTHORIZED ACCESS', 'status': 401}
        return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED,
                            content=response)

    query = Job.insert().values(
        created_by=authenticated_user['user_id'],
        category=job.category,
        company_name=job.company_name,
        job_title=job.job_title,
        job_type=job.job_type,
        experiance_min=job.experiance_min,
        experiance_max=job.experiance_max,
        job_count=job.job_count,
        location=job.location,
        status='cr',
        description_short=job.description_short,
        description_long=job.description_long,
    )
    session.execute(query)
    session.commit()
    return {**job.dict()}
Exemple #13
0
	def _collect_common_part(self, job):
		kron_job = Job(job.desc.content, job.url.location.path)

		if hasattr(job.priority, 'level'):
			kron_job.priority = job.priority.level

		if hasattr(job.target, 'version'):
			kron_job.target = job.target.version.name

		if hasattr(job.sync, 'value'):
			kron_job.sync = job.sync.value

		if hasattr(job.secure, 'key'):
			kron_job.security = job.secure.key

		return kron_job
Exemple #14
0
    def run(self):
        while True:
            self.socket.listen(5)
            client, address = self.socket.accept()
            message = client.recv(255).decode().split(" ")
            header = message[0]

            # Received a new job
            if header == Job.PROTOCOL_FLAG:
                logging.getLogger(self.__class__.__name__).info(
                    "Recieved a new Job: {0}".format(message))
                job = Job.readDesc(" ".join(message[1:]))
                self.node.pushJob(job)

            # Received a new Neighbour
            elif header == Neighbour.PROTOCOL_FLAG:
                neighbour = Neighbour.readDesc(" ".join(message[1:]))
                logging.getLogger(self.__class__.__name__).info(
                    "Recieved a new Neighbour: {0}".format(message))
                self.node.addNeighbour(neighbour)

            else:
                logging.getLogger(self.__class__.__name__).error(
                    "Message could not be interepreted: {0}".format(message))

            client.close()

        self.node.exit()
        self.socket.close()
Exemple #15
0
def load_jobs():
    """Load jobs from jobs.json into database."""

    #  Read jobs.json file and insert data
    job_dict = json.load(open('seed_data/jobs.json'))

    for j in job_dict:

        is_exist = db.session.query(
            Job.query.filter(Job.unique_key == j).exists()).scalar()

        if is_exist:
            continue
        else:
            comp = job_dict[j]['company']
            c_id = db.session.query(
                Company.company_id).filter(Company.company_name == comp)
            job = Job(unique_key=j,
                      title=job_dict[j]['title'],
                      company_id=c_id,
                      apply_url=job_dict[j]['apply_url'],
                      description=job_dict[j]['description'],
                      indeed_url=job_dict[j]['indeed_url'])
            db.session.add(job)

    db.session.commit()

    print("Jobs loaded.")
Exemple #16
0
def load_jobs():
    """Load jobs into database."""

    print("Jobs")
    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate jobs
    Job.query.delete()

    # Importing function that returns json of all CA job listings after API call 
    jobs_json = get_api_data()

    # Parse through API response and assign data to appropriate columns in job table 
    job_id = 1 # set first job_id to 1 and increment additional listings as +1 the current job_id
    for listing in jobs_json:
        
        job = Job(job_id = job_id,
                  title = listing['title'],
                  company = listing['company'],
                  location = listing['location'],
                  released_at = listing['created_at'],
                  github_job_uid = listing['id'],
                  logo= listing['company_logo'])
    
        db.session.add(job)
        job_id += 1

    # Once we're done, we should commit our work
    db.session.commit()
Exemple #17
0
 def start_job(self):
     self.parse_search_terms()
     if self.verify_settings():
         settings = self.get_settings()
         self.job = Job(settings, self.multi)
         self.update_log(
             f'PROCESSING: Processing job with settings: {settings}')
         btn = self.builder.get_object('Start')
         try:
             self.process = Process(target=self.job.do_the_job,
                                    args=(self.queue, ))
             btn['text'] = 'Cancel'
             self.builder.get_object('Status')['text'] = 'Working...'
             self.process.start()
             self.master.after(50, self.get_progress)
         except Exception as e:
             self.update_log(f'ERROR: Exception {e} occurred.')
Exemple #18
0
 def get_failed_jobs_since(self, since):
     with db_lock:
         with self.db.cursor() as cur:
             cur.execute(
                 'SELECT * FROM jobs WHERE status = %s AND updated_at > %s',
                 (JobStatus.Fail.value, since))
             rows = cur.fetchall()
     return [Job(**row) for row in rows]
Exemple #19
0
 def create(self, job: Job):
     with db_lock:
         job_dict = job._asdict()
         job_dict['created_at'] = datetime.datetime.now(
             tz=self.tz).isoformat()
         job_dict['updated_at'] = datetime.datetime.now(
             tz=self.tz).isoformat()
         del job_dict['id']
         sql = 'INSERT INTO jobs(' + ', '.join(list(
             job_dict.keys())) + ') VALUES (' + ', '.join(
                 ['%s'] * len(job_dict.keys())) + ')'
         with self.db.cursor() as cur:
             cur.execute(sql, list(job_dict.values()))
             cur.execute(
                 'SELECT * from jobs WHERE id = LAST_INSERT_ID() LIMIT 1')
             result = cur.fetchone()
         return Job(**result)
Exemple #20
0
 def insert(self, job_code, job_description, status):
     try:
         new_job = Job(job_code, job_description, status)
         self.database.db.session.add(new_job)
         self.database.db.session.commit()
         self.logger.info("Inserted new record Job Table")
     except:
         exc_type, exc_value, exc_traceback = sys.exc_info()
         self.logger.error("*** tb_lineno:", exc_traceback.tb_lineno)
Exemple #21
0
async def get_job(job_id: int):
    query = Job.select().where(Job.c.id == job_id)
    is_exist = await database.fetch_one(query)
    if not is_exist:
        response = {'detail': 'JOB NOT FOUND', 'status': 404}
        return JSONResponse(status_code=status.HTTP_404_NOT_FOUND,
                            content=response)

    return is_exist
def add_job(name, desc, location, salary, min_age, email):
    job = Job(name=name,
              description=desc,
              salary=salary,
              location=location,
              min_age_jobs=min_age,
              email=email)
    session.add(job)
    session.commit()
Exemple #23
0
    def post(delf):
        """Add a private job."""

        if not current_user.is_active:
            return 'Please login first.'

        key1 = request.form.get('key1')
        key2 = request.form.get('key2')
        key3 = request.form.get('key3')
        key4 = request.form.get('key4')

        company_id = None
        job_id = None

        if Company.query.filter(Company.company_name == key2).first():
            company = Company.query.filter(
                Company.company_name == key2).first()
            company_id = company.company_id
        else:
            new_company = Company(key2, is_private='t')
            db.session.add(new_company)
            db.session.commit()

            company = Company.query.filter(Company.company_name == key2).one()
            company_id = company.company_id

        if Job.query.filter((Job.title == key1) & (Job.description == key3)
                            & (Job.company_id == company_id)
                            & (Job.is_private == 't')).first():
            the_job = Job.query.filter((Job.title == key1)
                                       & (Job.description == key3)
                                       & (Job.company_id == company_id)
                                       & (Job.is_private == 't')).first()
            job_id = the_job.job_id
        else:
            new_job = Job(key1, company_id, key3, key4, is_private='t')
            db.session.add(new_job)
            db.session.commit()

            the_job = Job.query.filter((Job.title == key1)
                                       & (Job.description == key3)
                                       & (Job.company_id == company_id)
                                       & (Job.is_private == 't')).first()
            job_id = the_job.job_id

        user_id = current_user.get_id()
        status = 'Applied'

        new_user_job = UserJob(user_id, job_id, status)
        db.session.add(new_user_job)
        db.session.commit()

        return 'User Job Added.'
Exemple #24
0
 def _update(self, id: int, **kwargs):
     default_job = Job()
     job = dict()
     for key, value in kwargs.items():
         if hasattr(default_job, key) and type(value) == type(
                 getattr(default_job, key)):
             job[key] = value
     job['updated_at'] = datetime.datetime.now(tz=self.tz).isoformat()
     sql = 'UPDATE jobs set ' + ', '.join(
         [key + '= %s' for key in job.keys()]) + ' WHERE id = %s'
     with self.db.cursor() as cur:
         cur.execute(sql, list(job.values()) + [id])
Exemple #25
0
async def update_job(job_id: int, job: JobValidator,
                     token: str = Header(None)):
    query = Job.select().where(Job.c.id == job_id)
    is_exist = await database.fetch_one(query)
    if not is_exist:
        response = {'detail': 'JOB NOT FOUND', 'status': 404}
        return JSONResponse(status_code=status.HTTP_404_NOT_FOUND,
                            content=response)

    authenticated_user = verify_token_with_role(token,
                                                expected_role='recruiter')
    if not authenticated_user or is_exist.created_by != authenticated_user[
            'user_id']:
        response = {
            'detail': 'UNAUTHORIZED ACCESS(ONLY JOB OWNER CAN UPDATE THE JOB)',
            'status': 401
        }
        return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED,
                            content=response)

    query = Job.update().where(Job.c.id == job_id).values(
        company_name=job.company_name
        if job.company_name else is_exist.company_name,
        job_title=job.job_title if job.job_title else is_exist.job_title,
        job_type=job.job_type if job.job_type else is_exist.job_type,
        experiance_min=job.experiance_min
        if job.experiance_min else is_exist.experiance_min,
        experiance_max=job.experiance_max
        if job.experiance_max else is_exist.experiance_max,
        job_count=job.job_count if job.job_count else is_exist.job_count,
        location=job.location if job.location else is_exist.location,
        status=job.status if job.status else is_exist.status,
        description_short=job.description_short
        if job.description_short else is_exist.description_short,
        description_long=job.description_long
        if job.description_long else is_exist.description_long,
    )
    last_record_id = await database.execute(query)
    await database.execute(query)
    return {**job.dict(), "ID": last_record_id}
Exemple #26
0
 def job_add(self,
             _num=constant.init["job"],
             _uname=constant.init["user"],
             _state=constant.state["n2s"]["run"]):
     # test init job
     if _num == constant.init["job"] and _uname == constant.init["user"]:
         _state = constant.init["state"]
         self.user_add()
     # test user of job
     try:
         _uquery = self.user_query("one", _uname)
     except:
         pass
     else:
         _query = self.job_query("all", _num)
         if _query == []:
             add_row = Job()
             add_row.num = int(_num)
             add_row.user_id = _uquery.id
             add_row.const_state = u"" + _state
             self.__session.add(add_row)
             self.__session.commit()
Exemple #27
0
def add_job(board_id):
    """Add a job to a board."""

    title = request.form.get('title')
    desc = request.form.get('desc')
    job = Job(title, desc)

    db.session.add(job)
    db.session.commit()

    db.session.add(BoardJob(board_id, job.id))
    db.session.commit()

    return redirect('/')
Exemple #28
0
def main():
    python = Job.select().where(Job.position_name == 'python')
    java = Job.select().where(Job.position_name == 'java')
    php = Job.select().where(Job.position_name == 'php')
    c_plus = Job.select().where(Job.position_name == 'c++')
    c = Job.select().where(Job.position_name == 'c')

    positions = {
        'python': python,
        'java': java,
        'php': php,
        'c++': c_plus,
        'c': c
    }
    cities = ['北京', '上海', '广州', '深圳', '杭州']
    # cities = ['北京']

    # positionnum_city(positions, cities)
    # salary_city(positions, cities)
    # companysize_city(positions, cities)
    # salary_workyear(positions)
    # salary_education(positions)
    positionnum_workyear(positions)
    positionnum_education(positions)
def new_application():
    # company attributes
    company_name = request.form.get('company_name')
    website = request.form.get('website')
    # job attributes
    title = request.form.get('title')
    link = request.form.get('link')
    source = request.form.get('source')
    # application status attributes
    status = request.form.get('status')

    application = Application()
    db.session.add(application)

    company = db.session.query(Company) \
        .filter((Company.company_name==company_name) & (Company.website==website)) \
        .first()
    if not company:
        company = Company(company_name=company_name,
            website=website)
        db.session.add(company)
        db.session.commit()
    
    job = db.session \
        .query(Job) \
        .filter(Job.title==title, Job.link==link, Job.source==source, Job.company==company) \
        .first()
    if not job:
        job = Job(title=title, link=link, source=source)
        db.session.add(job)
        company.jobs.append(job)
        db.session.commit()
    
    application_status = ApplicationStatus(status=status)
    db.session.add(application_status)

    current_user.applications.append(application)
    job.applications.append(application)
    application.application_statuses.append(application_status)
    db.session.commit()
    # TODO: point entry for new application

    return jsonify({
        'application_id': application.application_id,
        'title': job.title,
        'company_name': company.company_name,
        'status': application_status.status,
    })
Exemple #30
0
def seed1():
    datetime_applied, datetime_created = datetime.now(), datetime.now()

    user = User(email='*****@*****.**', 
                password='******', 
                first_name='First', 
                last_name='Last', 
                datetime_created=datetime_created)
    db.session.add(user)

    company = Company(company_name='My Company', 
                        website='www.mycompany.com', 
                        datetime_created=datetime_created)
    db.session.add(company)
    db.session.commit()

    job = Job(company_id=company.company_id,
                title='Software Engineer',
                link='www.linkedin.com/mycompany/software-engineer',
                source='LinkedIn',
                datetime_created=datetime_created
                )
    db.session.add(job)
    db.session.commit()

    application = Application(user_id=user.user_id,
                                job_id=job.job_id,
                                datetime_applied=datetime_applied, 
                                referred_by="Anjelica", 
                                datetime_created=datetime_created)
    db.session.add(application)
    db.session.commit()

    application_status = ApplicationStatus(application_id=application.application_id,
                                            status='Applied',
                                            experience_rating='positive',
                                            datetime_created=datetime_created)
    db.session.add(application_status)

    journal_entry = JournalEntry(application_id=application.application_id,
                            entry='This is a journal entry.',
                            datetime_created=datetime_created)

    db.session.add(journal_entry)
    db.session.commit()
Exemple #31
0
def seed2():
    datetime_applied, datetime_created = datetime.now(), datetime.now()

    user = User.query.first()

    company = db.session.query(Company).filter(Company.company_name.like('%Another Company%')).first()
    if not company:
        company = Company(company_name='Another Company', 
                            website='www.anothercompany.com', 
                            datetime_created=datetime_created)
    db.session.add(company)
    db.session.commit()

    job = db.session.query(Job).filter(Job.company_id==company.company_id, Job.title.like('%Software Engineer%')).first()
    if not job:
        job = Job(company_id=company.company_id,
                    title='Software Engineer',
                    link='www.linkedin.com/anothercompany/software-engineer',
                    source='Glassdoor',
                    datetime_created=datetime_created)
    db.session.add(job)
    db.session.commit()

    application = Application(user_id=user.user_id,
                                job_id=job.job_id,
                                datetime_applied=datetime_applied, 
                                referred_by="Anjelica", 
                                datetime_created=datetime_created)
    db.session.add(application)
    db.session.commit()

    application_status = ApplicationStatus(application_id=application.application_id,
                                            status='Applied',
                                            experience_rating='positive',
                                            datetime_created=datetime_created)
    db.session.add(application_status)

    journal_entry = JournalEntry(application_id=application.application_id,
                            entry='Another journal entry.',
                            datetime_created=datetime_created)

    db.session.add(journal_entry)
    db.session.commit()
Exemple #32
0
def show_jobs(jobId=None):
    """ Get jobs from the queue """
    if request.method == 'POST':
        """ Add a job to the queue """
        new_job = Job(status='new', location=request.form['location'])
        alchemy_db.session.add(new_job)
        alchemy_db.session.commit()
        return redirect(url_for('show_jobs'))
    if jobId:
        if request.method == 'GET':
            entry = alchemy_db.session.query(
                Job.id, Job.status, Job.location,
                Job.data).filter(Job.id == jobId).first()

            data = {
                'data': {
                    'id': entry[0],
                    'status': entry[1],
                    'location': entry[2],
                    'data': entry[3]
                }
            }
            return '{}'.format(json.dumps(data))
        elif request.method == 'DELETE':
            alchemy_db.session.query(
                Job.id, Job.status, Job.location,
                Job.data).filter(Job.id == jobId).delete()
            alchemy_db.session.commit()

    entries = alchemy_db.session.query(Job.id, Job.status, Job.location,
                                       Job.data).all()
    data = {}
    for entry in entries:
        data[entry[0]] = {
            'status': entry[1],
            'location': entry[2],
            'links': {
                'run query': 'http://127.0.0.1:5000/run/{}'.format(entry[0]),
                'view data': 'http://127.0.0.1:5000/job/{}'.format(entry[0])
            }
        }

    return '{}'.format(json.dumps(data))
Exemple #33
0
    def _collect_common_part(self, job):
        kron_job = Job(job.desc.content, job.url.location.path)

        if hasattr(job.priority, 'level'):
            kron_job.priority = job.priority.level

        if hasattr(job.target, 'version'):
            kron_job.target = job.target.version.name

        if hasattr(job.sync, 'value'):
            kron_job.sync = job.sync.value

        if hasattr(job.secure, 'key'):
            kron_job.security = job.secure.key

        return kron_job
Exemple #34
0
def schedule():
    print(request.json)
    try:
        lat = float(request.json.get('lat'))
        lon = float(request.json.get('lon'))
        time = float(request.json.get('time'))
        time = datetime.datetime.fromtimestamp(time)
    except Exception as e:
        return {'success': False, 'message': str(e)}


    # check scheduling conflict etc
    if True:
        job = Job(lat=lat, lon=lon, time=time)
        db.session.add(job)
        db.session.commit()

        cron.add_job(func=take_image, args=([job.id]), trigger="date", run_date=time, id=str(job.id))

        return {
            'success': True, 'message': str(job), 'job_id': job.id
            }
Exemple #35
0
def create_job():
    """Creates a job in the database and returns the job ID to the user"""

    # Get the URL back from the form
    # Query the database to get the URL back
    # If the URl is not in the table, add it to the table, get job ID
    # If the URL is in the table already, get the Job ID
    # Return the job ID to the user as JSON

    requested_url = request.form.get("url")

    url = Job.query.filter(Job.url == requested_url).first()

    if not url:
        url = Job(url=requested_url)
        db.session.add(url)
        db.session.commit()

    job_id = url.job_id

    job_details = {"job_id": job_id}

    return jsonify(job_details)