diff --git a/bazarr/api.py b/bazarr/api.py index 5121c97ff..f02e07d7b 100644 --- a/bazarr/api.py +++ b/bazarr/api.py @@ -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 = [] diff --git a/bazarr/main.py b/bazarr/main.py index 4a304e23b..6d4474a62 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -1055,13 +1055,6 @@ def get_logs(): return dict(data=logs) -@app.route('/execute/') -@login_required -def execute_task(taskid): - scheduler.execute_now(taskid) - return '', 200 - - def configured(): database.execute("UPDATE system SET configured = 1") diff --git a/bazarr/scheduler.py b/bazarr/scheduler.py index 94c5c1a5d..0cb3aaedb 100644 --- a/bazarr/scheduler.py +++ b/bazarr/scheduler.py @@ -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()))) diff --git a/views/_main.html b/views/_main.html index 9aa665f00..1d141c419 100644 --- a/views/_main.html +++ b/views/_main.html @@ -210,12 +210,12 @@ -
-
+
+
{% block bcleft %} {% endblock bcleft %}
-
+
{% block bcright %} {% endblock bcright %}
@@ -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() { diff --git a/views/systemtasks.html b/views/systemtasks.html index 5cfbdf0f0..0a957c195 100644 --- a/views/systemtasks.html +++ b/views/systemtasks.html @@ -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 ''; + } else { + return ''; + } } } ] }); + + $('#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" + }); + }); }) {% endblock tail %}