Merge lp://staging/~roadmr/capomastro/project-scheduling-ui-fixing into lp://staging/capomastro

Proposed by Daniel Manrique
Status: Merged
Approved by: Caio Begotti
Approved revision: 191
Merged at revision: 193
Proposed branch: lp://staging/~roadmr/capomastro/project-scheduling-ui-fixing
Merge into: lp://staging/capomastro
Diff against target: 531 lines (+345/-17)
9 files modified
projects/forms.py (+6/-0)
projects/helpers.py (+33/-2)
projects/templates/projects/periodictask_confirm_delete.html (+26/-0)
projects/templates/projects/project_detail.html (+26/-1)
projects/templates/projects/projectbuild_form.html (+1/-1)
projects/tests/test_helpers.py (+74/-1)
projects/tests/test_views.py (+110/-2)
projects/urls.py (+1/-0)
projects/views.py (+68/-10)
To merge this branch: bzr merge lp://staging/~roadmr/capomastro/project-scheduling-ui-fixing
Reviewer Review Type Date Requested Status
Caio Begotti (community) Approve
Review via email: mp+256405@code.staging.launchpad.net

Commit message

User interface changes to create schedules to build projects periodically.

This just creates the required entries in the PeriodicTasks table for djcelery use, the actual running of said tasks will come in a subsequent merge.

Description of the change

The UI portion of the build scheduling feature.

I don't precreate nor provide a way of creating the 'intervals' at which the build can be scheduled: we can do that easily via the admin and the UI won't die if there are no intervals (it just won't allow scheduling builds).

The project build request form was repurposed to also allow scheduling, the button in the main project view reflects this. In the request form itself, one can select "Now" for an immediate build (old behavior) or choose one of the provided intervals. Clicking "build" will either fire up or schedule the build. If scheduled, the user is returned to the project detail view with a message.

The detail view will show any build schedules for the shown project, including the build interval and last-built time (which is important because the times are not aligned: e.g. if I select "every 24 hours" it will build 24 hours *after* I created the schedule, not at 00:00 hours). Also, a "delete" control with a confirmation screen is present in the detail view.

I don't provide a facility for editing schedules: they're quite trivial and it's easier to just remove them if unneeded and create new ones.

Any more complex editing of intervals or schedules can be done via the admin.

Also, note that this doesn't yet launch the builds, it just creates the records in the djcelery PeriodicTask table. The actual launching will come in another MR.

Finally, I didn't have time to write the tests for the deletion workflow :( I'll do so ASAP.

To post a comment you must log in.
Revision history for this message
Caio Begotti (caio1982) wrote :

Besides my comments inline I am deploying it from Wendigo to give it a try :-D

Revision history for this message
Caio Begotti (caio1982) wrote :

Oh! I created an interval and successfully set it up with with a Barajas build, but then I created another interval and tried to schedule a build again using the new interval and got this https://pastebin.canonical.com/129718/

duplicate key value violates unique constraint "djcelery_periodictask_name_key"
DETAIL: Key (name)=(Build Barajas) already exists.

So now I am running an immediate build now so it is cached for the schedule runs later.

Revision history for this message
Daniel Manrique (roadmr) wrote :

Replied to inline comments.

About the unique constraint: damn! I was including the build interval in the task names, so I hadn't seen this problem except when you scheduled the same project with the same interval twice (an unlikely scenario). But last-minute, I changed the task names to remove the build interval (since the task's repr shows that by default and it looked like ("Build project X every 24 minutes: every 24 minutes"). So now the unique constraint restriction is an issue again :) Give me a sec, I'll fix it.

Revision history for this message
Caio Begotti (caio1982) wrote :
Download full text (20.8 KiB)

Btw, thanks for even considering these! They were not really problems
but just string doubts/suggestions in the UI, you did a huge work
already.

On Thu, Apr 16, 2015 at 11:38 AM, Daniel Manrique
<email address hidden> wrote:
> Replied to inline comments.
>
> About the unique constraint: damn! I was including the build interval in the task names, so I hadn't seen this problem except when you scheduled the same project with the same interval twice (an unlikely scenario). But last-minute, I changed the task names to remove the build interval (since the task's repr shows that by default and it looked like ("Build project X every 24 minutes: every 24 minutes"). So now the unique constraint restriction is an issue again :) Give me a sec, I'll fix it.
>
> Diff comments:
>
>> === modified file 'projects/forms.py'
>> --- projects/forms.py 2015-01-23 21:18:51 +0000
>> +++ projects/forms.py 2015-04-15 22:26:00 +0000
>> @@ -1,5 +1,6 @@
>> from django import forms
>>
>> +from djcelery.models import IntervalSchedule
>> from jenkins.models import JenkinsServer, JobType
>> from projects.models import (
>> Project, Dependency, ProjectDependency)
>> @@ -77,3 +78,8 @@
>> error_messages={"required": "Must select at least one dependency."})
>> project = forms.ModelChoiceField(
>> Project.objects, required=True, widget=forms.HiddenInput)
>> + interval = forms.ModelChoiceField(label='When to build',
>> + widget=forms.RadioSelect(),
>> + queryset=IntervalSchedule.objects.all(),
>> + empty_label="Now",
>> + required=False)
>>
>> === modified file 'projects/helpers.py'
>> --- projects/helpers.py 2014-08-05 14:10:55 +0000
>> +++ projects/helpers.py 2015-04-15 22:26:00 +0000
>> @@ -1,7 +1,9 @@
>> +import json
>> +
>> from jenkins.tasks import build_job
>> from jenkins.models import Build
>> -from projects.models import ProjectDependency
>> -
>> +from projects.models import Project, ProjectDependency
>> +from djcelery.models import PeriodicTask
>>
>> def build_dependency(dependency, build_id=None, user=None):
>> """
>> @@ -96,3 +98,32 @@
>> return previous_build.build_dependencies.filter(
>> projectdependency=dependency).first()
>> return dependency.current_build
>> +
>> +
>> +def periodic_tasks_for_project(project):
>> + """
>> + Return a list of PeriodicTask records that are scheduled to build
>> + the given project.
>> + """
>> + expected_args = [project.pk]
>> + return [ptask for ptask in PeriodicTask.objects.filter(
>> + task="projects.tasks.start_periodic_build",
>> + args=expected_args)]
>> +
>> +
>> +def project_for_periodic_task(task):
>> + """
>> + Return the project that a given periodic_task will build, but only
>> + if the task is the start_periodic_build one. If it's not, then we
>> + can't be sure of the meaning of the parameter list so we return None.
>> + """
>> + # Tricky because what we have in the task is a json-encoded array
>> + if task.task != "projects....

Revision history for this message
Daniel Manrique (roadmr) wrote :

I pushed a fix for the unique name constraint. It'll tack on a serial number to the task name, but only if needed. So if someone adds two periodictasks for the same project (weird, but it can happen) it will work now.

Ready for another check!

189. By Daniel Manrique

projects: Allow deletion of build schedules.

This is just the DeleteView, new URL endpoint. It could be called
directly but has yet to be wired to the project detail view.

190. By Daniel Manrique

projects: UI to add, view and delete scheduled builds.

I also call them "build schedules" because it's a schedule under which
builds will be produced.

The UI allows:
- A user can select either "Now" for the old behavior, or one of the
  available intervals if a periodic build is desired. This allows
  periodic build scheduling with minimal UI changes.

- The project's detail view shows any build schedules for that project,
  and allows deleting them by invoking the previously-added deleteview.

- It will only show available intervals. If no intervals have been added
  via the admin pages, then the only option will be "Now", so confusion
  is kept to a minimum.

191. By Daniel Manrique

projects: Create and display build schedules.

Includes tests to check:
- Scheduled builds are shown in a project's details page
- A PeriodicTask (i.e. a schedule for builds) is created when an
  interval is selected, rather than launching a build immediately.

Revision history for this message
Caio Begotti (caio1982) wrote :

Tried a few different builds, canceling them, updating projects schedules and left both the old branch code running overnight and the new one with the unique name fix for some time. All builds seem good. The tests you and Chris were doing on Staging were all done using this branch!

review: Approve
Revision history for this message
Caio Begotti (caio1982) wrote :

Just for reference: I scheduled 6 overnight builds and this morning other 3 hourly ones.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches