本文整理汇总了Python中jobs.models.Job类的典型用法代码示例。如果您正苦于以下问题:Python Job类的具体用法?Python Job怎么用?Python Job使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Job类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
def handle(self, *args, **options):
listings = self.get_for_page(1)
jobs = Job.objects.all()
for job in jobs:
job.delete()
for listing in listings:
try:
location = listing['company']['location']['city']
except:
location = ''
try:
company = str(listing['company']['name'])
except:
company = ''
newjob = Job(title=listing['title'],
company=company,
location=location,
url=listing['url'],
data=json.dumps(listing),
created=listing['post_date'])
newjob.save()
示例2: test_do_work
def test_do_work(self):
response = self.client.post(reverse('jobs.start'), {
'job_name': 'counter'
})
json_response = simplejson.loads(response.content)
self.assert_json_success(json_response)
job_key = json_response['job_key']
# work the counter three times:
response = self.client.post(reverse('jobs.work'), {
'job_key': job_key
})
json_response = simplejson.loads(response.content)
self.assert_json_success(json_response)
job = Job.all().filter('job_name =', 'counter')[0]
self.assertEqual(simplejson.loads(job.result), {'count':1})
self.assertEqual(json_response['finished'], False)
response = self.client.post(reverse('jobs.work'), {
'job_key': job_key
})
json_response = simplejson.loads(response.content)
self.assert_json_success(json_response)
job = Job.all().filter('job_name =', 'counter')[0]
self.assertEqual(simplejson.loads(job.result), {'count':2})
self.assertEqual(json_response['finished'], False)
response = self.client.post(reverse('jobs.work'), {
'job_key': job_key
})
json_response = simplejson.loads(response.content)
self.assert_json_success(json_response)
job = Job.all().filter('job_name =', 'counter')[0]
self.assertEqual(simplejson.loads(job.result), {'count':3})
self.assertEqual(json_response['finished'], True)
示例3: run
def run(job, *args, **kwargs):
try:
servers = job.server_set.all()
for server in servers:
job.set_progress("Checking server {} for snapshots...".format(server))
snapshots = ServerSnapshot.objects.filter(server_id=server.id)
if not snapshots:
job.set_progress('No snapshots exist for server {}'.format(server))
continue
logger.info("Found snapshot, noting for deletion...")
job_params = DeleteSnapshotsParameters.objects.create()
job_params.snapshots.add(*snapshots)
logger.info("Creating job...")
child_job = Job(
type="delete_snapshots",
job_parameters=job_params,
owner=job.owner,
parent_job=job,
)
child_job.save()
child_job.server_set.add(server)
msg = (' Job #{} has been created to delete {} snapshot{} from server '
'{}.').format(
child_job.pk, len(snapshots),
's' if len(snapshots) > 1 else '', server)
job.set_progress(msg)
job.set_progress('Finished looking for snapshots on servers. Check child' +
' job(s) for progress updates.')
except Exception as err:
return ('FAILURE', '', err)
return ('', '', '')
示例4: test_work
def test_work(self):
job = Job(job_name='some-job')
job.put()
response = self.client.post(reverse('jobs.work'), {
'job_key': str(job.key()),
'params': '{}'
})
self.assertEqual(response.status_code, 403)
示例5: post
def post(self, request):
json_data = json.loads(request.body)
company = Company.objects.get(user=request.user)
job = Job(**json_data)
job.company = company
job.user = request.user
job.save()
return JsonResponse({"status": "ok", "id": job.id, 'msg': ''})
示例6: create_file_job
def create_file_job(name, sf_id, *args, **kwargs):
"""MD5, backup, etc"""
jobargs = [sf_id] + list(args)
job = Job(funcname=name, jobtype=jobmap[name]['type'],
timestamp=timezone.now(),
state=Jobstates.PENDING, args=json.dumps(jobargs),
kwargs=json.dumps(kwargs))
job.save()
FileJob.objects.create(storedfile_id=sf_id, job_id=job.id)
return job
示例7: store_ds_job
def store_ds_job(name, prejob_args, **kwargs):
pjres = jobmap[name]['getfns'](*prejob_args)
sf_ids = [x.id for x in pjres]
jobargs = prejob_args + sf_ids
job = Job(funcname=name, jobtype=jobmap[name]['type'],
timestamp=timezone.now(),
state=Jobstates.PENDING, args=json.dumps(jobargs),
kwargs=json.dumps(kwargs))
job.save()
FileJob.objects.bulk_create([FileJob(storedfile_id=sf_id, job_id=job.id) for sf_id in sf_ids])
return job
示例8: test_only_admin_can_access
def test_only_admin_can_access(self):
self.client.logout()
assert self.client.login(email="[email protected]", roles=[roles.DJ])
r = self.client.post(reverse("jobs.start"), data={"job_name": "build-trafficlog-report"})
eq_(r.status_code, 403)
job = Job(job_name="build-trafficlog-report")
job.put()
r = self.client.post(reverse("jobs.work"), data={"job_key": job.key(), "params": "{}"})
eq_(r.status_code, 403)
r = self.client.post(reverse("jobs.product", args=[str(job.key())]))
eq_(r.status_code, 403)
示例9: create
def create(request):
if request.method == 'POST':
form = JobForm(request.POST)
if form.is_valid():
job = Job(**form.cleaned_data)
if users.is_current_user_admin():
job.publish()
job.put()
return HttpResponseRedirect('/jobs/my')
else:
form = JobForm()
return _custom_render_to_response('job_form.html', {'form': form, 'title': 'Add new job'})
示例10: test_only_admin_can_access
def test_only_admin_can_access(self):
self.client.logout()
assert self.client.login(email="[email protected]",
roles=[roles.DJ])
r = self.client.post(reverse('jobs.start'),
data={'job_name': 'build-trafficlog-report'})
eq_(r.status_code, 403)
job = Job(job_name='build-trafficlog-report')
job.put()
r = self.client.post(reverse('jobs.work'),
data={'job_key': job.key(),
'params': '{}'})
eq_(r.status_code, 403)
r = self.client.post(reverse('jobs.product', args=[str(job.key())]))
eq_(r.status_code, 403)
示例11: setUp
def setUp(self):
self.central = pytz.timezone('US/Central')
self.now = datetime.datetime.now(tz=self.central)
self.race = Race(race_name='Test Race', race_type=Race.RACE_TYPE_FINALS, race_start_time=self.now)
self.race.save()
self.race_control = RaceControl(current_race=self.race)
self.race_control.save()
self.pick_checkpoint = Checkpoint(checkpoint_number=1, checkpoint_name="Test Checkpoint 1")
self.pick_checkpoint.save()
self.drop_checkpoint = Checkpoint(checkpoint_number=2, checkpoint_name="Test Checkpoint 2")
self.drop_checkpoint.save()
self.other_checkpoint = Checkpoint(checkpoint_number=3, checkpoint_name="Test Checkpoint 3")
self.other_checkpoint.save()
self.ready_now_job = Job(job_id=1, race=self.race, pick_checkpoint=self.pick_checkpoint, drop_checkpoint=self.drop_checkpoint, minutes_ready_after_start=0)
self.ready_now_job.save()
self.racer = Racer(racer_number=320, first_name='Doug', last_name='Suriano', category=Racer.RACER_CATEGORY_MESSENGER)
self.racer.save()
self.raceentry = RaceEntry(racer=self.racer, race=self.race)
self.raceentry.save()
self.run = Run(pk=1, job=self.ready_now_job, race_entry=self.raceentry, status=Run.RUN_STATUS_PICKED, utc_time_picked=datetime.datetime.now(tz=pytz.utc))
self.run.save()
示例12: _get_job_or_404
def _get_job_or_404(job_id):
job = Job.get_by_id(int(job_id))
current_user = users.get_current_user() # only job owner or admin can edit, check or delete the job
if job and job.owned_by(current_user, users.is_current_user_admin()):
return job
else:
raise Http404
示例13: do_job_work
def do_job_work(request):
init_jobs()
try:
job = Job.get(request.POST['job_key'])
params = request.POST.get('params', '{}')
worker = get_worker(job.job_name)
if worker['pre_request']:
early_response = worker['pre_request'](request)
if early_response is not None:
return early_response
if job.result:
result_for_worker = simplejson.loads(job.result)
else:
result_for_worker = None
finished, result = worker['callback'](result_for_worker,
simplejson.loads(params))
job.result = simplejson.dumps(result)
job.save()
except:
traceback.print_exc()
raise
@as_json
def data(request):
return {
'finished': finished,
'success': True
}
return data(request)
示例14: show
def show(request, job_id):
job = Job.get_by_id(int(job_id))
if not job:
raise Http404
if not job.is_published: # only job owner or admin can view unpublished jobs
if not job.owned_by(users.get_current_user(), users.is_current_user_admin()):
raise Http404
return _custom_render_to_response('show_job.html', {'job': job, 'title': job.title})
示例15: obj_update
def obj_update(self, bundle, **kwargs):
"""
Update to deactive mostly
"""
try:
if 'deactivate' in bundle.data.keys() and bundle.data['deactivate']:
existing_job = Job.objects.get(id=bundle.data['job_id'])
existing_job.deactivate = True
existing_job.save()
bundle.obj = existing_job
else:
company = Company.objects.get(id=bundle.data['company_id'])
new_job = Job(name=bundle.data['name'], job_type=bundle.data['job_type'], location=bundle.data['location'], description=bundle.data['description'], company=company)
new_job.save()
bundle.obj = new_job
except Exception, e:
print e
raise e