Skip to content

SAT-35237 - Keep report in generated folder for disconnected users #1050

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

chris1984
Copy link
Member

@chris1984 chris1984 commented Jul 30, 2025

What are the changes introduced in this pull request?

  • Report was being moved regardless of the setting so added logger statements and to return out of the task if the disconnected setting is on.
  • Added unit tests for queue_for_upload_job since we didn't have any and added some for the change I made
  • Also added in logic if the disconnected flag was passed in which can be done from hammer now, ui will come later.

Considerations taken when implementing this change?

  • Made sure report generate and upload still works for connected users

What are the testing steps for this pull request?

  • Turn subscription_connection_enabled to false
  • Generate a report, check the location, and see that it got moved to uploads
  • Check out pr
  • Try again, check that the report is now in the location the output states in generated
  • Check the logs showing the message:
  • 15:04:54 rails.1 | 2025-07-30T15:04:54 [I|bac|aaed2ff0] Report not moved because connection to Insights is not enabled or the --no-upload option was passed. Report: report_for_1.tar.xz, Organization: Default Organization

Summary by Sourcery

Handle disconnected mode in QueueForUploadJob by skipping report upload and retaining files in the generated folder, while logging contextual messages, and add comprehensive tests for these behaviors

New Features:

  • Skip moving reports and scheduling uploads when subscription connection is disabled or --no-upload flag is passed
  • Emit contextual log messages including report path and organization name upon disconnection

Enhancements:

  • Add DISCONNECTED_MESSAGE_TEMPLATE constant and content_disconnected? helper in QueueForUploadJob
  • Introduce organization_id accessor and log_disconnected_message method to log disconnection details
  • Integrate disconnection checks in both plan and run phases of QueueForUploadJob

Tests:

  • Add unit tests for plan and run methods covering connected and disconnected scenarios
  • Verify file movement, folder and script creation when connected
  • Assert that files remain in place and appropriate logs are emitted when disconnected

Copy link

sourcery-ai bot commented Jul 30, 2025

Reviewer's Guide

Enhance QueueForUploadJob to respect a disconnected flag or disabled subscription setting by skipping report movement and upload with a standardized log message, propagate organization_id for context, and introduce comprehensive unit tests covering both connected and disconnected flows.

Sequence diagram for QueueForUploadJob with disconnected mode

sequenceDiagram
    participant User as actor User
    participant Job as QueueForUploadJob
    participant Logger as Logger
    participant Org as Organization
    participant Setting as Setting
    User->>Job: plan(base_folder, report_file, organization_id, disconnected)
    Job->>Setting: Check subscription_connection_enabled
    alt Disconnected mode (disconnected flag or setting false)
        Job->>Org: Find organization by id
        Job->>Logger: log_disconnected_message(report_file, organization_id)
        Job-->>User: Return (report remains in generated folder)
    else Connected mode
        Job->>Job: plan_upload_report(enqueued_file_name, organization_id, disconnected)
        Job-->>User: Continue with upload
    end
Loading

Class diagram for updated QueueForUploadJob

classDiagram
    class QueueForUploadJob {
      +plan(base_folder, report_file, organization_id, disconnected)
      +run()
      -log_disconnected_message(report_file, organization_id)
      +report_file
      +organization_id
      +content_disconnected?
      +plan_upload_report(enqueued_file_name, organization_id, disconnected)
      <<EntryAction>>
      DISCONNECTED_MESSAGE_TEMPLATE
    }
    class UploadReportJob
    class Organization {
      +find_by(id)
      +name
    }
    class Setting
    QueueForUploadJob --> UploadReportJob : plans
    QueueForUploadJob --> Organization : uses
    QueueForUploadJob --> Setting : uses
Loading

File-Level Changes

Change Details Files
Handle disconnected mode and propagate organization context in QueueForUploadJob
  • Introduce content_disconnected? to check flag or subscription setting
  • Extend plan_self to accept organization_id and disconnected parameters
  • Early-return in plan and run with log_disconnected_message when disconnected
  • Implement log_disconnected_message using DISCONNECTED_MESSAGE_TEMPLATE and organization lookup
lib/foreman_inventory_upload/async/queue_for_upload_job.rb
Add unit tests for QueueForUploadJob covering connected and disconnected scenarios
  • Test skip behavior in plan and run when disconnected via flag or setting
  • Verify file movement, uploads folder and script creation when connected
  • Assert standardized logging of disconnected messages with organization context
test/jobs/queue_for_upload_job_test.rb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

sourcery-ai[bot]

This comment was marked as outdated.

sourcery-ai[bot]

This comment was marked as outdated.

sourcery-ai[bot]

This comment was marked as outdated.

sourcery-ai[bot]

This comment was marked as resolved.

@chris1984 chris1984 force-pushed the disc-report branch 2 times, most recently from 054b34f to 3459988 Compare July 30, 2025 16:26
sourcery-ai[bot]

This comment was marked as resolved.

* Report was being moved regardless of the setting so added logger statements and to return out of the task if the disconnected setting is on.
* Added unit tests for queue_for_upload_job since we didn't have any and added some for the change I made
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @chris1984 - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant