Skip to content

Commit

Permalink
decorator to warn if do_scheduler not true
Browse files Browse the repository at this point in the history
  • Loading branch information
deargle committed May 12, 2021
1 parent bf88a42 commit 8b82847
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion psiturk/dashboard/__init__.py
Expand Up @@ -100,6 +100,21 @@ def wrapped_view(**kwargs):

return wrapped_view

def warn_if_scheduler_not_running(view):
@wraps(view)
def wrapped_view(**kwargs):
app.logger.debug('checking if scheduler is running...')
do_scheduler = config.getboolean('Server Parameters', 'do_scheduler')
app.logger.debug(f'do_scheduler was {do_scheduler}')
if not do_scheduler:
flash((
'Warning: `do_scheduler` is set to False. '
'Tasks (such as campaigns) can be created, modified, or deleted, '
'but they will not be run by this psiturk instance.'
), 'warning')
return view(**kwargs)

return wrapped_view

@dashboard.before_request
@login_required
Expand Down Expand Up @@ -144,9 +159,9 @@ def hits_list():
def assignments_list():
return render_template('dashboard/assignments/list.html')


@dashboard.route('/campaigns')
@dashboard.route('/campaigns/')
@warn_if_scheduler_not_running
def campaigns_list():
completed_count = Participant.count_completed(
codeversion=services_manager.codeversion,
Expand All @@ -167,6 +182,7 @@ def campaigns_list():

@dashboard.route('/tasks')
@dashboard.route('/tasks/')
@warn_if_scheduler_not_running
def tasks_list():
return render_template('dashboard/tasks/list.html')

Expand Down

0 comments on commit 8b82847

Please sign in to comment.