Skip to content

Commit

Permalink
Merge pull request ansible#1636 from ryanpetrello/bad-license-no-sche…
Browse files Browse the repository at this point in the history
…dules

don't run scheduled jobs if there isn't a valid license
  • Loading branch information
ryanpetrello authored May 2, 2018
2 parents 65b342a + 30af0a1 commit ad11653
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions awx/main/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
# AWX
from awx import __version__ as awx_application_version
from awx.main.constants import CLOUD_PROVIDERS, PRIVILEGE_ESCALATION_METHODS
from awx.main.access import access_registry
from awx.main.models import * # noqa
from awx.main.constants import ACTIVE_STATES
from awx.main.exceptions import AwxTaskError
Expand All @@ -65,6 +66,9 @@
from awx.main.consumers import emit_channel_notification
from awx.conf import settings_registry

from rest_framework.exceptions import PermissionDenied


__all__ = ['RunJob', 'RunSystemJob', 'RunProjectUpdate', 'RunInventoryUpdate',
'RunAdHocCommand', 'handle_work_error', 'handle_work_success', 'apply_cluster_membership_policies',
'update_inventory_computed_fields', 'update_host_smart_inventory_memberships',
Expand Down Expand Up @@ -410,6 +414,13 @@ def awx_periodic_scheduler(self):
for schedule in old_schedules:
schedule.save()
schedules = Schedule.objects.enabled().between(last_run, run_now)

invalid_license = False
try:
access_registry[Job](None).check_license()
except PermissionDenied as e:
invalid_license = e

for schedule in schedules:
template = schedule.unified_job_template
schedule.save() # To update next_run timestamp.
Expand All @@ -419,6 +430,13 @@ def awx_periodic_scheduler(self):
try:
job_kwargs = schedule.get_job_kwargs()
new_unified_job = schedule.unified_job_template.create_unified_job(**job_kwargs)

if invalid_license:
new_unified_job.status = 'failed'
new_unified_job.job_explanation = str(invalid_license)
new_unified_job.save(update_fields=['status', 'job_explanation'])
new_unified_job.websocket_emit_status("failed")
raise invalid_license
can_start = new_unified_job.signal_start()
except Exception:
logger.exception('Error spawning scheduled job.')
Expand Down

0 comments on commit ad11653

Please sign in to comment.