Skip to content

Commit 6bfcb6d

Browse files
committed
4.7.8
- added support for task PID, so it can be killed in future releases - now a task instance can be filtered by status on the admin section
1 parent 70660b3 commit 6bfcb6d

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

process/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__title__ = 'django-process'
22
__description__ = 'An app for create process workflows and schedule tasks on django'
33
__url__ = 'https://github.com/Jesrat/django-process'
4-
__version__ = '4.7.7'
4+
__version__ = '4.7.8'
55
__author__ = 'Josue Gomez'
66
__author_email__ = 'jgomez@jesrat.com'
77
__license__ = 'Apache 2.0'

process/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def cancel(self, request, queryset):
101101
@admin.register(JobTask)
102102
class JobTaskAdmin(admin.ModelAdmin):
103103
form = JobTaskForm
104+
list_filter = ('status',)
104105
list_display = ('__str__', 'dt_start', 'dt_end', 'observations')
105106

106107
def get_readonly_fields(self, request, obj=None):

process/management/commands/_task.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@ def run(self):
4444

4545
logger.info(f'command to execute {cmd}')
4646

47+
# executing the task and save the PID
4748
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
49+
self.obj.pid = p.pid
50+
self.obj.save()
51+
52+
# communicate to PID to get the standard output and error
4853
stdout, stderr = p.communicate()
54+
4955
# return code must be 0 for success
5056
self.obj.observations = stdout.decode('utf-8')
5157
if p.returncode:

process/management/commands/run_jobs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class Command(BaseCommand):
1212
help = 'Run All Jobs'
1313

14+
# noinspection PyMethodMayBeStatic
1415
def handle(self, *args, **options):
1516
logger.info('django-process run_jobs started')
1617
configure_env()

process/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def create(cls, process, *args, **kwargs):
271271
"""
272272
this method creates a job-process instance and all its tasks, however if the job its created as finished it will
273273
not create any task, example the time has come for start a job but a previous instance is still running and the
274-
process its configured for not overlap the new instance will be created as finished
274+
process it's configured for not overlap the new instance will be created as finished
275275
"""
276276
job = cls(process=process, *args, **kwargs)
277277
job.save()
@@ -297,7 +297,7 @@ def cancel(self):
297297
# noinspection SpellCheckingInspection
298298
class JobTask(models.Model):
299299
"""
300-
A JobTask its an instance of a Task that has been executed ant its related to the Job Instance
300+
A JobTask is an instance of a Task that has been executed ant it is related to the Job Instance
301301
"""
302302
initialized = 'initialized'
303303
awaiting = 'awaiting'
@@ -350,6 +350,7 @@ class JobTask(models.Model):
350350
related_name='logs'
351351
)
352352
status = models.CharField(_("status"), db_index=True, max_length=20, choices=status_choices, default=awaiting)
353+
pid = models.PositiveIntegerField(_("pid"), default=0)
353354
dt_created = models.DateTimeField(_("created date"), blank=True, null=True, auto_now_add=True)
354355
dt_start = models.DateTimeField(_("start date"), blank=True, null=True)
355356
dt_end = models.DateTimeField(_("end date"), blank=True, null=True)

0 commit comments

Comments
 (0)