Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to schedule job with job interval "immediately" from API #1845

Closed
gsnider2195 opened this issue Jun 2, 2022 · 0 comments · Fixed by #2196
Closed

Unable to schedule job with job interval "immediately" from API #1845

gsnider2195 opened this issue Jun 2, 2022 · 0 comments · Fixed by #2196
Assignees
Labels
type: bug Something isn't working as expected

Comments

@gsnider2195
Copy link
Contributor

Environment

  • Python version: 3.7.13
  • Nautobot version: 1.3.5

Steps to Reproduce

  1. Send POST to /api/extras/jobs/{job id}/run/ with the following data in the body:
{
  "data": "",
  "commit": true,
  "schedule": {
    "name": "test-api",
    "start_time": "2022-06-02T20:36:37.915Z",
    "interval": "immediately"
  }
}

Expected Behavior

Job runs immediately

Observed Behavior

Job is scheduled but never runs

Immediate jobs need to be set to one_off=True and the extras.JobResult model schedule property needs to be updated to recognize immediate jobs as using the django-celery-beat clocked schedule instead of cron.

diff --git a/nautobot/extras/api/views.py b/nautobot/extras/api/views.py
@@ -361,11 +361,10 @@ def _create_schedule(serializer, data, commit, job, job_model, request):
         description=f"Nautobot job {name} scheduled by {request.user} on {time}",
         kwargs=job_kwargs,
         interval=type_,
-        one_off=(type_ == JobExecutionType.TYPE_FUTURE),
+        one_off=(type_ not in JobExecutionType.RECURRING_CHOICES),
         user=request.user,
         approval_required=job_model.approval_required,
     )

diff --git a/nautobot/extras/models/jobs.py b/nautobot/extras/models/jobs.py
@@ -805,7 +807,7 @@ class ScheduledJob(BaseModel):

     @property
     def schedule(self):
-        if self.interval == JobExecutionType.TYPE_FUTURE:
+        if self.interval not in JobExecutionType.RECURRING_CHOICES:
             # This is one-time clocked task
             return clocked(clocked_time=self.start_time)

diff --git a/nautobot/extras/views.py b/nautobot/extras/views.py
@@ -1021,11 +1021,10 @@ class JobView(ObjectPermissionRequiredMixin, View):
                     description=f"Nautobot job {schedule_name} scheduled by {request.user} for {schedule_datetime}",
                     kwargs=job_kwargs,
                     interval=schedule_type,
-                    one_off=schedule_type == JobExecutionType.TYPE_FUTURE,
+                    one_off=(schedule_type not in JobExecutionType.RECURRING_CHOICES),
                     user=request.user,
                     approval_required=job_model.approval_required,
                 )
@gsnider2195 gsnider2195 self-assigned this Jun 2, 2022
@gsnider2195 gsnider2195 added the type: bug Something isn't working as expected label Jun 2, 2022
bryanculver added a commit that referenced this issue Aug 12, 2022
Close #1845

* Honor `has_sensitive_variables` when storing kwargs for re-run
* Update Job class docstring
* Add test for not storing kwargs on rerun for sensitive variable jobs
* Fix #1845 to suppor testing
* Update job sensitive variables messaging
briddo pushed a commit that referenced this issue Aug 16, 2022
…mmediate job schedule in API (#2196)

* Honor `has_sensitive_variables` when storing kwargs for re-run
* Update Job class docstring
* Add test for not storing kwargs on rerun for sensitive variable jobs
* Fix #1845 to suppor testing
* Update job sensitive variables messaging

Co-authored-by: Gary Snider <75227981+gsnider2195@users.noreply.github.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
No open projects
Archived in project
1 participant