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

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

Conversation

zavan
Copy link

@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!

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.

None yet

3 participants