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. |
justb4
left a comment
There was a problem hiding this comment.
Let's try take this direction. Some general remarks:
- database upgrade: existing installations need to update their DBs using
paver upgrade. Amigrationneeds to be added. I have a migration script, generated when trying your PR. - some spelling errors of
frequency(will indicate in code) test_frequencyuse 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_wsgiorgunicorn. 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 usecrontype scheduling. flush_runs()runs once a minute, possibly once an hour or even day will do.requirements.txtadd specific version ofAPScheduleras 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.
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.
This is quite often, possibly once an hour will do.
|
|
||
| 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.
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.
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.
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.
Spelling: resource_frenquency_value should be resource_frequency_value
| </td> | ||
| </tr> | ||
| <tr> | ||
| <th>{{ _('Test frenquency (minutes)') }}</th> |
There was a problem hiding this comment.
Spelling: frenquency should be frequency
| 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) |
|
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