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
Job fixes for git repositories #3840
Job fixes for git repositories #3840
Conversation
- Replace `import_tasks_from_jobs_root` with `import_jobs_as_celery_tasks`, handling Celery loading of system jobs, local jobs, and git jobs all together. - Git jobs are imported as `<repo_slug>.jobs.<module>.<ClassName>` - This change allows removing `settings.CELERY_IMPORTS` as unnecessary - Job class_path structure has been changed from "git.repo_slug/submodule_name/ClassName" to simply "module_name.ClassName" throughout the code. (TODO: document this, fix up API endpoint) - Job.source and Job.git_repository have been removed as no longer needed, redundant - Job.unique_together is now just `["module_name", "job_class_name"]` - Job.slug has been removed. - `refresh_git_jobs()` now relies on the registered Celery tasks instead of on `jobs_in_directory()`, which is no longer needed and has been removed - `get_jobs()` and its helper `_get_job_source_paths` are no longer needed and have been removed - Accessing `JobModel.job_class` now just pulls from the Celery registry instead of looking for the job on disk and potentially resyncing a Git repository - `refresh_job_models()` has been reworked to rely on the registered Celery tasks instead of `get_jobs()`
…'t auto-import them
* Ensure GitRepostory.slug is a valid Python package name * Tell base test slugify function * Web views too * Update nautobot/extras/migrations/0072_job__unique_name_data_migration.py Co-authored-by: Gary Snider <75227981+gsnider2195@users.noreply.github.com> * Clean method enforcement * Update enforcement, slugify JS function, tests * Revert validation error change * Fix view tests --------- Co-authored-by: Gary Snider <75227981+gsnider2195@users.noreply.github.com>
Co-authored-by: Bryan Culver <31187+bryanculver@users.noreply.github.com>
@@ -192,6 +192,12 @@ def empty_repo(self, path, url, *args, **kwargs): | |||
os.remove(os.path.join(path, "jobs", "__init__.py")) | |||
return mock.DEFAULT | |||
|
|||
def assert_repo_slug_valid_python_package_name(self): | |||
git_repository = GitRepository.objects.create( | |||
name="1 Very-Bad Git_____Repo Name (2)", remote_url="http://localhost/git.git" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the slugify function/clean handle dots in the slug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They get discarded:
>>> from nautobot.core.models.fields import slugify_dashes_to_underscores
>>> slugify_dashes_to_underscores("Alpha.Beta-Gamma")
'alphabeta_gamma'
Resolved in b7e2b0a with some more mucking around in Celery guts. |
Closes: #3856
What's Changed
import_tasks_from_jobs_root
withimport_jobs_as_celery_tasks
, handling Celery loading of system jobs, local jobs, and git jobs all together.<repo_slug>.jobs.<module>.<ClassName>
settings.CELERY_IMPORTS
as unnecessary(TODO: document this)["module_name", "job_class_name"]
refresh_git_jobs()
now relies on the registered Celery tasks instead of onjobs_in_directory()
, which is no longer needed and has been removedget_jobs()
and its helper_get_job_source_paths
are no longer needed and have been removedJobModel.job_class
now just pulls from the Celery registry instead of looking for the job on disk and potentially resyncing a Git repositoryrefresh_job_models()
has been reworked to rely on the registered Celery tasks instead ofget_jobs()
/tests/
subdirectory (edit: or atest_*.py
file), which was resulting in all of thenautobot/extras/tests/example_jobs
being directly imported and registered with Celery when running tests. This is undesirable; I fixed it by moving this directory tonautobot/extras/test_jobs
(edit: and renaming all of the job files to remove thetest_
prefix from them) so that it no longer gets auto-imported by the runner.TODO