##// END OF EJS Templates
Task #769: Implementacion Scheduler para ABS, Task #717: Implementacion de start_device() y stop_device()...
Fiorella Quino -
r205:2b52673784ab
parent child
Show More
@@ -2,7 +2,8 from django.db import models
2 from apps.main.models import Configuration
2 from apps.main.models import Configuration
3 from django.core.urlresolvers import reverse
3 from django.core.urlresolvers import reverse
4 # Create your models here.
4 # Create your models here.
5
5 from celery.execute import send_task
6 from datetime import datetime
6 import ast
7 import ast
7 import socket
8 import socket
8 import json
9 import json
@@ -297,13 +298,48 class ABSConfiguration(Configuration):
297 active_beam = json.loads(self.active_beam)
298 active_beam = json.loads(self.active_beam)
298 new_beams = ABSBeam.objects.filter(abs_conf=self)
299 new_beams = ABSBeam.objects.filter(abs_conf=self)
299 active_beam['active_beam'] = new_beams[0].id
300 active_beam['active_beam'] = new_beams[0].id
301
300 self.active_beam = json.dumps(active_beam)
302 self.active_beam = json.dumps(active_beam)
301 self.save()
303 self.save()
302 #-----For Active Beam-----
304 #-----For Active Beam-----
305 #-----For Device Status---
306 self.device.status = 3
307 self.device.save()
308 #-----For Device Status---
303
309
304 return self
310 return self
305
311
306
312
313 def start_device(self):
314
315 if self.device.status == 3:
316
317 try:
318 #self.write_device()
319 send_task('task_change_beam', [self.id],)
320 self.message = 'ABS running'
321
322 except Exception as e:
323 self.message = str(e)
324 return False
325
326 return True
327
328 else:
329 self.message = 'Please, select Write ABS Device first.'
330 return False
331
332
333 def stop_device(self):
334
335 self.device.status = 2
336 self.device.save()
337 self.message = 'ABS has been stopped.'
338 self.save()
339
340 return True
341
342
307 def module_conf(self, module_num, beams):
343 def module_conf(self, module_num, beams):
308 """
344 """
309 This function creates beam configurations for one abs module.
345 This function creates beam configurations for one abs module.
@@ -392,13 +428,15 class ABSConfiguration(Configuration):
392 #-------------Jueves-------------
428 #-------------Jueves-------------
393 if disconnected_modules == 64:
429 if disconnected_modules == 64:
394 self.message = "Could not write ABS Modules"
430 self.message = "Could not write ABS Modules"
431 self.device.status = 0
395 return False
432 return False
396 else:
433 else:
397 self.message = "ABS Beams List have been sent to ABS Modules"
434 self.message = "ABS Beams List have been sent to ABS Modules"
398 beams[0].set_as_activebeam()
435 beams[0].set_as_activebeam()
399
436
437 self.device.status = 3
400 self.module_status = json.dumps(beams_status)
438 self.module_status = json.dumps(beams_status)
401 self.save()
439
402
440
403
441
404 self.save()
442 self.save()
@@ -6,19 +6,7 import json
6 from datetime import timedelta, datetime
6 from datetime import timedelta, datetime
7 from celery.task import task
7 from celery.task import task
8
8
9 """
9 @task(name='task_change_beam')
10 @task
11 def beam_task(id_conf):
12
13 abs_conf = Configuration.objects.get(pk=id_conf)
14
15 task_change_beam(abs_conf.pk)
16
17 return task_change_beam(abs_conf.pk)
18
19 """
20
21 @task
22 def task_change_beam(id_conf):
10 def task_change_beam(id_conf):
23
11
24 abs_conf = Configuration.objects.get(pk=id_conf)
12 abs_conf = Configuration.objects.get(pk=id_conf)
@@ -29,6 +17,9 def task_change_beam(id_conf):
29 now = datetime.utcnow()
17 now = datetime.utcnow()
30 date = now + run_every
18 date = now + run_every
31
19
20 if abs_conf.device.status != 3:
21 return abs_conf.device.status
22
32 if abs_conf.operation_mode == 0: #Manual Mode
23 if abs_conf.operation_mode == 0: #Manual Mode
33 return 1
24 return 1
34
25
@@ -51,7 +42,7 def task_change_beam(id_conf):
51 abs_conf.send_beam_num(1)
42 abs_conf.send_beam_num(1)
52 beams_list[0].set_as_activebeam()
43 beams_list[0].set_as_activebeam()
53 task = task_change_beam.apply_async((abs_conf.pk,), eta=date)
44 task = task_change_beam.apply_async((abs_conf.pk,), eta=date)
54 print next_beam
45 print beams_list[0]
55 i=0
46 i=0
56
47
57 else:
48 else:
@@ -10,7 +10,7 from datetime import datetime
10 from time import sleep
10 from time import sleep
11 import os
11 import os
12
12
13 from apps.main.models import Device, Configuration
13 from apps.main.models import Device, Configuration, Experiment
14 from apps.main.views import sidebar
14 from apps.main.views import sidebar
15
15
16 from .models import ABSConfiguration, ABSBeam
16 from .models import ABSConfiguration, ABSBeam
@@ -149,7 +149,7 def abs_conf(request, id_conf):
149
149
150 kwargs['title'] = 'ABS Configuration'
150 kwargs['title'] = 'ABS Configuration'
151 kwargs['suptitle'] = 'Details'
151 kwargs['suptitle'] = 'Details'
152 kwargs['no_play'] = True
152 #kwargs['no_play'] = True
153
153
154 kwargs['button'] = 'Edit Configuration'
154 kwargs['button'] = 'Edit Configuration'
155 #------------------Active Beam-----------------------
155 #------------------Active Beam-----------------------
@@ -169,7 +169,7 def abs_conf(request, id_conf):
169 kwargs['color_status'] = color_status
169 kwargs['color_status'] = color_status
170 kwargs['module_messages'] = module_messages
170 kwargs['module_messages'] = module_messages
171
171
172 kwargs['only_stop'] = True
172 #kwargs['only_stop'] = True
173
173
174 ###### SIDEBAR ######
174 ###### SIDEBAR ######
175 kwargs.update(sidebar(conf=conf))
175 kwargs.update(sidebar(conf=conf))
General Comments 0
You need to be logged in to leave comments. Login now