##// END OF EJS Templates
Version con fecha de campanhas corregida pero falta lanzar las tareas e celery rev2
gonzalesluisfrancisco -
r346:f3a35356b00a
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
@@ -420,9 +420,10 class ABSConfiguration(Configuration):
420 420 try:
421 421 data, address = sock.recvfrom(1024)
422 422 print (address, data)
423
423 data = data.decode("utf-8")
424 424 if data == '1':
425 425 status[int(address[0][10:])-1] = '3'
426 #print (int(address[0][10:])-1)
426 427 elif data == '0':
427 428 status[int(address[0][10:])-1] = '1'
428 429 except socket.timeout:
@@ -477,6 +478,7 class ABSConfiguration(Configuration):
477 478 print('Inicia intento de salvar device.status')
478 479 self.device.status = 3
479 480 self.module_status = ''.join(status)
481 #print(status)
480 482 self.save()
481 483 print('Estatus salvado')
482 484 conf_active, __ = ABSActive.objects.get_or_create(pk=1)
@@ -6,6 +6,9 import json
6 6 from datetime import timedelta, datetime
7 7 from celery.task import task
8 8
9 from celery.utils.log import get_task_logger
10 logger = get_task_logger(__name__)
11
9 12 @task(name='task_change_beam')
10 13 def task_change_beam(id_conf):
11 14
@@ -37,12 +40,12 def task_change_beam(id_conf):
37 40 abs_conf.send_beam_num(i+1)
38 41 next_beam.set_as_activebeam()
39 42 task = task_change_beam.apply_async((abs_conf.pk,), eta=date)
40 print next_beam
43 print (next_beam)
41 44 else:
42 45 abs_conf.send_beam_num(1)
43 46 beams_list[0].set_as_activebeam()
44 47 task = task_change_beam.apply_async((abs_conf.pk,), eta=date)
45 print beams_list[0]
48 print (beams_list[0])
46 49 i=0
47 50
48 51 else:
1 NO CONTENT: modified file
1 NO CONTENT: modified file
@@ -5,6 +5,13 from celery import task
5 5 from datetime import timedelta, datetime
6 6
7 7 from .models import Experiment
8 from celery import Celery
9
10 from celery.utils.log import get_task_logger
11
12 from django.utils import timezone
13
14 logger = get_task_logger(__name__)
8 15
9 16 @task
10 17 def task_start(id_exp):
@@ -17,6 +24,9 def task_start(id_exp):
17 24 now = datetime.now()
18 25 start = datetime.combine(now.date(), exp.start_time)
19 26 end = datetime.combine(now.date(), exp.end_time)
27 print(now)
28 print(start)
29 print(end)
20 30 if end < start:
21 31 end += timedelta(1)
22 32 try:
@@ -26,7 +36,7 def task_start(id_exp):
26 36 print('Error')
27 37 exp.status = 0
28 38 if exp.status == 2:
29 task = task_stop.apply_async((id_exp,), eta=end+timedelta(hours=5))
39 task = task_stop.apply_async((id_exp,),eta=end) #Antiguo eta=end+timedelta(hours=5))
30 40 exp.task = task.id
31 41 exp.save()
32 42 return exp.status
@@ -44,7 +54,7 def task_stop(id_exp):
44 54
45 55 now = datetime.now()
46 56 start = datetime.combine(now.date()+timedelta(1), exp.start_time)
47 task = task_start.apply_async((id_exp, ), eta=start+timedelta(hours=5))
57 task = task_start.apply_async((id_exp, ), eta=start) #Antiguo eta=start+timedelta(hours=5))
48 58 exp.task = task.id
49 59 exp.status = 3
50 60 exp.save()
@@ -53,7 +63,7 def task_stop(id_exp):
53 63 #Task to get status
54 64 @task
55 65 def task_status(id_exp):
56
66 print ("task status"+str(id_exp))
57 67 exp = Experiment.objects.get(pk=id_exp)
58 68 if exp.status==2:
59 69 run_every = timedelta(minutes=1)
@@ -46,6 +46,7 urlpatterns = (
46 46
47 47 path('experiment/<int:id_exp>/new_dev_conf/', views.dev_conf_new, name='url_add_dev_conf'),
48 48 path('experiment/<int:id_exp>/new_dev_conf/<int:id_dev>/', views.dev_conf_new, name='url_add_dev_conf'),
49
49 50 path('dev_conf/', views.dev_confs, name='url_dev_confs'),
50 51 path('dev_conf/<int:id_conf>/', views.dev_conf, name='url_dev_conf'),
51 52 path('dev_conf/<int:id_conf>/edit/', views.dev_conf_edit, name='url_edit_dev_conf'),
@@ -13,6 +13,8 from django.contrib import messages
13 13 from django.http.request import QueryDict
14 14 from django.contrib.auth.decorators import login_required, user_passes_test
15 15
16 from django.utils.timezone import is_aware
17
16 18 try:
17 19 from urllib.parse import urlencode
18 20 except ImportError:
@@ -21,8 +23,6 except ImportError:
21 23 from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm
22 24 from .forms import OperationSearchForm, FilterForm, ChangeIpForm
23 25
24 from .tasks import task_start
25
26 26 from apps.rc.forms import RCConfigurationForm, RCLineCode, RCMixConfigurationForm
27 27 from apps.dds.forms import DDSConfigurationForm
28 28 from apps.jars.forms import JARSConfigurationForm
@@ -41,9 +41,10 from apps.rc.models import RCConfiguration, RCLine, RCLineType, RCClock
41 41 from apps.dds.models import DDSConfiguration
42 42 from apps.dds_rest.models import DDSRestConfiguration
43 43
44 from .tasks import task_start
44 45 from radarsys.celery import app
45 46
46
47 #comentario test
47 48 CONF_FORMS = {
48 49 'rc': RCConfigurationForm,
49 50 'dds': DDSConfigurationForm,
@@ -1793,9 +1794,21 def radar_start(request, id_camp, id_radar):
1793 1794 campaign = get_object_or_404(Campaign, pk=id_camp)
1794 1795 experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments']
1795 1796 now = datetime.now()
1797
1796 1798 for exp in experiments:
1799 #app.control.revoke(exp.task)
1800 print(exp.status)
1797 1801 start = datetime.combine(datetime.now().date(), exp.start_time)
1798 1802 end = datetime.combine(datetime.now().date(), exp.end_time)
1803 print(exp.start_time)
1804 print(exp.end_time)
1805
1806 print(start)
1807 print(end)
1808 print(is_aware(start))
1809 print(campaign.start_date)
1810 print(campaign.end_date)
1811 print(is_aware(campaign.start_date))
1799 1812 if end < start:
1800 1813 end += timedelta(1)
1801 1814
@@ -1814,8 +1827,9 def radar_start(request, id_camp, id_radar):
1814 1827 continue
1815 1828
1816 1829 app.control.revoke(exp.task)
1817
1830 print("Llego luego del revoke")
1818 1831 if now > start and now <= end:
1832 print("Caso now >start and <end")
1819 1833 task = task_start.delay(exp.id)
1820 1834 exp.status = task.wait()
1821 1835 if exp.status == 0:
@@ -1823,12 +1837,11 def radar_start(request, id_camp, id_radar):
1823 1837 if exp.status == 2:
1824 1838 messages.success(request, 'Experiment {} started'.format(exp))
1825 1839 else:
1826 task = task_start.apply_async(
1827 (exp.pk, ), eta=start+timedelta(hours=5))
1840 print("Caso now < start o >end")
1841 task = task_start.apply_async((exp.pk, ), eta=start)#start+timedelta(hours=5))
1828 1842 exp.task = task.id
1829 1843 exp.status = 3
1830 messages.success(
1831 request, 'Experiment {} programmed to start at {}'.format(exp, start))
1844 messages.success(request, 'Experiment {} programmed to start at {}'.format(exp, start))
1832 1845
1833 1846 exp.save()
1834 1847
@@ -1840,12 +1853,16 def radar_stop(request, id_camp, id_radar):
1840 1853
1841 1854 campaign = get_object_or_404(Campaign, pk=id_camp)
1842 1855 experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments']
1843
1856 print("Ingreso en stop radar_stop")
1844 1857 for exp in experiments:
1845 1858
1846 1859 if exp.task:
1860 print("Ingreso antes de revoke stop")
1847 1861 app.control.revoke(exp.task)
1848 if exp.status == 2:
1862
1863
1864 if exp.status == 2: #status 2 es started
1865 print("llama a exp.stop")
1849 1866 exp.stop()
1850 1867 messages.warning(request, 'Experiment {} stopped'.format(exp))
1851 1868 exp.status = 1
@@ -1861,8 +1878,11 def radar_refresh(request, id_camp, id_radar):
1861 1878 experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments']
1862 1879
1863 1880 i = app.control.inspect()
1864 scheduled = i.scheduled().values()[0]
1865 revoked = i.revoked().values()[0]
1881 print(i)
1882 print(i.scheduled())
1883 print(i.scheduled().values())
1884 scheduled = list(i.scheduled().values())[0]
1885 revoked = list(i.revoked().values())[0]
1866 1886
1867 1887 for exp in experiments:
1868 1888 if exp.task in revoked:
@@ -1880,14 +1900,14 def radar_refresh(request, id_camp, id_radar):
1880 1900 def revoke_tasks(request, id_camp):
1881 1901
1882 1902 i = app.control.inspect()
1883 scheduled = i.scheduled().values()[0]
1884 revoked = i.revoked().values()[0]
1903 scheduled = list(i.scheduled().values())[0]
1904 revoked = list(i.revoked().values())[0]
1885 1905
1886 1906 for t in scheduled:
1887 1907 if t['request']['id'] in revoked:
1888 1908 continue
1889 1909 app.control.revoke(t['request']['id'])
1890 exp = Experiment.objects.get(pk=eval(t['request']['args'])[0])
1910 exp = Experiment.objects.get(pk=eval(str(t['request']['args']))[0])
1891 1911 eta = t['eta']
1892 1912 task = t['request']['name'].split('.')[-1]
1893 1913 messages.warning(request, 'Scheduled {} at {} for experiment {} revoked'.format(task, eta, exp.name))
@@ -1898,13 +1918,13 def revoke_tasks(request, id_camp):
1898 1918 def show_tasks(request, id_camp):
1899 1919
1900 1920 i = app.control.inspect()
1901 scheduled = i.scheduled().values()[0]
1902 revoked = i.revoked().values()[0]
1921 scheduled = list(i.scheduled().values())[0]
1922 revoked = list(i.revoked().values())[0]
1903 1923
1904 1924 for t in scheduled:
1905 1925 if t['request']['id'] in revoked:
1906 1926 continue
1907 exp = Experiment.objects.get(pk=eval(t['request']['args'])[0])
1927 exp = Experiment.objects.get(pk=eval(str(t['request']['args']))[0])
1908 1928 eta = t['eta']
1909 1929 task = t['request']['name'].split('.')[-1]
1910 1930 messages.success(request, 'Task {} scheduled at {} for experiment {}'.format(task, eta, exp.name))
@@ -6,7 +6,7 from django.conf import settings
6 6 # set the default Django settings module for the 'celery' program.
7 7 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'radarsys.settings')
8 8 app = Celery('radarsys')
9
9 app.conf.timezone = 'America/Lima'
10 10 # Using a string here means the worker will not have to
11 11 # pickle the object when using Windows.
12 12 app.config_from_object('django.conf:settings')
@@ -105,14 +105,14 DATABASES = {
105 105
106 106 LANGUAGE_CODE = 'en-us'
107 107
108 USE_TZ = False
109
108 110 TIME_ZONE = os.environ.get('TZ', 'America/Lima')
109 111
110 112 USE_I18N = True
111 113
112 114 USE_L10N = True
113 115
114 USE_TZ = False
115
116 116 # Static files (CSS, JavaScript, Images)
117 117 # https://docs.djangoproject.com/en/1.8/howto/static-files/
118 118
@@ -129,7 +129,7 STATICFILES_FINDERS = (
129 129
130 130 # Celery stuff
131 131 REDIS_HOST = os.environ.get('REDIS_HOST', '127.0.0.1')
132 REDIS_PORT = os.environ.get('REDIS_PORT', 6300)
132 REDIS_PORT = os.environ.get('REDIS_PORT', 6379)
133 133
134 134 BROKER_TRANSPORT = 'redis'
135 135 BROKER_URL = 'redis://{}:{}/0'.format(REDIS_HOST, REDIS_PORT)
@@ -140,3 +140,4 CELERY_ACCEPT_CONTENT = ['application/json']
140 140 CELERY_TASK_SERIALIZER = 'json'
141 141 CELERY_RESULT_SERIALIZER = 'json'
142 142 CELERY_ENABLE_UTC = False
143 CELERY_TIMEZONE = 'America/Lima'
General Comments 0
You need to be logged in to leave comments. Login now