##// 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 2 from apps.main.models import Configuration
3 3 from django.core.urlresolvers import reverse
4 4 # Create your models here.
5
5 from celery.execute import send_task
6 from datetime import datetime
6 7 import ast
7 8 import socket
8 9 import json
@@ -297,13 +298,48 class ABSConfiguration(Configuration):
297 298 active_beam = json.loads(self.active_beam)
298 299 new_beams = ABSBeam.objects.filter(abs_conf=self)
299 300 active_beam['active_beam'] = new_beams[0].id
301
300 302 self.active_beam = json.dumps(active_beam)
301 303 self.save()
302 304 #-----For Active Beam-----
305 #-----For Device Status---
306 self.device.status = 3
307 self.device.save()
308 #-----For Device Status---
303 309
304 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 343 def module_conf(self, module_num, beams):
308 344 """
309 345 This function creates beam configurations for one abs module.
@@ -392,13 +428,15 class ABSConfiguration(Configuration):
392 428 #-------------Jueves-------------
393 429 if disconnected_modules == 64:
394 430 self.message = "Could not write ABS Modules"
431 self.device.status = 0
395 432 return False
396 433 else:
397 434 self.message = "ABS Beams List have been sent to ABS Modules"
398 435 beams[0].set_as_activebeam()
399 436
437 self.device.status = 3
400 438 self.module_status = json.dumps(beams_status)
401 self.save()
439
402 440
403 441
404 442 self.save()
@@ -6,19 +6,7 import json
6 6 from datetime import timedelta, datetime
7 7 from celery.task import task
8 8
9 """
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
9 @task(name='task_change_beam')
22 10 def task_change_beam(id_conf):
23 11
24 12 abs_conf = Configuration.objects.get(pk=id_conf)
@@ -29,6 +17,9 def task_change_beam(id_conf):
29 17 now = datetime.utcnow()
30 18 date = now + run_every
31 19
20 if abs_conf.device.status != 3:
21 return abs_conf.device.status
22
32 23 if abs_conf.operation_mode == 0: #Manual Mode
33 24 return 1
34 25
@@ -51,7 +42,7 def task_change_beam(id_conf):
51 42 abs_conf.send_beam_num(1)
52 43 beams_list[0].set_as_activebeam()
53 44 task = task_change_beam.apply_async((abs_conf.pk,), eta=date)
54 print next_beam
45 print beams_list[0]
55 46 i=0
56 47
57 48 else:
@@ -10,7 +10,7 from datetime import datetime
10 10 from time import sleep
11 11 import os
12 12
13 from apps.main.models import Device, Configuration
13 from apps.main.models import Device, Configuration, Experiment
14 14 from apps.main.views import sidebar
15 15
16 16 from .models import ABSConfiguration, ABSBeam
@@ -149,7 +149,7 def abs_conf(request, id_conf):
149 149
150 150 kwargs['title'] = 'ABS Configuration'
151 151 kwargs['suptitle'] = 'Details'
152 kwargs['no_play'] = True
152 #kwargs['no_play'] = True
153 153
154 154 kwargs['button'] = 'Edit Configuration'
155 155 #------------------Active Beam-----------------------
@@ -169,7 +169,7 def abs_conf(request, id_conf):
169 169 kwargs['color_status'] = color_status
170 170 kwargs['module_messages'] = module_messages
171 171
172 kwargs['only_stop'] = True
172 #kwargs['only_stop'] = True
173 173
174 174 ###### SIDEBAR ######
175 175 kwargs.update(sidebar(conf=conf))
General Comments 0
You need to be logged in to leave comments. Login now