-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Cron by ressource #175
Cron by ressource #175
Conversation
Thanks @Gabriel-Desharnais, this is a much requested feature from other users also described in issue #132 by @alexandreleroux . I was wondering if this could be done within a Flask webapp, especially when running in multi-process WGSI deployments like As a first step, you may have noticed that the Travis build has failed. Mostly this is due to the Flake8 Python Coding Standards check. It is quite strict but easy to fix and test. See the Travis details. And just run Also one of the tests failed, unclear why but your can rerun while fixing:
|
That should do it |
@Gabriel-Desharnais @tomkralidis Note some discussion on Gitter on this PR. Probably better to proceed here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try take this direction. Some general remarks:
- database upgrade: existing installations need to update their DBs using
paver upgrade
. Amigration
needs to be added. I have a migration script, generated when trying your PR. - some spelling errors of
frequency
(will indicate in code) test_frequency
use database column default i.s.o. code to always have default of 60 mins.- need to tackle the case of "multi-processing": where GHC runs as several separate processes, e.g. in Apache
mod_wsgi
orgunicorn
. See suggestion on Gitter. - GHC_RETENTION_DAYS, why the change into
days, seconds, microseconds, milliseconds, minutes, hours, weeks
? Will be incompatible with existing configs. May usecron
type scheduling. flush_runs()
runs once a minute, possibly once an hour or even day will do.requirements.txt
add specific version ofAPScheduler
as dependency
def start_crons(): | ||
# Cold start evry cron of evry ressource | ||
for resource in Resource.query.all(): | ||
freq = resource.test_frequency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do this via setting a default value for test_frequency
in Models.py and the migration script. No need to set here.
'max_instances': 100000 | ||
}) | ||
|
||
scheduler.add_job(flush_runs, 'interval', minutes=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite often, possibly once an hour will do.
@@ -37,7 +37,8 @@ | |||
# Replace None with 'your secret key string' in quotes | |||
SECRET_KEY = None | |||
|
|||
GHC_RETENTION_DAYS = 30 | |||
# days, seconds, microseconds, milliseconds, minutes, hours, weeks | |||
GHC_RETENTION_DAYS = (30, 0, 0, 0, 0, 0, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to retain the existing type for GHC_RETENTION_DAYS
, may expand this to a timedelta
explicitly.
# Complete handle of old runs deletion | ||
def flush_runs(): | ||
APP = App.get_app() | ||
retention_time = timedelta(*APP.config['GHC_RETENTION_DAYS']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See earlier comments: may just calculate retention time from days, e.g. retention_time
in milliseconds will be something like:
GHC_RETENTION_DAYS * 24 * 3600 * 1000
<tr> | ||
<th>Test frenqucy</th> | ||
<td> | ||
<input type="number" id="input_resource_frequency" name="resource_frenquency_value" value="{{ resource.test_frequency }}" style="width: 100%;"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling: resource_frenquency_value
should be resource_frequency_value
|
||
|
||
// Collect test_frequency | ||
var new_frequency = $('input[name="resource_frenquency_value"]').val(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling: resource_frenquency_value
should be resource_frequency_value
@@ -80,6 +80,12 @@ <h3 class="page-header">{{ _('Monitoring Period') }}: {{ resource.first_run.chec | |||
<button class="btn btn-{{ resource.reliability| cssize_reliability }} btn-sm nohover">{{ resource.reliability|round2 }}%</button> | |||
</td> | |||
</tr> | |||
<tr> | |||
<th>{{ _('Test frenquency (minutes)') }}</th> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling: frenquency
should be frequency
@@ -200,6 +199,7 @@ class Resource(DB.Model): | |||
owner = DB.relationship('User', | |||
backref=DB.backref('username2', lazy='dynamic')) | |||
tags = DB.relationship('Tag', secondary=resource_tags, backref='resource') | |||
test_frequency = DB.Column(DB.Integer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add default
60 mins here
Sorry, but closing this PR, as it has been implemented via PR #222. Thanks @Gabriel-Desharnais for the ideas in this PR. The actual implementation in #222 appeared to be more involved as GHC can run multiple processes in cases, e.g. via WSGI. Also attended via #132. |
So this modification integrate the cron inside the web app. There is no need to use crontab. Also there is one cron by resource and each of them can be set at different time interval