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

Compatibility with api_only applications #87

Merged
merged 3 commits into from
Aug 19, 2024
Merged

Compatibility with api_only applications #87

merged 3 commits into from
Aug 19, 2024

Conversation

zavan
Copy link
Contributor

@zavan zavan commented Feb 27, 2024

This is an attempt to address #60 and make this gem work with API-only Rails applications without the need to change the host application.

I only tested it with a bare api_only application and my own non-api_only application and it seems to work, but we probably need more tests.

  1. Added propshaft as a dependency and required it (maybe we should conditionally require it based on if the host app already has any asset pipeline setup? can propshaft can cause issues with applications using Rails <7? Should we go for sprockets instead?)
  2. Included all ActionController::Base modules in ApplicationController, unless they're already included (maybe we should be more selective?)
  3. Included the engine and importmap helpers in ApplicationController, unless they're already included
  4. Setup the ActionDispatch::Flash middleware if not already setup

@rosa
Copy link
Member

rosa commented Mar 1, 2024

This looks great!

Added propshaft as a dependency and required it (maybe we should conditionally require it based on if the host app already has any asset pipeline setup? can propshaft can cause issues with applications using Rails <7? Should we go for sprockets instead?)

I think this is ok, since this requires Rails 7+. I wouldn't worry too much about that.

@MarcMogdanz
Copy link

Thanks for the PR! It works fine for me so far but I've encountered one issue and I'm not quite sure if it's due to my setup or the PR here: I can't unpause a queue anymore.

I'm a bloody beginner when it comes to Rails and especially Turbo still, so I'm unsure if the issue is due to my setup, the fact that I converted my Rails app to an API only app recently or something related to the PR here, so take it with a grain of salt:

After pausing a queue (which works fine) it does update to button to show Resume. Clicking the button also does fire a request which is a POST to /jobs/applications/XXX/queues/default/pause?server_id=solid_queue containing _method=delete as the form data. This seems to be where the issue is lying, taking a look at the logs it shows that it's trying to pause the queue rather than unpausing it.

Started GET "/assets/mission_control/jobs/application-6148a20a46492f80f96ae94c8a893b373e8396c7.css" for 127.0.0.1 at 2024-03-12 23:53:59 +0100
Started GET "/assets/turbo.min-505f2d34b595d59de9b09163f773c2bc4fb286ae.js" for 127.0.0.1 at 2024-03-12 23:53:59 +0100
Started GET "/assets/mission_control/jobs/application-6003f9d69cd3ed9fd1a20af411717f54a4652676.js" for 127.0.0.1 at 2024-03-12 23:53:59 +0100
Started GET "/assets/stimulus-loading-25917588565633495ac04a032df7c72f2a9368de.js" for 127.0.0.1 at 2024-03-12 23:53:59 +0100
Started GET "/assets/mission_control/jobs/controllers/application-1b22bc5afcb96df9324dce6f6349f44e3ea5ad2a.js" for 127.0.0.1 at 2024-03-12 23:53:59 +0100
Started GET "/assets/mission_control/jobs/helpers/debounce_helpers-4f902fe8914a952efc59530617a5295a590d3586.js" for 127.0.0.1 at 2024-03-12 23:53:59 +0100
Started GET "/assets/mission_control/jobs/controllers/index-fd99e138facb2d2e92e72a282a4b349ebebf95a1.js" for 127.0.0.1 at 2024-03-12 23:53:59 +0100
Started GET "/assets/stimulus.min-7ea3d58b7f4507e3603ec999251ff60d16431a30.js" for 127.0.0.1 at 2024-03-12 23:53:59 +0100
Started GET "/assets/mission_control/jobs/helpers/index-c494b5ef5ceb7d3ce135b2c5987dd023097df11a.js" for 127.0.0.1 at 2024-03-12 23:53:59 +0100
Started GET "/assets/turbo.min.js-0737a33f6c8793049e1aeacb2213d8be06fce410.map" for 127.0.0.1 at 2024-03-12 23:53:59 +0100
Started GET "/assets/stimulus.min.js-e528a1dec846262ee5bed747878e9332209d754e.map" for 127.0.0.1 at 2024-03-12 23:53:59 +0100
Started GET "/assets/mission_control/jobs/controllers/form_controller-dd64bcda06d192ac8a77521fcdccd22023525d6e.js" for 127.0.0.1 at 2024-03-12 23:53:59 +0100
Started POST "/jobs/applications/XXX/queues/default/pause?server_id=solid_queue" for 127.0.0.1 at 2024-03-12 23:54:02 +0100
Processing by MissionControl::Jobs::Queues::PausesController#create as TURBO_STREAM
  Parameters: {"server_id"=>"solid_queue", "application_id"=>"XXX", "queue_id"=>"default"}
  SolidQueue::Job Load (16.4ms)  SELECT DISTINCT "solid_queue_jobs"."queue_name" FROM "solid_queue_jobs"
  SolidQueue::Pause Load (2.2ms)  SELECT "solid_queue_pauses".* FROM "solid_queue_pauses" WHERE "solid_queue_pauses"."queue_name" = $1  [["queue_name", "default"]]
  SolidQueue::ReadyExecution Count (2.1ms)  SELECT COUNT(*) FROM "solid_queue_ready_executions" WHERE "solid_queue_ready_executions"."queue_name" = $1  [["queue_name", "default"]]
  TRANSACTION (5.6ms)  BEGIN
  SolidQueue::Pause Create (32.3ms)  INSERT INTO "solid_queue_pauses" ("queue_name", "created_at") VALUES ($1, $2) RETURNING "id"  [["queue_name", "default"], ["created_at", "2024-03-12 22:54:02.941087"]]
  TRANSACTION (6.9ms)  ROLLBACK
  SolidQueue::Pause Load (0.6ms)  SELECT "solid_queue_pauses".* FROM "solid_queue_pauses" WHERE "solid_queue_pauses"."queue_name" = $1 LIMIT $2  [["queue_name", "default"], ["LIMIT", 1]]
Redirected to http://localhost:3000/jobs/applications/XXX/queues?server_id=solid_queue
Completed 302 Found in 75ms (ActiveRecord: 66.1ms | Allocations: 10901)

If I manually send a DELETE (instead of POST) request to the same URL without any body it does properly unpause the queue as expected. I'm not sure how the <input type="hidden" name="_method" value="delete" autocomplete="off"> (which is part of the html form which is being submitted through the resume button) is supposed to work, but I guess it's some kind of fallback for browsers not supporting the delete method for forms?

Started GET "/assets/mission_control/jobs/application-6148a20a46492f80f96ae94c8a893b373e8396c7.css" for 127.0.0.1 at 2024-03-13 00:21:26 +0100
Started DELETE "/jobs/applications/XXX/queues/default/pause?server_id=solid_queue" for 127.0.0.1 at 2024-03-13 00:21:29 +0100
Processing by MissionControl::Jobs::Queues::PausesController#destroy as */*
  Parameters: {"server_id"=>"solid_queue", "application_id"=>"XXX", "queue_id"=>"default"}
  SolidQueue::Job Load (8.4ms)  SELECT DISTINCT "solid_queue_jobs"."queue_name" FROM "solid_queue_jobs"
  SolidQueue::Pause Load (2.3ms)  SELECT "solid_queue_pauses".* FROM "solid_queue_pauses" WHERE "solid_queue_pauses"."queue_name" = $1  [["queue_name", "default"]]
  SolidQueue::ReadyExecution Count (2.0ms)  SELECT COUNT(*) FROM "solid_queue_ready_executions" WHERE "solid_queue_ready_executions"."queue_name" = $1  [["queue_name", "default"]]
  SolidQueue::Pause Delete All (20.0ms)  DELETE FROM "solid_queue_pauses" WHERE "solid_queue_pauses"."queue_name" = $1  [["queue_name", "default"]]
Redirected to http://localhost:3000/jobs/applications/XXX/queues?server_id=solid_queue
Completed 302 Found in 38ms (ActiveRecord: 32.7ms | Allocations: 4449)

Lemme know if I can help and sorry in case it's not related to the PR here!

@zavan
Copy link
Contributor Author

zavan commented Jul 24, 2024

Branch rebased and fixed CSS importing, if anyone wants to try it:

gem "mission_control-jobs", github: "zavan/mission_control-jobs", branch: "api-only"

@InteNs
Copy link

InteNs commented Jul 30, 2024

I'm testing this for one of our apps that does not have any UI.

so far no issues!

@InteNs
Copy link

InteNs commented Jul 30, 2024

disregard, everything is awesome! (sorry for polluting the thread!)

previous text

Unfortunately i'm having some troubles:

  • filtering on job_class or queue name does not send a request at all
  • getting some errors loading javascript
    Untitled 2

@zavan
Copy link
Contributor Author

zavan commented Jul 30, 2024

@InteNs can you tell me a bit more about your application? Rails version? Are you using API-only mode? Do you have propshaft or sprockets in your gemfile?

@InteNs
Copy link

InteNs commented Jul 30, 2024

Disregard everything, this was related to multiple issues with CORS, CSP and asset_host/path

nothing with mission_control itself

previous text

sorry!
Rails -> 7.1.3.4

  • api_only mode is not actually enabled.
  • No propshaft (except from the new dependency in this PR)
  • No sprockets
  • disabled rails frameworks:
# require "active_model/railtie"
# require "active_storage/engine"
# require "action_mailer/railtie"
# require "action_mailbox/engine"
# require "action_text/engine"
# require "action_cable/engine"

edit:
Do i need to do something to setup propshaft properly? (run assets:precompile or something?) I've done nothing except for adding this branch as the gem version

edit2:
I've noticed that when fetching assets it forgets the nested path that mission control is mounted on:

  constraints host: METRICS_DOMAIN do
    scope(path: "/metrics/jobtest_market") do
      mount MissionControl::Jobs::Engine => "/jobs"
    end
  end

this is when navigating to a local instance:
image

yet another edit!

It seems that the issue is related to me making the dashboard accessible through an alternative domain
something like this may work:

MyApp::Application.configure do
  config.action_controller.asset_host = "http://www.myapp.com"
end

@arikarim
Copy link

Any update on this @rosa ?

@rosa
Copy link
Member

rosa commented Aug 15, 2024

Sorry, I hadn't realised this was ready. I thought there was still an issue, but I see it was not related to Mission Control in the end. I'll try to review next week!

@InteNs
Copy link

InteNs commented Aug 18, 2024

@zavan any chance you can merge main into this? I need the updated recurring tasks support ;)

@zavan
Copy link
Contributor Author

zavan commented Aug 19, 2024

@InteNs merged (but untested), if you want to try it.

@rosa @arikarim I think this is still a pending issue, not sure. I don't have enough free time right now to check.

@rosa
Copy link
Member

rosa commented Aug 19, 2024

@zavan thanks a lot! I was just testing this locally, and I can't reproduce that issue. Things look good to me here:

Screenshot 2024-08-19 at 15 28 11

Copy link
Member

@rosa rosa left a comment

Choose a reason for hiding this comment

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

Amazing work here @zavan, thanks a lot! 🙇‍♀️

@rosa rosa merged commit 7f71ec8 into rails:main Aug 19, 2024
5 checks passed
@rosa rosa mentioned this pull request Aug 21, 2024
@sebglazebrook
Copy link

sebglazebrook commented Sep 7, 2024

Hi, just wanted to see if this is going to be pushed out as a version change soon.

Thanks!

@rosa
Copy link
Member

rosa commented Sep 7, 2024

@sebglazebrook, is it working ok for you? I think there were still a few open issues that I haven't had the time to look at 😳 And realistically, I won't have time until at least a month from now. The open issues are here, one is about CSS and the other one is the Queue Pause button being broken.

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.

6 participants