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
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.")
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")
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)
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()
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.'})
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]
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)
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)
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()
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')
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])
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.'
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('/')
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
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, })
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
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)
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.')
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()
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))
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()
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()
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 }
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)
def load_jobs(): """Load fake sample job data from job-example.txt into database""" print("Loading jobs...") # Delete all rows in table to make sure there are no dupes Job.query.delete() # Read file and insert data for row in open("data/job-example.txt"): row = row.rstrip() title, link, company_id, active_status, notes = row.split("|") job = Job(title=title, link=link, company_id=company_id, active_status=bool(active_status), notes=notes) # Add to the session db.session.add(job) # commit the session to database db.session.commit()
def start_job(self): try: self.job = Job(self.get_settings()) return True except: return False
def download_webloc(self, filepath: str, request_options: dict, callback: callable = None) -> None: with youtube_dl.YoutubeDL(self.get_ydl_options(request_options)) as ydl: url = webloc.read(filepath) future = self.download_executor.submit(ydl.download, [url]) self.jobs.append(Job.Job(url, filepath, request_options, future, callback))
def download_url(self, url: str, request_options: dict, callback: callable = None) -> None: with youtube_dl.YoutubeDL(self.get_ydl_options(request_options)) as ydl: future = self.download_executor.submit(ydl.download, [url]) self.jobs.append(Job.Job(url, None, request_options, future, callback))
def process_job_form(): """Allow user to add a job""" # redirect if user is not logged in if not session: return redirect('/') else: # get user_id from session user_id = session['user_id'] # get data from form job_title = request.form['job_title'] job_status = request.form['job_status'] # look for optional data and add if it exists if request.form['job_link']: job_link = request.form['job_link'] if not job_link: job_link = None elif job_link[:4] != 'http': job_link = ''.join(['http://', job_link]) else: job_link = "" if request.form['job_notes']: job_notes = request.form['job_notes'] else: job_notes = "" # look for company_id and find existing company # or get new company_name and create company object, add, commit if request.form['company_id']: company_id = int(request.form['company_id']) company = Company.query.filter( Company.company_id == company_id).first() elif request.form['company_name']: company_name = request.form['company_name'] company = Company(name=company_name) db.session.add(company) db.session.commit() # create a new job object, add, commit job = Job(title=job_title, link=job_link, company_id=company.company_id, active_status=True, notes=job_notes) db.session.add(job) db.session.commit() # create a job event to kick off job status, add, commit today = datetime.now() job_event = JobEvent(user_id=user_id, job_id=job.job_id, job_code=job_status, date_created=today) db.session.add(job_event) db.session.commit() todo_for_event = { '1': '1', '2': '2', '3': '3', '4': '3', '5': '4', '6': '5', '7': '6', '8': '7' } todo_code = todo_for_event[job_status] find_code = ToDoCode.query.filter( ToDoCode.todo_code == todo_code).first() num_days = find_code.sugg_due_date due_date = today + timedelta(days=num_days) # activate todo for event new_todo = ToDo(job_event_id=job_event.job_event_id, todo_code=todo_code, date_created=today, date_due=due_date, active_status=True) db.session.add(new_todo) db.session.commit() # return to active jobs and show confirmation flash('{} added to your jobs.'.format(job_title), 'success') return redirect('/dashboard/jobs')