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

Document the rest of the code #118

Conversation

Mr0grog
Copy link
Contributor

@Mr0grog Mr0grog commented Sep 1, 2020

This is meant to merge into #111 rather than the main branch.

This brings GoodJob to 89% documented — the remaining bits are the methods on LogSubscriber, which didn't seem worth documenting since they merely mirror the names of notifications they respond to, so I feel like they're pretty self documenting. These can probably be handled with one of:

  • :nodoc: comments (which unfortunately show up in the resulting docs).
  • A macro that makes a pretty simplistic comment.
  • @api nodoc comments combined with --hide-api nodoc in the .yardopts file. (This will hide them completely.)

Additionally, I didn’t really want to mess with it too much since it looks like some of the methods are for non-existent notifications. Not sure if things have changed since you last touched it or if you were anticipating notifications that haven’t yet been created. These are all the ones that I could see GoodJob sending:

  • scheduler_shutdown_start
  • scheduler_shutdown
  • scheduler_restart_pools
  • finished_timer_task
  • finished_job_task
  • scheduler_create_pools
  • cleanup_preserved_jobs
  • enqueue_job
  • perform_job
  • notifier_listen
  • notifier_notified
  • notifier_notify_error
  • notifier_unlisten

Don’t know if you want to document them somewhere or not.

This also adds the yard-activesupport-concern gem, which is pretty helpful for documenting methods inside included and class_methods blocks, which are Rails features that are wind up hiding their contents from Yard.

I spent an unfortunate amount of time attempting to make macros work nicely for ActiveRecord’s scope, but never found a solution that didn’t cause strange warnings from Yard, odd behavior with duplicated methods every time you reloaded the docs, or other problems, so I wound up with pretty verbose syntax for those. There might be a nice Yard plugin that solves this better. ¯\_(ツ)_/¯

Finally, I changed the CLI description setup slightly. It turns out we were putting long descriptions where the short, summary descriptions were meant to go, leaving us with this:

$ bundle exec good_job help
Commands:
  good_job cleanup_preserved_jobs  # Deletes preserved job records. By default, GoodJob deletes job records when the job is performed and this command is not necessary. However, ...
  good_job help [COMMAND]          # Describe available commands or one specific command
  good_job start                   # Executes queued jobs. All options can be configured with environment variables. See option descriptions for the matching environment variable...

Now we have the more readable:

$ bundle exec good_job help
Commands:
  good_job cleanup_preserved_jobs  # Deletes preserved job records.
  good_job help [COMMAND]          # Describe available commands or one specific command
  good_job start                   # Executes queued jobs.

As a bonus, it let me make a nice little macro for the doc comments. 😉

This brings GoodJob to 89% documented -- the remaining bits are the methods on `LogSubscriber`, which didn't seem worth documenting since they merely mirror the names of notifications they respond to, so I feel like they're pretty self documenting. These can probably be handled with one of:
- `:nodoc:` comments (which unfortunately show up in the resulting docs)
- A macro that makes a pretty simplistic comment
- `@api nodoc` comments combined with `--hide-api nodoc` in the `.yardopts` file. This will hide them completely.

This also adds the `yard-activesupport-concern` gem, which is pretty helpful for documenting methods inside `included` and `class_methods` blocks, which are Rails features that are wind up hiding their contents from Yard.
Comment on lines 109 to 116
# Finds the next eligible Job, acquire an advisory lock related to it, and
# executes the job.
# @return [Array<GoodJob::Job, Object, Exception>, nil]
# If a job was executed, returns an array with the {Job} record, the
# return value for the job's +#perform+ method, and the exception the job
# raised, if any (if the job raised, then the second array entry will be
# +nil+). If there were no jobs to execute, returns +nil+.
def self.perform_with_advisory_lock
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the README and in other spots, we used the language of “executing” jobs. This made me wonder if we should have said “perform” everywhere instead. Especially since it is the ActiveJob language.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. "Perform" is the correct verb in the context of "jobs".

Unfortunately there are many things that are executed that may or may not result in a job being performed. I'm ambivalent to a search-and-replace, but a documented decision would be helpful.

Copy link
Owner

@bensheldon bensheldon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Nothing critical needs to be changed but I left some comments for improvement.

I agree about leaving LogSubscriber undocumented.

And I understand about :nodoc: not working, that seems to be a hill YARD wants to die on.

lib/good_job/job.rb Outdated Show resolved Hide resolved
Comment on lines 109 to 116
# Finds the next eligible Job, acquire an advisory lock related to it, and
# executes the job.
# @return [Array<GoodJob::Job, Object, Exception>, nil]
# If a job was executed, returns an array with the {Job} record, the
# return value for the job's +#perform+ method, and the exception the job
# raised, if any (if the job raised, then the second array entry will be
# +nil+). If there were no jobs to execute, returns +nil+.
def self.perform_with_advisory_lock
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. "Perform" is the correct verb in the context of "jobs".

Unfortunately there are many things that are executed that may or may not result in a job being performed. I'm ambivalent to a search-and-replace, but a documented decision would be helpful.

lib/good_job/job.rb Outdated Show resolved Hide resolved
lib/good_job/lockable.rb Outdated Show resolved Hide resolved
lib/good_job/lockable.rb Outdated Show resolved Hide resolved
@bensheldon
Copy link
Owner

Oh, of your options for LogSubscriber, I think the macro one is best for now.

@Mr0grog
Copy link
Contributor Author

Mr0grog commented Sep 1, 2020

of your options for LogSubscriber, I think the macro one is best for now.

Can do. What about the mismatch between method names and the actual notifications? e.g. create, timer_task_finished, and job_finished (just looking at the first three) don’t correspond to actual notifications, or are named similarly but not the same as actual notifications (e.g. timer_task_finished vs. finished_timer_task)?

@bensheldon
Copy link
Owner

I think they have to match or they're broken. So that might just need a todo or fixit.

@Mr0grog
Copy link
Contributor Author

Mr0grog commented Sep 1, 2020

FYI, I’m rearranging some of the methods on LogSubscriber due to this bug in Yard: lsegal/yard#1350

Explain how it mainly relates to transactions and the visibility of new records.
@Mr0grog
Copy link
Contributor Author

Mr0grog commented Sep 1, 2020

I’m going to hold off on “perform” vs. “execute” in this PR since it touches a lot more files than are here, and requires some more nuance.

Ready for re-review.

Copy link
Owner

@bensheldon bensheldon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thank you!

@bensheldon bensheldon merged commit 79b78db into bensheldon:code_docs Sep 2, 2020
@bensheldon bensheldon added the documentation Improvements or additions to documentation label Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants