1 | | Here are all the models: |
2 | | |
3 | | {{{ |
4 | | |
5 | | from django.contrib.auth.models import User |
6 | | from django.db import models |
7 | | |
8 | | job_state = (('P', 'Pending'), ('A', 'Active'), ('C', 'Completed'), ('F', 'Failed')) |
9 | | app_type = (('R', 'RX'), ('W', 'WAR')) |
10 | | server_types = #taken out |
11 | | |
12 | | |
13 | | class JobGroup(models.Model): |
14 | | job_type = models.CharField(max_length=100, db_index=True) |
15 | | created_by = models.ForeignKey(User) |
16 | | queued_date = models.DateTimeField(null=True, db_index=True) |
17 | | created_date = models.DateTimeField(auto_now_add=True, db_index=True) |
18 | | |
19 | | |
20 | | class JobParameter(models.Model): |
21 | | job_group = models.ForeignKey(JobGroup, related_name='job_param', on_delete=models.CASCADE) |
22 | | name = models.CharField(max_length=100, db_index=True) |
23 | | value = models.TextField() |
24 | | |
25 | | def split_values(self): |
26 | | if ',' in self.value and isinstance(self.value, str): |
27 | | return self.value.split(', ') |
28 | | else: |
29 | | return [self.value] |
30 | | |
31 | | class Meta: |
32 | | unique_together = ('job_group', 'name') |
33 | | |
34 | | |
35 | | class Job(models.Model): |
36 | | job_group = models.ForeignKey(JobGroup, related_name='jobs', on_delete=models.CASCADE) |
37 | | state = models.CharField(max_length=1, choices=job_state, default='P', db_index=True) |
38 | | start_date = models.DateTimeField(null=True, db_index=True) |
39 | | end_date = models.DateTimeField(null=True) |
40 | | store = models.CharField(max_length=40, db_index=True) |
41 | | payload = models.TextField() |
42 | | |
43 | | def get_full_state(self): |
44 | | return self.get_state_display() if self.state in dict(job_state) else 'Unknown' |
45 | | |
46 | | class Meta: |
47 | | permissions = ( |
48 | | ('deployment_job', 'Access Deployment job'), |
49 | | ('services_job', 'Access System Services job'), |
50 | | ('offline_status_job', 'Access Offline Status job'), |
51 | | ) |
52 | | |
53 | | |
54 | | class JobLog(models.Model): |
55 | | job = models.ForeignKey(Job, related_name='logs', on_delete=models.CASCADE) |
56 | | command = models.TextField() |
57 | | command_output = models.TextField() |
58 | | result = models.BooleanField(default=False) |
59 | | |
60 | | |
61 | | class Service(models.Model): |
62 | | service_name = models.CharField(max_length=40) |
63 | | human_readable_name = models.CharField(max_length=40) |
64 | | server_type = models.CharField(choices=server_types, max_length=5) |
65 | | |
66 | | def __str__(self): |
67 | | return self.human_readable_name |
68 | | |
69 | | class Meta: |
70 | | ordering = ['human_readable_name'] |
71 | | unique_together = ['service_name', 'server_type'] |
72 | | }}} |