Ejemplo n.º 1
0
 def extract_info_from_document(self, document):
     for item in document.xpath('.//div[@id="resultList"]/div[@class="el"]'):
         job_id = get_simple_dom(item, './/input[@name="delivery_jobid"]/@value')
         try:
             Job.get(Job.uniqueId == job_id)
             continue
         except Job.DoesNotExist:
             pass
         job_url = get_simple_dom(item, './/p[contains(@class, "t1")]/span/a/@href')
         company_url = get_simple_dom(item, './/span[contains(@class, "t2")]/a/@href')
         company_unique_id = self.get_company_unique_id(company_url)
         if not company_unique_id:
             continue
         try:
             company = Company.get(Company.uniqueId == company_unique_id)
             company_id = company.id
         except Company.DoesNotExist:
             company_name = get_simple_dom(item, './/span[@class="t2"]/a/@title')
             position = get_simple_dom(item, './/span[@class="t3"]/text()')
             try:
                 company_id = self.extract_company_info(company_url, company_name, position)
             except:
                 print('Company解析error,companyURL为' + company_url)
                 continue
         try:
             self.extract_job_info(job_url, job_id, company_id)
         except Exception as e:
             # import traceback
             # traceback.print_exc(e)
             # import ipdb;ipdb.set_trace()
             print('Job解析error,jobURL为' + job_url)
Ejemplo n.º 2
0
 def post(self, job_id):
     job = Job.get_by_key_name(job_id)
     # make sure the job is recent
     if not(job.active):
         self.error(404)
     club = job.flyer.club
     email = job.email
     # update the email
     email.updated_at = datetime.now()
     email.put()
     # find the email-club join
     join_query = EmailToClub.all()
     join_query.filter("email =", email)
     join_query.filter("club =", club)
     join = join_query.get()
     # do the delete
     join.enable = False
     join.updated_at = datetime.now()
     join.put()
     # mark all the jobs inactive
     flyer_query = Flyer.all()
     flyer_query.filter("club =", club)
     flyer_query.filter("active =", True)
     flyers = flyer_query.fetch(20)
     for flyer in flyers:
         job_query = Job.all()
         job_query.filter("email =", email)
         job_query.filter("flyer =", flyer)
         job_query.filter("active =", True)
         job = job_query.get()
         if job:
             job.active = False
             job.put()
     self.response.out.write(template.render("templates/sorry.html",
                                             {}))
Ejemplo n.º 3
0
 def post(self, job_id):
     job = Job.get_by_key_name(job_id)
     # make sure the job is recent
     if not(job.active):
         self.error(404)
     email = job.email
     email.enable = False
     email.updated_at = datetime.datetime.now()
     email.put()
     # find the email-club join
     join_query = EmailToClub.all()
     join_query.filter("email =", email)
     joins = join_query.fetch(20)
     # do the delete
     for join in joins:
         join.enable = False
         join.updated_at = datetime.now()
         join.put()
     # mark all the jobs inactive
     job_query = Job.all()
     job_query.filter("email =", email)
     job_query.filter("active =", True)
     jobs = job_query.fetch(20)
     for job in jobs:
         job.active = False
         job.put()
     self.response.out.write(template.render("templates/sorry.html", {}))
Ejemplo n.º 4
0
def add_job_view(request):
    if request.method == 'POST':
        title = request.POST.get('job-title')
        date = request.POST.get('job-date')
        description = request.POST.get('job-description')

        user = User.objects.get(username=request.user.username)

        new_job = Job(user=user,
                      title=title,
                      description=description,
                      created=datetime.strptime(date, '%Y-%m-%d'))
        new_job.save()

        icon = '<i class="fa fa-plus text-success" aria-hidden="true"></i>'
        added_msg = "Added new job <strong>{0}</strong>".format(title)
        new_activity = Activity(
            user=User.objects.get(username=request.user.username),
            icon=icon,
            description=added_msg)
        new_activity.save()

        messages.success(request, added_msg, extra_tags='added_job')

    return redirect('dashboard:index')
Ejemplo n.º 5
0
    def create_job(jwt):
        request_value = request.get_json()

        if request_value is None:
            abort(400)

        company_id = request_value['company_id']
        company = Company.query.filter_by(id=company_id).one_or_none()

        if company is None:
            abort(400)

        job = Job(
            request_value['title'],
            request_value['description'],
            request_value['city'],
            request_value['state'],
            request_value['imageBase64'],
            request_value['is_active'],
            request_value['is_remote'],
            company_id
        )

        job.insert()

        return jsonify({
            'status_code': 200,
            'job': job.format_long(),
            'message': 'The job was successfully created',
            'success': True,
        })
Ejemplo n.º 6
0
def add_job(request):
    try:
        form = JobForm(request.POST or None)
        if form.is_valid():
            required_skills = set(form.cleaned_data["required_skills"])
            optional_skills = set(form.cleaned_data["optional_skills"]) - required_skills
            with transaction.atomic():
                employer = Employer.objects.get(user=request.user)
                job = Job(
                    employer=employer,
                    description=form.cleaned_data["description"],
                    category=form.cleaned_data["category"],
                    years_of_experience=form.cleaned_data["years_of_experience"],
                    other=form.cleaned_data["other"],
                )
                job.save()
                for skill in required_skills:
                    skill = RequiredJobSkill(job=job, skill=skill)
                    skill.save()
                if optional_skills:
                    for skill in optional_skills:
                        skill = OptionalJobSkill(job=job, skill=skill)
                        skill.save()
            match_job.delay(job.id)

            messages.success(request, "Job saved successfully. You'll receive matching candidates soon")
            return HttpResponseRedirect("/")
        return render(request, "jobs/add_job.html", {"form": form})
    except Exception, e:
        logging.exception(e)
        return server_error(request)
Ejemplo n.º 7
0
def get_jobs(credentials):
    threads = []
    # results is a mutable object, so as the threads complete they save their
    # results into this object. This method is used in lieu of messing with
    # multiple processes
    results = [None] * len(credentials)
    for i, cred in enumerate(credentials):
        t = threading.Thread(target=_get_jobs,
                             args=(cred, cred.cluster.name, i, results))
        t.start()
        threads.append(t)

    for t in threads:
        t.join(20)

    clusters = [x for x in results if x]
    for cred, cluster in zip(credentials, clusters):
        jobs = defaultdict(list)
        jobids = []
        for job in cluster["jobs"]:
            status = job[-1]
            job_id = job[0]
            jobids.append(job_id)
            if not Job.objects.filter(jobid=job_id, credential=cred):
                continue  # outside submited jobs not allowed
            jobs[status].append(job_id)
        running = Job.get_running_jobs(credential=cred)
        unknown = running.exclude(jobid__in=set(jobids)).values_list('jobid',
                                                                     flat=True)
        if unknown:
            jobs[Job.UNKNOWN] = list(unknown)
        Job.update_states(cred, jobs)
    return clusters
Ejemplo n.º 8
0
    def get(self, job_id):
        job = Job.get_by_key_name(job_id)

        if job and job.state != DONE and job.active == True:
            job.updated_at = datetime.now()
            job.state = DONE
            job.put()
            # update the email
            email = job.email
            email.updated_at = datetime.now()
            email.put()
            # count the number of jobs attached to this flyer
            job_query = Job.all()
            job_query.filter("flyer =", job.flyer)
            job_query.filter("active =", True)
            total_jobs = job_query.count()
            # count the number of jobs done so far
            job_query = Job.all()
            job_query.filter("flyer =", job.flyer)
            job_query.filter("active =", True)
            job_query.filter("state =", DONE)
            done_jobs = job_query.count()
            # write out
            self.response.out.write(template.render("templates/finish.html",
                                                    {"total": total_jobs,
                                                     "done": done_jobs}))
        else:
            self.error(404)
Ejemplo n.º 9
0
def bpusher_PostJob(request):

    jsonData = json.loads(request.body)

    try:
        destination = Destination.objects.get(name=jsonData['job']['destination'])
    except ObjectDoesNotExist:
        status = http_NOT_FOUND
        return HttpResponse(json.dumps({'message': 'Destination not found'}), status=status, content_type='application/json')

    job = Job()
    job.name		= jsonData['job']['name']
    job.input_name	= jsonData['job']['input_name']
    job.system_path	= jsonData['job']['system_path']
    job.input_path	= jsonData['job']['input_path']
    job.destination	= destination
    job.priority	= jsonData['job']['priority']
    job.status		= 'Q' # Queue
    

    job.save()

    response = {"job": {"id": job.id, "name": job.name}}
    #
    # La unica respuesta para esto es OK

    status = http_POST_OK
    return HttpResponse(json.dumps(response), status=status, content_type='application/json')
Ejemplo n.º 10
0
    def post(self, request, *args, **kwargs):
        form = JobForm(request.POST, request.FILES)
        if form.is_valid():
            now = datetime.datetime.now()
            name = request.POST['name']
            description = request.POST['description']
            interval = request.POST['interval']
            interval_options = request.POST['interval_options']
            arguments = request.POST['arguments']
            active = False
            try:
                request.POST['active']
                active = True
            except:
                pass

            file = request.FILES['file']
            file_content = file.read()
            file_name = str(now.year) + str(now.month) + str(now.day) + str(now.hour) + str(now.minute) + str(now.second) + str(now.microsecond) + name.replace(' ', '-') + '.py'
            f = open(BASE_DIR + '/job_files/' + file_name, 'w')
            f.write(file_content)
            f.close()

            #Save job
            new_job = Job(name=name, description=description, interval=interval, interval_options=interval_options, arguments=arguments, active=active, file_name=file_name)
            new_job.save()

            res = 'Job created'

        return render_to_response(self.template_name, locals(), context_instance=RequestContext(request))
Ejemplo n.º 11
0
def imen_PostJob(request):

    jsonData = json.loads(request.body)

    try:
        preset = ThumbPreset.objects.get(name=jsonData['job']['thumb_preset'])
    except ObjectDoesNotExist:
        status = http_NOT_FOUND
        return HttpResponse(json.dumps({'message': 'ThumbPreset not found'}), status=status, content_type='application/json')


    job = Job()
    job.input_filename  = jsonData['job']['input_filename']
    job.input_path      = jsonData['job']['input_path']
    job.basename        = jsonData['job']['basename']
    job.thumb_preset    = preset
    job.priority        = jsonData['job']['priority']
    job.output_path     = jsonData['job']['output_path']
    job.status          = 'Q' # Queue

    job.save()

    response = {"job": {"id": job.id}}
    #
    # La unica respuesta para esto es OK

    status = http_POST_OK
    return HttpResponse(json.dumps(response), status=status, content_type='application/json')
Ejemplo n.º 12
0
  def test_job_should_emit_results_for_all_urls(self):
    first_domain = Domain("http://example.com")
    first_img_url = Image("http://example.com/1.png")
    second_img_url = Image("http://example.com/2.png")
    third_img_url = Image("http://example.com/3.png")

    first_domain.images.extend([first_img_url, second_img_url, third_img_url])

    second_domain = Domain("http://example.com/2")
    fourth_img_url = Image("http://example.com/4.png")
    second_domain.images.extend([fourth_img_url])

    job = Job([first_domain,second_domain])

    self.assertEqual(job.get_results(), {
        "id": job.id,
        "domains":{
            "http://example.com":[
                "http://example.com/1.png",
                "http://example.com/2.png",
                "http://example.com/3.png"
            ],
            "http://example.com/2":[
                "http://example.com/4.png"
            ]
        }
    })
Ejemplo n.º 13
0
def run_job(credential, gjfstring, jobstring=None, **kwargs):
    results = {
        "jobid": None,
        "error": None,
    }
    try:
        results["cluster"] = credential.cluster.name
        if not credential.user.is_staff:
            results["error"] = "You must be a staff user to submit a job."
            return results
        ssh = get_ssh_connection_obj(credential)
        sftp = get_sftp_connection_obj(credential)
    except:
        results["error"] = "Invalid credential"
        results["cluster"] = None
        logger.info("Invalid credential %s" % credential)
        return results

    with ssh, sftp:
        jobid, error = _run_job(ssh, sftp, gjfstring, jobstring, **kwargs)
        results["jobid"] = jobid
        results["error"] = error
        if not error:
            job = Job(
                credential=credential,
                jobid=jobid,
                **kwargs
            )
            job.save()
        return results
Ejemplo n.º 14
0
def new_job():
    if not g.site.domain == g.user:
        abort(403)

    j = Job()
    if request.method == "POST":
        portfolio = Portfolio.objects.get(site=g.site.domain)
        job_name = request.form.get("name")
        slugs = [__j.slug for __j in Job.objects.filter(site=g.site.domain)]
        counter = 1
        slug = slugify(job_name)
        __slug = slug
        while __slug in slugs:
            counter += 1
            __slug = "%s_%d" % (slug, counter)
        j.slug = __slug
        j.name = job_name
        j.site = g.site.domain
        j.categories = [ c.strip() for c in request.form.get("categories").split(",") ]
        j.intro = request.form.get("intro")
        j.description = request.form.get("description")
        j.slides = []
        texts = request.form.getlist("text")
        image_urls = request.form.getlist("image_url")
        captions = request.form.getlist("caption")
        caption_links = request.form.getlist("caption_link")
        for text, image_url, caption, caption_link in zip(texts, image_urls, captions, caption_links):
            if text or image_url:
                j.slides.append(Slide(text=text, image_url=image_url, caption=caption, caption_link=caption_link))
        j.save()
        portfolio.jobs.append(j)
        portfolio.save()
        return redirect(url_for(".job", slug=j.slug))
    return render_template("edit_job.html", job=j)
Ejemplo n.º 15
0
  def test_job_should_emit_status_for_all_urls(self):
    first_domain = Domain("http://example.com")
    first_domain.crawled = True
    second_domain = Domain("http://example.com/2")
    job = Job([first_domain,second_domain])

    self.assertEqual(job.get_status()["completed"], 1)
    self.assertEqual(job.get_status()["inprogress"], 1)
Ejemplo n.º 16
0
def create():
    try:
        Job.create_job(request.json)
        job = Job.find_by_id(request.json["job_id"])
        return jsonify(job), 201

    except Exception as e:
        print(e)
        return jsonify(error="couldn't add job"), 400
Ejemplo n.º 17
0
def schedule(function, args = None, kwargs = None,
        run_after= None, meta = None):
    """Schedule a tast for execution.
    """
    job = Job(
        name=full_name(function),
            args=dumps(args or []), kwargs=dumps(kwargs or {}),
        meta=dumps(meta or {}), scheduled=run_after)
    job.save()
    return job
Ejemplo n.º 18
0
def create():
	post_data = get_post_data()
	post_data['lead_id'] = parse_endpoint(post_data['lead'], 'leads')

	# saves the job
	job = Job()
	job.build(post_data)
	job.status = 'CREATED'
	job.unique_id = Job.generate_unique_id()

	if job.put():
		# enqueue job to be sent to townflix
		_enqueue_job_creation_message(job)

		pprint.pprint('=== JOB CREATED')

		# mark the lead as converted
		lead = job.lead.get()
		lead.status = 'CONVERTED'
		lead.put()

		create_activity('LEAD_CONVERTED', lead=lead, job=job)
		create_activity('JOB_CREATED', lead=lead, job=job)

		# send a message to property owner
		_enqueue_job_create_message(job)

		# if the lead has been sent by someone
		if lead.sender_broker is not None:
			# send a message to the broker
			_enqueue_broker_job_create_message(job)

		return jsonify(data=job.to_json()), 201
	else:
		return jsonify(data=job.error_messages()), 500
Ejemplo n.º 19
0
def bmanager_post_job(request):
    jsonData =json.loads(request.body)

    job = Job()
    job.basename        = jsonData['job']['basename']
    job.format          = jsonData['job']['format']
    job.input_filename  = jsonData['job']['input_filename']
    job.input_path      = jsonData['job']['input_path']


    try:
        job.profile = Profile.objects.get(name=jsonData['job']['profile'])
    except ObjectDoesNotExist:
        status = http_NOT_FOUND
        return HttpResponse(json.dumps({'message': 'Profile not found'}), status=status, content_type='application/json')

    dest_list = []
    destinations = jsonData['job']['destinations']

    for destination in destinations:
        try:
            dest_list.append(Destination.objects.get(name=destination))
            #job.destinations.add(Destination.objects.get(name=destination))
        except ObjectDoesNotExist:
            status = http_NOT_FOUND
            return HttpResponse(json.dumps({'message': 'Destination not found'}), status=status,content_type='application/json')

    job.save()
    job.destinations = dest_list
    #job.save()

    response = {"job": {"id": job.id, "basename": job.basename}}
    status = http_POST_OK
    return HttpResponse(json.dumps(response), status=status, content_type='application/json')
Ejemplo n.º 20
0
def main():
    while True:
        job = Job.get_queue()
        if job:
            print 'Working on',job['_id']
            work(job)
            job['is_done'] = True
            Job.save(job)
            print 'Done'
        else:
            time.sleep(POLL_TIME)
Ejemplo n.º 21
0
def before_request():
    g.db = connect_db()
    Slot_Conf.set_db(g.db)
    Job.set_db(g.db)
    TimeInfo.set_db(g.db)
    slotStartEnd.set_db(g.db)
    Projects.set_db(g.db)
    Results.set_db(g.db)
    ProjNames.set_db(g.db)
    SlotTimes.set_db(g.db)
    ProjectTimes.set_db(g.db)
Ejemplo n.º 22
0
def jobs_post(request): # FIXME use method POST
    job = Job()
    for field in PUBLIC_FIELDS:
        if field in request.GET:
            if field == 'params':
                job[field] = json.loads(request[field])
            else:
                job[field] = request[field]
    job.save()

    return format_job(job)
Ejemplo n.º 23
0
def job_add(request, event_id, task_id):
    event = get_object_or_404(Event, pk=event_id)
    task = get_object_or_404(Task, pk=task_id)
    #job_user = get_object_or_404(User, pk=user_id)

    #if job_user != user:
    #   return HttpResponseNotAllowed('<h1>Must not add other users!</h1>')
    job = Job(event=event, task = task, user = request.user)
    job.save()
    messages.success(request, _("Took job"))
    return HttpResponseRedirect(reverse('event', args=[event.id]))
Ejemplo n.º 24
0
def create(name, url):
    '''新增'''
    job = Job()
    job.name = name
    job.url = url
    job.create_time = datetime.now()

    session = Session()
    session.add(job)
    session.commit()
    session.close()
Ejemplo n.º 25
0
def before_request():
	g.db = connect_db()
	Slot_Conf.set_db(g.db)
	Job.set_db(g.db) 
	TimeInfo.set_db(g.db)
	slotStartEnd.set_db(g.db)
	Projects.set_db(g.db)
	Results.set_db(g.db)
	ProjNames.set_db(g.db)
	SlotTimes.set_db(g.db)
	ProjectTimes.set_db(g.db)
Ejemplo n.º 26
0
    def submit(self, request):
        job = Job(query=json.dumps(self.cleaned_data['query']))

        try:
            job.save()
        except DatabaseError:
            raise DatabaseIntegrityError()

        if self.cleaned_data['query']['type'] == 'FASTA':
            pass
        else:
            pass
Ejemplo n.º 27
0
    def submit(self, request):
        job = Job(query=json.dumps(self.cleaned_data["query"]))

        try:
            job.save()
        except DatabaseError:
            raise DatabaseIntegrityError()

        if self.cleaned_data["query"]["type"] == "FASTA":
            pass
        else:
            pass
Ejemplo n.º 28
0
def getJobInfo(dom, company):
    '''获取一个职位的招聘信息'''

    job_info = {}
    type_tr = dom('.jobInfoItems tr:eq(0)')
    trtext = type_tr.text()
    trtext = trtext.split(u':') if trtext else []
    if len(trtext) == 2:
        k, v = trtext
        v = v.replace('/', ',')
        job_info[k] = v

    trs = dom('.jobInfoItems tr:gt(1)')
    for tr in trs:
        tr = pq(tr)
        tds = tr('td')
        for td in tds:
            td = pq(td)
            tdtext = td.text().split(u':')
            if len(tdtext) == 2:
                k, v = tdtext
                job_info[k] = v
    
    salary = job_info.get(u'职位月薪')
    if salary:
        sh = re.search(r'(\d+)-(\d+)', salary)
        salary = sh.groups() if sh else (None, None)
    else:
        salary = (None, None)
    quantity = job_info.get(u'招聘人数')
    if quantity:
        sh = re.search(r'(\d+)', quantity)
        quantity = sh.group(0) if sh else None

    job = Job()
    occ_type = job_info.get(u'职位类别')
    occ = Occupational.query.filter(Occupational.type==occ_type).first()
    if not occ:
        occ = Occupational()
        occ.name = 'FILL'
        occ.type = occ_type
        db.session.add(occ)
    job.occupational = occ
    job.type = job_info.get(u'工作性质')
    job.exp = job_info.get(u'工作经验')
    job.manage_exp = job_info.get(u'管理经验')
    job.quantity = quantity
    job.degree = job_info.get(u'最低学历')
    job.salary_low, job.salary_high = salary
    job.description = dom('.jobDes').html()
    job.etag = ''

    return job
Ejemplo n.º 29
0
    def proxy_complete(self):
        if self.uploading is True:
            return

        if self.status.get('builder_status', None) == "BuilderStatus.ABORTING":
            buildid = self.status.get('buildid', None)
            job = Job.selectBy(id=buildid)[0]
            self.complete(job, JobStatus.CANCELED)
        
        if self.status.get('builder_status', None) == 'BuilderStatus.WAITING':
            buildid = self.status.get('build_id', None)
            try:
                job = Job.selectBy(id=buildid)[0]
            except Exception as e:
                print(e)
                return

            if self.status.get('build_status') == "BuildStatus.OK":
                job_status = JobStatus.BUILD_OK
            else:
                job_status = JobStatus.FAILED
                # notify build
                try:
                    _package = job.package.dict()
                    cwd = os.path.join(config['cache']['sources'], _package['pkgname'])
                    command = "git show %s --pretty=%%ae | head -n 1" % _package['hashsum']
                    status, email = functions.getstatusoutput(command, cwd=cwd)
                    if status != 0:
                        email = None

                    command = "git log -1 %s --pretty=%%s | head -n 1" % _package['hashsum']
                    status, subject = functions.getstatusoutput(command, cwd=cwd)
                    if status != 0:
                        subject = None

                    message_text = "Build %(pkgname)s - %(pkgver)s to %(reponame)s" % _package
                    message_text += " [Failed](%s/job/%s)" % (config['runtime']['url'], str(job.id))
                    attachments_text = "Action: %(action)s\nHashsum: %(hashsum)s\n" % _package
                    if subject:
                        attachments_text += "Subject: %s\n" % subject

                    attachments = [{
                        "text": attachments_text,
                        "color": "#ffa500"
                        }]
                    #Notify().notify('bearychat', message_text=message_text,
                    #    author_email=email, message_attachments=attachments)
                    Notify().notify('deepinworknoticebot', message_text=message_text,
                        author_email=email, message_attachments=attachments)
                except Exception as error:
                    print(error)
                
            self.complete(job, job_status)
Ejemplo n.º 30
0
def todayStats():
        slots = []
	#today = time.strftime("%Y-%m-%d")
	 
	#weekbefore = (date.today()-timedelta(6)).strftime('%Y-%m-%d')
	jobEnds = Job.view('statistics/jobEnds',group_level=3,startkey = [today])
        jobStarts = Job.view('statistics/jobStarts',group_level=3,startkey = [today])
        slots = Slot_Conf.view('statistics/Slots',startkey = today)
        times = TimeInfo.view('statistics/completionTime',group = True, startkey = weekbefore)
        data = []
        jobsEnded = {}	
        jobsStarted = {}

	for s in slots:
		jobsEnded[s.slot] = 0
		jobsStarted[s.slot] = 0

        for j in jobEnds:
                jobsEnded[j['key'][1]]=j['value']

        for j in jobStarts:
                jobsStarted[j['key'][1]]=j['value']

        unfinished = 0
        unstarted = 0
        unfinished_list = []
        unstarted_list = []
        completed_list = []
        for s in slots:
                if(jobsEnded[s.slot]!=len(s.platforms)):
                        unfinished+=1
                        unfinished_list.append(s.slot)
                if(jobsStarted[s.slot]!=len(s.platforms)):
                        unstarted+=1
                        unstarted_list.append(s.slot)
                if(jobsStarted[s.slot]==len(s.platforms) and jobsEnded[s.slot]==len(s.platforms)):
                        completed_list.append(s.slot)
        sum = 0
        for t in times:
                if t['key']==today:
                        todaymin = t['value']['min']
                        sum = sum - (t['value']['max'] - t['value']['min'])
                sum = sum + (t['value']['max'] - t['value']['min'])

        avgcompletion = sum/6
        data = []
        all_list = unfinished_list+unstarted_list+completed_list
        data.append({"total":len(slots),"all":all_list,"finished":len(slots)-unfinished,"unfinished":unfinished,"unstarted":unstarted,"todaymin":todaymin,"avgcompletion":avgcompletion,"listofunfinished":unfinished_list,"listofunstarted":unstarted_list,"listofcompleted":completed_list})

        data =json.dumps(data)
   
	return data
Ejemplo n.º 31
0
def schedule(function, args = None, kwargs = None,
        priority = 5, run_after= None, meta = None):
    """Schedule a tast for execution.
    """
    # Too many arguments
    # pylint: disable=R0913
    job = Job(
        name=full_name(function),
            args=dumps(args or []), kwargs=dumps(kwargs or {}),
        meta=dumps(meta or {}), scheduled=run_after,
        priority=priority)
    job.save()
    return job
Ejemplo n.º 32
0
def add(request):
    #########################################################################################
    # 用户操作行为安全保护

    # 计时器
    timer = time.time() - request.session.get('time_stamp',0)

    # 危险操作次数
    action_times = request.session.get('action_times',0)

    # 错误次数是否大于最大
    if action_times >= 1:
        if not check_verify(request):
            return render('verify.html',locals(),context_instance=RequestContext(request))
        else:

            # 重置标志位
            reset(request)
    #########################################################################################
    current_page = 'jobs'

    # 检查用户选择的城市是否存在
    if check_city(request.GET.get('city_name',False)):
        request.session['job_city'] = request.GET.get('city_name')
    else:
        return index(request=request)

    # 打印表单
    if request.method == 'GET':
        form = JobForm()
        return render('jobs_add.html',locals(),context_instance=RequestContext(request))

    # 处理提交数据
    form = JobForm(request.POST)
    if form.is_valid():
        data = form.cleaned_data
        new_job = Job()
        new_job.title = data['title']
        new_job.city = request.session.get('job_city','北京')
        new_job.company = data['company']
        new_job.website = data['website']
        new_job.email = data['email']
        new_job.content = data['content']
        try:
            new_job.save()
        except Exception,e:
            return HttpResponse('保存招聘信息时出现错误:'+str(e))
        else:
            set(request)
            msg = '提交成功,正在等待管理员审核...'
            # 发送信号
            new_job_was_post.send(
                sender = new_job.__class__,
                job = new_job
            )
        return render('posted.html',locals(),context_instance=RequestContext(request))
Ejemplo n.º 33
0
    def scrape_single_position_job(self, job: Job, job_element: WebElement):
        summary_element = self.find_summary_element(job_element,
                                                    'pv-entity__summary-info')

        job.company.name = self.canonize_company_name(
            summary_element.find_element_by_class_name(
                'pv-entity__secondary-title').text)

        position = Position()
        position.title = summary_element.find_element_by_class_name(
            't-16').text.strip()
        position.date_range = self.scrape_date_range(job_element)
        position.location = self.scrape_location(job_element)
        job.add_position(position)
Ejemplo n.º 34
0
def approve(id):
	job = _get_job(id)

	if _change_approval_status(job, 'APPROVED'):
		create_activity('JOB_APPROVED', job=job)

		Job.start_publishing(id)

		if job.tf_job_id is not None:
			tf_complete_job(id, job.tf_job_id)

		return jsonify(data=job.to_json()), 201
	else:
		abort(400, {'message': CANNOT_APPROVE_JOB_MESSAGE })
Ejemplo n.º 35
0
def reset_database():
    DB.drop_all()
    DB.create_all()

    role = Role()
    role.name = 'Administrator'

    user = User()
    user.public_id = 'd38924fb-9417-4a50-b715-01f805c28063'
    # password
    user.password = '******'
    user.name = 'admin'
    user.email = '*****@*****.**'
    user.role = role

    coffee_machine = CoffeeMachine()
    coffee_machine.name = 'Winston'
    coffee_machine.repository = 'hidden-firefly'

    coffee_type = CoffeeType()
    coffee_type.name = 'Arabica'

    coffee_brand = CoffeeBrand()
    coffee_brand.name = 'Dallmayr'

    coffee_product = CoffeeProduct()
    coffee_product.name = 'Dallmayr Prodomo'
    coffee_product.coffee_brand = coffee_brand
    coffee_product.coffee_type = coffee_type

    profile = Profile()
    profile.name = 'Morning'
    profile.water_in_percent = 32 * 1000
    profile.coffee_strength_in_percent = 42
    profile.user = user

    job = Job()
    current_time = time.time()
    job.create_date = current_time
    job.coffee_strength_in_percent = 66
    job.water_in_percent = 44
    job.price = 10
    job.doses = 1
    job.user = user
    job.coffee_machine = coffee_machine
    job.coffee_product = coffee_product

    DB.session.add(job)
    DB.session.commit()
Ejemplo n.º 36
0
 def exitJob(self, ctx):
     for slot in self.stack.pop() :
         job = Job()
         job.source = self.context[-1]
         job.title = self.__strToken(ctx.QUOTE(0))
         job.description = self.__strToken(ctx.QUOTE(1))
         job.start = slot['begin']
         job.end = slot['end']
         job.needs = 1            
         if ctx.needs() != None :
             job.needs = self.__intToken(ctx.needs().NUMBER())
         job.protected = False
         if ctx.getChild(0).getText() == 'protected' :
             job.protected = True
         self.rows.append(job)
Ejemplo n.º 37
0
def get_all_jobs(credentials):
    updates = [Job.get_oldest_update_time(credential=x) for x in credentials]
    # TUNABLE: change time constraint
    if any((timezone.now() - x).seconds > 60 for x in updates):
        jobs = get_jobs(credentials)
    else:
        jobs = []
        for cred in credentials:
            objs = Job.get_running_jobs(credential=cred)
            jobs.append({
                "name": cred.cluster.name,
                "columns": WANTED_COLS,
                "jobs": [x.format() for x in objs],
            })
    return jobs
 def post(self, *args, **kwargs):
     ''' Creates a job based on the parameters '''
     form = Form(
         jobname="Please enter a job name",
         algorithm_uuid="Please select an algorithm",
         hashes="Please provide the target hashes",
     )
     if form.validate(self.request.arguments):
         algo = Algorithm.by_uuid(self.get_argument('algorithm_uuid'))
         user = self.get_current_user()
         if algo is None:
             self.render('cracking/jobs/create.html', 
                 errors=['Invalid algorithm']
             )
         elif Job.by_job_name(self.get_argument('jobname')) is not None:
             self.render('cracking/jobs/create.html', 
                 errors=['Duplicate job name']
             )
         else:
             job = self.create_job(user, algo)
             dispatch = Dispatch.Instance()
             dispatch.refresh()
             self.render("cracking/jobs/created.html", job=job)
     else:
         self.render('cracking/jobs/create.html', errors=form.errors)
Ejemplo n.º 39
0
 def get(self, email):
     q = Job.all()
     q.filter("email =", urllib.unquote(email))
     jobs = q.fetch(BOUND)
     for job in jobs:
         job.delete()
     self.response.out.write(template.render("templates/sorry.html", {}))
Ejemplo n.º 40
0
def run(item_id, job_type):
  inv_item = Inventory.query.get(item_id)

  if inv_item.status == 'pending':
    return 'ERROR: Not ready'

  if inv_item.has_active_jobs(job_type=job_type):
    return 'ERROR: I already have an active job of that type'

  job = Job(job_type=job_type)
  job.set_status('queued')
  inv_item.set_status('active')
  inv_item.jobs.append(job)
  db_session.commit()
  job.run()
  return redirect('/items/{0}'.format(inv_item.id))
 def __queue__(self):
     ''' Starts a job or leaves it in the queue (thread safe) '''
     logging.debug("Attempting to acquire queue mutex ...")
     self.mutex.acquire()
     logging.debug("Successfully acquired queue mutex.")
     queue = list(Job.queue())  # Create a copy of the queue
     for job in queue:
         logging.info("Dispatching job: %s" % job.job_name)
         if len(job) == 0:
             job.status = u"COMPLETED"
             dbsession.add(job)
             dbsession.flush()
         else:
             algo = Algorithm.by_id(job.algorithm_id)
             weapon_systems = WeaponSystem.system_ready(algo)
             if weapon_systems is not None and 0 < len(weapon_systems):
                 logging.info("Weapon systems available: %d" % (
                     len(weapon_systems),
                 ))
                 thread.start_new_thread(
                     self.__crack__, 
                     (job, weapon_systems[0],)
                 )
             else:
                 logging.info("No available weapon systems at this time.")
     self.mutex.release()