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

Rails API with Mission Control #60

Open
tooney92 opened this issue Feb 5, 2024 · 33 comments
Open

Rails API with Mission Control #60

tooney92 opened this issue Feb 5, 2024 · 33 comments
Assignees

Comments

@tooney92
Copy link

tooney92 commented Feb 5, 2024

Is there a way to use mission control UI for a rails API backend application?

@rosa
Copy link
Member

rosa commented Feb 6, 2024

Hey @tooney92, yes! It shouldn't be any difference, as long as your application has jobs that you need to manage, you should be able to use Mission Control for it. Are you encountering any problems there?

@tooney92
Copy link
Author

tooney92 commented Feb 6, 2024

Hi @rosa Thanks for the feedback, this is the error I get

Screenshot 2024-02-06 at 15 17 28

for context, I have no assets folder since my application is purely a rails API.

@rosa
Copy link
Member

rosa commented Feb 12, 2024

Oh, right, of course 🤦‍♀️ The API-only app doesn't know about JS assets or anything related to them. I'd need some more time to figure out how to fix this in your app. Let me know if you fix it!

@rails rails deleted a comment from LAEG31 Feb 22, 2024
@zavan
Copy link
Contributor

zavan commented Feb 23, 2024

I had to give up on API mode to use it.

  1. Added gem "propshaft" to gem file (lighter than sprockets and seems to work for this)
  2. ApplicationController extends ActionController::Base instead of ActionController::API and added protect_from_forgery with: :null_session
  3. Removed config.api_only = true from config/application.rb

@tooney92
Copy link
Author

Thanks @zavan I think I would try this route. Thank you also @rosa for helping out. Will close the issue now :)

@joshforbes
Copy link

I'm not exactly sure how they do it but Sidekiq has a web UI that works with an API-only Rails app.

https://github.com/sidekiq/sidekiq/wiki/Monitoring#rails

If anyone has a solution that doesn't involve leaving API mode, I'd be interested in hearing it. 🙏

@zavan
Copy link
Contributor

zavan commented Feb 27, 2024

@joshforbes They are using a custom rack app to handle routes, views and assets (see https://github.com/sidekiq/sidekiq/tree/main/lib/sidekiq/web). I don't think that's a good option for Mission Control as it's Rails-based.

I may be wrong, but maybe it's possible for the Mission Control Rails engine to load its required middleware if they're not loaded already by the main Application, and add a propshaft dependency if necessary.

@rosa
Copy link
Member

rosa commented Feb 27, 2024

@zavan yes! I think we could make it work; it's just that we didn't think about API mode when we built this. I probably won't have time to work on this soon, but if anyone wants to try, it'd be super welcome. Otherwise, we'll eventually get to it 😊

@zavan
Copy link
Contributor

zavan commented Feb 27, 2024

@rosa Can you take a look at #87?

@joshforbes @tooney92 If you could test the branch out on your applications that would help too:

gem "mission_control-jobs", git: "https://github.com/basecamp/mission_control-jobs.git", ref: "pull/87/head"

@tooney92
Copy link
Author

Will do @zavan

@tooney92
Copy link
Author

Screenshot 2024-02-28 at 12 11 40
Screenshot 2024-02-28 at 12 12 07

Got these errors. I attached my gem file

@zavan
Copy link
Contributor

zavan commented Feb 28, 2024

@tooney92 Yeah I got this a few times too but it worked at some point. Can you try using the branch from my fork please:

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

@MarcMogdanz
Copy link

@tooney92 Yeah I got this a few times too but it worked at some point. Can you try using the branch from my fork please:

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

Can confirm that this works for my API-only Rails app without any issues so far, thank you so much for your work!

@grin
Copy link

grin commented Mar 20, 2024

I know this is being addressed, just wanted to mention this is not an api-only issue. You'll get the same error if you use something like vite_ruby to manage the assets in your app.

@fabianof
Copy link

Hi, @zavan.

First of all, thanks for your PR focused on API-only apps.

I tried it out, but somehow columns for error and button actions, as well as "Recurring tasks" menu item, are not being shown.

This is what I get from mission_control-jobs 0.2.0 together with sprockets-rails:

Screenshot 2024-03-27 at 15 59 13

This is what I get from mission_control-jobs 0.2.0 together with propshaft (no error column, no discard and retry buttons per job entry):

Screenshot 2024-03-27 at 16 07 31

This is what I get from your PR (no error column, no discard and retry buttons per job entry, no "Recurring tasks" menu item):

Screenshot 2024-03-27 at 15 58 49

Could you please let me know we need any additional changes?

@zavan
Copy link
Contributor

zavan commented Mar 27, 2024

Hey @fabianof, this is because my branch is behind v0.2.0.

I’ll come back to this PR tomorrow and hopefully get it ready to merge.

@fabianof
Copy link

Not sure word breaking will be handled by your branch:

317484959-b4af84ff-f784-4e88-bfde-9a4dda40d2c9

This is what we get from sprockets-rails out of the box:

.jobs td {
   word-break: break-all;
}

Which prevents layout breaking when job has huge words:

317484867-ab16b460-d229-4c55-9e13-23c55ca73102

@fabianof
Copy link

The issue is that following CSS is rendered out of the box by sprockets-rails, but not by propshaft.

.jobs td {
   word-break: break-all;
}

https://github.com/zavan/mission_control-jobs/blob/api-only/app/assets/stylesheets/mission_control/jobs/jobs.css

@fabianof
Copy link

Hi, @zavan. Are you planning coming back to this change any time soon? Unfortunately we are still facing the issue.

Somehow Mission Control Jobs CSS is handled out of the box by sprockets-rails, but not by propshaft.

.jobs td {
   word-break: break-all;
}

https://github.com/zavan/mission_control-jobs/blob/api-only/app/assets/stylesheets/mission_control/jobs/jobs.css

Not sure you will be able to handle that as well.

@zavan
Copy link
Contributor

zavan commented Jul 24, 2024

@fabianof I have rebased my branch to be current with main and I believe fixed the CSS importing.

Can you try it?

@fabianof
Copy link

fabianof commented Aug 8, 2024

Issue persists, @zavan. Somehow Mission Control jobs styles are not being loaded properly. Note that word break is missing here, which prevents showing other dashboard columns:

Screenshot 2024-08-08 at 16 42 26

@arikarim
Copy link

Thanks for your pr @zavan
There is an issue with pausing a queue then resuming it.
currently if you pause a queue it will work, but clicking on resume does not do anything an the queue will stuck including all the jobs inside it.

@rosa
Copy link
Member

rosa commented Aug 19, 2024

@arikarim, huh! That's weird, let me look into that.

@rosa
Copy link
Member

rosa commented Aug 19, 2024

Hmm... @arikarim, I can't reproduce that. Pausing and resuming is working correctly for me, with Solid Queue. Are you referring to Solid Queue or Resque? And can you grab the logs for the Resume request?

@arikarim
Copy link

Hello @rosa thanks for your quick response.
It is so weird, clicking on resume button still sends the pause request.
I am using rails in API mode with solid_queue, also im using @zavan 's forked branch.
image

@rosa
Copy link
Member

rosa commented Aug 19, 2024

That's correct, the request goes to /pause but it should send _method: delete. Does it? Could you check the server logs for that request too?

@arikarim
Copy link

below is the server log:
I, [2024-08-19T14:11:19.737117 #21] INFO -- : [5c99e992-5262-4234-b065-caad31d57be7] {"method":"POST","path":"/jobs/applications/beasprocessesapi/queues/default/pause","format":"turbo_stream","controller":"MissionControl::Jobs::Queues::PausesController","action":"create","status":302,"allocations":3279,"duration":9.33,"view":0.0,"db":4.46,"location":"http://localhost:3000/jobs/applications/beasprocessesapi/queues"}

@rosa
Copy link
Member

rosa commented Aug 19, 2024

Hm... yeah, that's the pause request... so weird. I'll try again to reproduce it.

@rosa rosa reopened this Aug 20, 2024
@rosa rosa self-assigned this Aug 20, 2024
@Jay-Dabo
Copy link

Jay-Dabo commented Sep 7, 2024

After installing i get

{"error":"undefined method `length' for nil"}

on my web

@sasharevzin
Copy link

if css used as CDN, can't we have custom CSS be embedded with <style> tags and remove propshaft despendency?

@HLFH
Copy link

HLFH commented Oct 21, 2024

Since 0.3.3 release, we are getting the error:

/Users/MYUSER/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-8.0.0.rc1/lib/rails/railtie/configuration.rb:109:in `method_missing': undefined method `assets' for an instance of Rails::Application::Configuration (NoMethodError)
Did you mean?  asset_host
        from /Users/MYUSER/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-0.3.3/lib/mission_control/jobs/engine.rb:90:in `block in <class:Engine>'

To revert to the working API-only version, please do the following in your Gemfile:

# Active Job dashboard
gem "mission_control-jobs", "0.3.2"

@blocknotes
Copy link

@sasharevzin: I was trying the same idea but from a fast check you would have troubles with hotwire/turbo rails (used for example for filtering).

From my standpoint, the UI could be updated to use only inline resources (without Hotwire I suppose).
Or creating a bundle of the JS files and loading it from the CDN (since Bulma is loaded via cdn.jsdelivr.net).

Both ways require some effort (in different ways).

@wilbertliu
Copy link

wilbertliu commented Oct 31, 2024

Anyone know what happened here?

I'm on Rails 8 rc2 with Inertia and vite_ruby. Posting here because I saw @grin said vite_ruby users are also affected.

CleanShot 2024-10-31 at 13 29 22@2x
CleanShot 2024-10-31 at 13 31 17@2x

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

No branches or pull requests