@@ -1,19 +1,63 | |||
|
1 | 1 | from __future__ import absolute_import |
|
2 | from celery import task | |
|
3 | from .models import Experiment | |
|
4 | 2 | |
|
5 | #@task | |
|
6 | #def task_start(id_exp): | |
|
3 | from apps.main.models import Configuration | |
|
4 | from .models import ABSBeam | |
|
5 | import json | |
|
6 | from datetime import timedelta, datetime | |
|
7 | from celery.task import task | |
|
7 | 8 | |
|
8 | # exp = Experiment.objects.get(pk=id_exp) | |
|
9 | """ | |
|
10 | @task | |
|
11 | def beam_task(id_conf): | |
|
9 | 12 |
|
|
10 | # return exp.start() | |
|
13 | abs_conf = Configuration.objects.get(pk=id_conf) | |
|
11 | 14 |
|
|
15 | task_change_beam(abs_conf.pk) | |
|
12 | 16 |
|
|
17 | return task_change_beam(abs_conf.pk) | |
|
13 | 18 |
|
|
14 | #@task | |
|
15 | #def task_stop(id_exp): | |
|
19 | """ | |
|
16 | 20 | |
|
17 | # exp = Experiment.objects.get(pk=id_exp) | |
|
21 | @task | |
|
22 | def task_change_beam(id_conf): | |
|
18 | 23 | |
|
19 | # return exp.stop() | |
|
24 | abs_conf = Configuration.objects.get(pk=id_conf) | |
|
25 | beams_list = ABSBeam.objects.filter(abs_conf=abs_conf) | |
|
26 | active_beam = json.loads(abs_conf.active_beam) | |
|
27 | ||
|
28 | run_every = timedelta(seconds=abs_conf.operation_value) | |
|
29 | now = datetime.utcnow() | |
|
30 | date = now + run_every | |
|
31 | ||
|
32 | if abs_conf.operation_mode == 0: #Manual Mode | |
|
33 | return 1 | |
|
34 | ||
|
35 | if active_beam: | |
|
36 | current_beam = ABSBeam.objects.get(pk=active_beam['active_beam']) | |
|
37 | i=0 | |
|
38 | for beam in beams_list: | |
|
39 | if beam == current_beam: | |
|
40 | i+=1 | |
|
41 | break | |
|
42 | i+=1 | |
|
43 | ||
|
44 | if i < len(beams_list): | |
|
45 | next_beam = beams_list[i] | |
|
46 | abs_conf.send_beam_num(i+1) | |
|
47 | next_beam.set_as_activebeam() | |
|
48 | task = task_change_beam.apply_async((abs_conf.pk,), eta=date) | |
|
49 | print next_beam | |
|
50 | else: | |
|
51 | abs_conf.send_beam_num(1) | |
|
52 | beams_list[0].set_as_activebeam() | |
|
53 | task = task_change_beam.apply_async((abs_conf.pk,), eta=date) | |
|
54 | print next_beam | |
|
55 | i=0 | |
|
56 | ||
|
57 | else: | |
|
58 | abs_conf.send_beam_num(1) | |
|
59 | beams_list[0].set_as_activebeam() | |
|
60 | task = task_change_beam.apply_async((abs_conf.pk,), eta=date) | |
|
61 | ||
|
62 | ||
|
63 | return 2 |
General Comments 0
You need to be logged in to leave comments.
Login now