Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable configuration of result_ttl in django-rq-scheduler #18

Merged
merged 4 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scheduler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '1.1.1'
__version__ = '1.1.2'

default_app_config = 'scheduler.apps.SchedulerConfig'
2 changes: 2 additions & 0 deletions scheduler/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ScheduledJobAdmin(QueueMixin, admin.ModelAdmin):
'fields': (
'scheduled_time',
'timeout',
'result_ttl'
),
}),
)
Expand Down Expand Up @@ -64,6 +65,7 @@ class RepeatableJobAdmin(QueueMixin, admin.ModelAdmin):
('interval', 'interval_unit', ),
'repeat',
'timeout',
'result_ttl'
),
}),
)
25 changes: 25 additions & 0 deletions scheduler/migrations/0004_auto_20170903_1339.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2017-09-03 13:39
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('scheduler', '0003_remove_queue_choices'),
]

operations = [
migrations.AddField(
model_name='repeatablejob',
name='result_ttl',
field=models.IntegerField(blank=True, help_text='The TTL value (in seconds) of the job result. -1: Result never expires, you should delete jobs manually. 0: Result gets deleted immediately. >0: Result expires after n seconds.', null=True, verbose_name='result ttl'),
),
migrations.AddField(
model_name='scheduledjob',
name='result_ttl',
field=models.IntegerField(blank=True, help_text='The TTL value (in seconds) of the job result. -1: Result never expires, you should delete jobs manually. 0: Result gets deleted immediately. >0: Result expires after n seconds.', null=True, verbose_name='result ttl'),
),
]
11 changes: 11 additions & 0 deletions scheduler/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class BaseJob(TimeStampedModel):
'timeout.'
)
)
result_ttl = models.IntegerField(
_('result ttl'), blank=True, null=True,
help_text=_('The TTL value (in seconds) of the job result. -1: '
'Result never expires, you should delete jobs manually. '
'0: Result gets deleted immediately. >0: Result expires '
'after n seconds.')
)

def __str__(self):
return self.name
Expand Down Expand Up @@ -91,6 +98,8 @@ def schedule(self):
kwargs = {}
if self.timeout:
kwargs['timeout'] = self.timeout
if self.result_ttl is not None:
kwargs['result_ttl'] = self.result_ttl
job = self.scheduler().enqueue_at(
self.schedule_time_utc(), self.callable_func(),
**kwargs
Expand Down Expand Up @@ -154,6 +163,8 @@ def schedule(self):
}
if self.timeout:
kwargs['timeout'] = self.timeout
if self.result_ttl is not None:
kwargs['result_ttl'] = self.result_ttl
job = self.scheduler().schedule(**kwargs)
self.job_id = job.id
return True
Expand Down