mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 01:21:21 +03:00
Integrate main schedules resource
Integrated scheduled jobs list Implement updating ancillary details on dependent models Further cleanup
This commit is contained in:
parent
7237d313d2
commit
799e8d30ba
@ -1310,10 +1310,12 @@ class ScheduleSerializer(BaseSerializer):
|
|||||||
def get_related(self, obj):
|
def get_related(self, obj):
|
||||||
res = super(ScheduleSerializer, self).get_related(obj)
|
res = super(ScheduleSerializer, self).get_related(obj)
|
||||||
res.update(dict(
|
res.update(dict(
|
||||||
#unified_jobs = reverse('api:schedule_unified_jobs_list', args=(obj.pk,)),
|
unified_jobs = reverse('api:schedule_unified_jobs_list', args=(obj.pk,)),
|
||||||
))
|
))
|
||||||
if obj.unified_job_template and obj.unified_job_template.active:
|
if obj.unified_job_template and obj.unified_job_template.active:
|
||||||
res['unified_job_template'] = obj.unified_job_template.get_absolute_url()
|
#TODO: Figure out why we have to do this
|
||||||
|
ujt = UnifiedJobTemplate.objects.get(id=obj.unified_job_template.id)
|
||||||
|
res['unified_job_template'] = ujt.get_absolute_url() #obj.unified_job_template.get_absolute_url()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def validate_rrule(self, attrs, source):
|
def validate_rrule(self, attrs, source):
|
||||||
|
@ -158,6 +158,7 @@ job_event_urls = patterns('awx.api.views',
|
|||||||
schedule_urls = patterns('awx.api.views',
|
schedule_urls = patterns('awx.api.views',
|
||||||
url(r'^$', 'schedule_list'),
|
url(r'^$', 'schedule_list'),
|
||||||
url(r'^(?P<pk>[0-9]+)/$', 'schedule_detail'),
|
url(r'^(?P<pk>[0-9]+)/$', 'schedule_detail'),
|
||||||
|
url(r'^(?P<pk>[0-9]+)/jobs/$', 'schedule_unified_jobs_list'),
|
||||||
)
|
)
|
||||||
|
|
||||||
activity_stream_urls = patterns('awx.api.views',
|
activity_stream_urls = patterns('awx.api.views',
|
||||||
@ -171,7 +172,7 @@ v1_urls = patterns('awx.api.views',
|
|||||||
url(r'^authtoken/$', 'auth_token_view'),
|
url(r'^authtoken/$', 'auth_token_view'),
|
||||||
url(r'^me/$', 'user_me_list'),
|
url(r'^me/$', 'user_me_list'),
|
||||||
url(r'^dashboard/$', 'dashboard_view'),
|
url(r'^dashboard/$', 'dashboard_view'),
|
||||||
url(r'^schedules/$', include(schedule_urls)),
|
url(r'^schedules/', include(schedule_urls)),
|
||||||
url(r'^organizations/', include(organization_urls)),
|
url(r'^organizations/', include(organization_urls)),
|
||||||
url(r'^users/', include(user_urls)),
|
url(r'^users/', include(user_urls)),
|
||||||
url(r'^projects/', include(project_urls)),
|
url(r'^projects/', include(project_urls)),
|
||||||
|
@ -238,7 +238,7 @@ class DashboardView(APIView):
|
|||||||
'total': job_template_list.count()}
|
'total': job_template_list.count()}
|
||||||
return Response(data)
|
return Response(data)
|
||||||
|
|
||||||
class ScheduleList(ListCreateAPIView):
|
class ScheduleList(ListAPIView):
|
||||||
|
|
||||||
view_name = "Schedules"
|
view_name = "Schedules"
|
||||||
model = Schedule
|
model = Schedule
|
||||||
@ -251,6 +251,14 @@ class ScheduleDetail(RetrieveUpdateDestroyAPIView):
|
|||||||
serializer_class = ScheduleSerializer
|
serializer_class = ScheduleSerializer
|
||||||
new_in_148 = True
|
new_in_148 = True
|
||||||
|
|
||||||
|
class ScheduleUnifiedJobsList(SubListAPIView):
|
||||||
|
|
||||||
|
model = UnifiedJob
|
||||||
|
serializer_class = UnifiedJobSerializer
|
||||||
|
parent_model = Schedule
|
||||||
|
relationship = ''
|
||||||
|
view_name = 'Schedule Jobs List'
|
||||||
|
|
||||||
class AuthTokenView(APIView):
|
class AuthTokenView(APIView):
|
||||||
|
|
||||||
authentication_classes = []
|
authentication_classes = []
|
||||||
|
@ -23,6 +23,7 @@ class Schedule(CommonModel):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
|
ordering = ['-next_run']
|
||||||
|
|
||||||
objects = ScheduleManager()
|
objects = ScheduleManager()
|
||||||
|
|
||||||
@ -53,21 +54,24 @@ class Schedule(CommonModel):
|
|||||||
editable=False,
|
editable=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def __unicode__(self):
|
||||||
return reverse('api:schedule_list')
|
return u'%s_t%s_%s_%s' % (self.name, self.unified_job_template.id, self.id, self.next_run)
|
||||||
#return reverse('api:schedule_detail', args=(self.pk,))
|
|
||||||
|
|
||||||
def update_dt_elements(self):
|
def get_absolute_url(self):
|
||||||
|
return reverse('api:schedule_detail', args=(self.pk,))
|
||||||
|
|
||||||
|
def update_computed_fields(self):
|
||||||
future_rs = dateutil.rrule.rrulestr(self.rrule, forceset=True)
|
future_rs = dateutil.rrule.rrulestr(self.rrule, forceset=True)
|
||||||
next_run_actual = future_rs.after(now())
|
next_run_actual = future_rs.after(now())
|
||||||
|
|
||||||
self.next_run = next_run_actual
|
self.next_run = next_run_actual
|
||||||
if self.dtstart is None:
|
if self.dtstart is None:
|
||||||
self.dtstart = self.next_run
|
self.dtstart = self.next_run
|
||||||
if "until" in self.rrule.lower() or 'count' in self.rrule.lower():
|
if self.dtend is None and "until" in self.rrule.lower() or 'count' in self.rrule.lower():
|
||||||
self.dtend = future_rs[-1]
|
self.dtend = future_rs[-1]
|
||||||
|
self.unified_job_template.update_computed_fields()
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.update_dt_elements()
|
# Check if new rrule, if so set dtstart and dtend to null
|
||||||
|
self.update_computed_fields()
|
||||||
super(Schedule, self).save(*args, **kwargs)
|
super(Schedule, self).save(*args, **kwargs)
|
||||||
# update template next run details
|
|
||||||
|
@ -135,6 +135,13 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique):
|
|||||||
def last_updated(self):
|
def last_updated(self):
|
||||||
return self.last_job_run
|
return self.last_job_run
|
||||||
|
|
||||||
|
def update_computed_fields(self):
|
||||||
|
related_schedules = Schedule.objects.get(enabled=True, unified_job_template=self, next_run__isnull=False).order_by('-next_run')
|
||||||
|
if related_schedules.exists():
|
||||||
|
self.next_schedule = related_schedules[0]
|
||||||
|
self.next_job_run = related_schedules[0].next_run
|
||||||
|
self.save(update_fields=['next_schedule', 'next_job_run'])
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
# If update_fields has been specified, add our field names to it,
|
# If update_fields has been specified, add our field names to it,
|
||||||
# if it hasn't been specified, then we're just doing a normal save.
|
# if it hasn't been specified, then we're just doing a normal save.
|
||||||
|
Loading…
Reference in New Issue
Block a user