pull/884/head
Louis Vézina 4 years ago
parent 8749fc13f2
commit 57cdd2fce9

@ -39,6 +39,8 @@ from flask_restful import Resource, Api
api_bp = Blueprint('api', __name__, url_prefix=base_url.rstrip('/')+'/api')
api = Api(api_bp)
scheduler = Scheduler()
class Badges(Resource):
def get(self):
@ -64,13 +66,19 @@ class Languages(Resource):
class SystemTasks(Resource):
def get(self):
scheduler = Scheduler()
task_list = scheduler.get_task_list()
return jsonify(data=task_list)
def post(self):
taskid = request.json['taskid']
scheduler.execute_job_now(taskid)
return '', 200
class SystemLogs(Resource):
def get(self):
logs = []

@ -1055,13 +1055,6 @@ def get_logs():
return dict(data=logs)
@app.route('/execute/<taskid>')
@login_required
def execute_task(taskid):
scheduler.execute_now(taskid)
return '', 200
def configured():
database.execute("UPDATE system SET configured = 1")

@ -21,7 +21,7 @@ import pytz
from tzlocal import get_localzone
from calendar import day_name
import pretty
from random import seed, uniform, randint
from random import randrange
from websocket_handler import event_stream
@ -125,14 +125,20 @@ class Scheduler:
else:
next_run = pretty.date(job.next_run_time.replace(tzinfo=None))
if job.id in self.__running_tasks:
running = True
else:
running = False
if isinstance(job.trigger, IntervalTrigger):
interval = "every " + get_time_from_interval(job.trigger.__getstate__()['interval'])
task_list.append({'name': job.name, 'interval': interval, 'next_run_in': next_run,
'next_run_time': job.next_run_time.replace(tzinfo=None), 'job_id': job.id})
'next_run_time': job.next_run_time.replace(tzinfo=None), 'job_id': job.id,
'job_running': running})
elif isinstance(job.trigger, CronTrigger):
task_list.append({'name': job.name, 'interval': get_time_from_cron(job.trigger.fields),
'next_run_in': next_run, 'next_run_time': job.next_run_time.replace(tzinfo=None),
'job_id': job.id})
'job_id': job.id, 'job_running': running})
return task_list
@ -240,5 +246,4 @@ class Scheduler:
def __randomize_interval_task(self):
for job in self.aps_scheduler.get_jobs():
if isinstance(job.trigger, IntervalTrigger):
seed(randint(0,1000))
self.aps_scheduler.modify_job(job.id, next_run_time=datetime.now() + timedelta(seconds=uniform(job.trigger.interval.total_seconds()*0.75, job.trigger.interval.total_seconds())))
self.aps_scheduler.modify_job(job.id, next_run_time=datetime.now() + timedelta(seconds=randrange(job.trigger.interval.total_seconds()*0.75, job.trigger.interval.total_seconds())))

@ -210,12 +210,12 @@
<!-- ============================================================== -->
<!-- Bread crumb and right sidebar toggle -->
<!-- ============================================================== -->
<div class="row page-titles">
<div class="col-md-5 col-8 align-self-center">
<div id="buttons_bars" class="row page-titles">
<div id="buttons_bar_left" class="col-md-5 col-8 align-self-center">
{% block bcleft %}
{% endblock bcleft %}
</div>
<div class="col-md-7 col-4 align-self-center">
<div id="buttons_bar_right" class="col-md-7 col-4 align-self-center">
{% block bcright %}
{% endblock bcright %}
</div>
@ -313,6 +313,12 @@
})
})
}
if ( $('#buttons_bar_left').children().length > 0 || $('#buttons_bar_right').children().length > 0 ) {
$('#buttons_bars').show();
} else {
$('#buttons_bars').hide();
}
});
$(window).on('beforeunload', function() {

@ -1,6 +1,6 @@
{% extends '_main.html' %}
{% block title %}Logs - Bazarr{% endblock %}
{% block title %}Tasks - Bazarr{% endblock %}
{% block bcleft %}
@ -40,7 +40,10 @@
ordering: false,
processing: true,
serverSide: false,
ajax: "{{ url_for('api.systemtasks') }}",
ajax: {
url: "{{ url_for('api.systemtasks') }}",
type: 'GET'
},
columns: [
{
data: 'name'
@ -51,11 +54,29 @@
},
{ data: null,
render: function(data) {
return 'button'
if (data.job_running) {
return '<i class="execute fas fa-sync fa-spin" data-taskid="'+data.job_id+'"></i>';
} else {
return '<i class="execute fas fa-sync" data-taskid="'+data.job_id+'"></i>';
}
}
}
]
});
$('#tasks').on('click', '.execute', function(e){
e.preventDefault();
const values = {
'taskid': $(this).data("taskid")
};
$.ajax({
url: "{{ url_for('api.systemtasks') }}",
method: "POST",
data: JSON.stringify(values),
contentType: "application/json"
});
});
})
</script>
{% endblock tail %}

Loading…
Cancel
Save