Do engines get unloaded?

I notice this a bunch when working with the katello api:

With body: {"displayMessage":"undefined method without_deleting&#39; for #&lt;Class:0x0000000bb7cfb8&gt;&quot;,&quot;errors&quot;:[&quot;undefined methodwithout_deleting' for #<Class:0x0000000bb7cfb8>"]}

The cause of this is that the app is not seeing the engines extensions
to base foreman objects. Could the runtime be unloading the engine some
how? Do we know if this will lessen when not in development mode?

– bk

Depends on the mode: in development mode, the app reloads models
(potentially) on every request, which can (and eventually does) result
in the app losing dynamically added changes. If you switch into the
production mode, you will no longer see this issue.

-d

··· On Thu, Dec 12, 2013 at 7:59 PM, Bryan Kearney wrote: > I notice this a bunch when working with the katello api: > > With body: {"displayMessage":"undefined method `without_deleting' for > #","errors":["undefined method `without_deleting' > for #"]} > > > The cause of this is that the app is not seeing the engines extensions to > base foreman objects. Could the runtime be unloading the engine some how? Do > we know if this will lessen when not in development mode? > > -- bk > > -- > You received this message because you are subscribed to the Google Groups > "foreman-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to foreman-dev+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out.

Ivan showed me this extension to ActiveSupport, which you can use to
re-extend constants when they're reloaded. It's used in foreman_hooks
so hooks get re-registered when something like Host::Managed gets reloaded:

If you abstract out the extensions from initialisers then you could
re-extend classes from both.

··· On 12/12/13 20:13, Dmitri Dolguikh wrote: > Depends on the mode: in development mode, the app reloads models > (potentially) on every request, which can (and eventually does) result > in the app losing dynamically added changes. If you switch into the > production mode, you will no longer see this issue.


Dominic Cleal
Red Hat Engineering

> > Depends on the mode: in development mode, the app reloads models
> > (potentially) on every request, which can (and eventually does) result
> > in the app losing dynamically added changes. If you switch into the
> > production mode, you will no longer see this issue.
>
> Ivan showed me this extension to ActiveSupport, which you can use to
> re-extend constants when they're reloaded. It's used in foreman_hooks
> so hooks get re-registered when something like Host::Managed gets reloaded:
>
> https://github.com/theforeman/foreman_hooks/blob/master/lib/foreman_hooks.rb#L79-L91
>
> If you abstract out the extensions from initialisers then you could
> re-extend classes from both.

Also, config.to_prepare should do the trick, as ohad does here

https://github.com/ohadlevy/foreman-background/blob/master/lib/foreman-background/engine.rb#L17

the to_prepare block gets called once in production and on every request in development. It's
probably a bit cleaner way of doing this kind of things.

– Ivan

··· ----- Original Message ----- > On 12/12/13 20:13, Dmitri Dolguikh wrote:


Dominic Cleal
Red Hat Engineering


You received this message because you are subscribed to the Google Groups
"foreman-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hmm, foreman_hooks is using that, maybe I should re-investigate some
time and see why it wasn't sufficient.

··· On 13/12/13 10:10, Ivan Necas wrote: > > > ----- Original Message ----- >> On 12/12/13 20:13, Dmitri Dolguikh wrote: >>> Depends on the mode: in development mode, the app reloads models >>> (potentially) on every request, which can (and eventually does) result >>> in the app losing dynamically added changes. If you switch into the >>> production mode, you will no longer see this issue. >> >> Ivan showed me this extension to ActiveSupport, which you can use to >> re-extend constants when they're reloaded. It's used in foreman_hooks >> so hooks get re-registered when something like Host::Managed gets reloaded: >> >> https://github.com/theforeman/foreman_hooks/blob/master/lib/foreman_hooks.rb#L79-L91 >> >> If you abstract out the extensions from initialisers then you could >> re-extend classes from both. > > Also, config.to_prepare should do the trick, as ohad does here > > https://github.com/ohadlevy/foreman-background/blob/master/lib/foreman-background/engine.rb#L17 > > the to_prepare block gets called once in production and on every request in development. It's > probably a bit cleaner way of doing this kind of things.


Dominic Cleal
Red Hat Engineering

> >
> >
> >>> Depends on the mode: in development mode, the app reloads models
> >>> (potentially) on every request, which can (and eventually does) result
> >>> in the app losing dynamically added changes. If you switch into the
> >>> production mode, you will no longer see this issue.
> >>
> >> Ivan showed me this extension to ActiveSupport, which you can use to
> >> re-extend constants when they're reloaded. It's used in foreman_hooks
> >> so hooks get re-registered when something like Host::Managed gets
> reloaded:
> >>
> >>
> https://github.com/theforeman/foreman_hooks/blob/master/lib/foreman_hooks.rb#L79-L91
> >>
> >> If you abstract out the extensions from initialisers then you could
> >> re-extend classes from both.
> >
> > Also, config.to_prepare should do the trick, as ohad does here
> >
> >
> https://github.com/ohadlevy/foreman-background/blob/master/lib/foreman-background/engine.rb#L17
> >
> > the to_prepare block gets called once in production and on every request
> in development. It's
> > probably a bit cleaner way of doing this kind of things.
>
> Hmm, foreman_hooks is using that, maybe I should re-investigate some
> time and see why it wasn't sufficient.
>
>
Katello is making use of config.to_prepare as well and still encountering
the above issues mentioned occasionally.

··· On Fri, Dec 13, 2013 at 5:14 AM, Dominic Cleal wrote: > On 13/12/13 10:10, Ivan Necas wrote: > > ----- Original Message ----- > >> On 12/12/13 20:13, Dmitri Dolguikh wrote:


Dominic Cleal
Red Hat Engineering


You received this message because you are subscribed to the Google Groups
"foreman-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.