Dynflow async task in rails intializer

Hi,

In the Katello plugin,
I'm trying to kick of a long running async task when rails starts. Putting
the following snippet in lib/katello/engine.rb doesn't seem to execute the
the task asynchronously:

  initializer 'katello.subs_sync', :after => 

"katello.set_dynflow_middlewares" do |app|
ForemanTasks.async_task Katello::Actions::SubscriptionsSync
end

Since there is a continuous loop in the task, It blocks and prevents rails
from continuing to startup. Is there a way to do what I'm trying to do?

Thanks! Dustin

How does the action look like? Also, it should be ::Actions::Katello, not ::Katello::Actions (as this one is deprecated)

– Ivan

··· ----- Original Message ----- > Hi, > > In the Katello plugin, > I'm trying to kick of a long running async task when rails starts. Putting > the following snippet in lib/katello/engine.rb doesn't seem to execute the > the task asynchronously: > > initializer 'katello.subs_sync', :after => > "katello.set_dynflow_middlewares" do |app| > ForemanTasks.async_task Katello::Actions::SubscriptionsSync > end > > Since there is a continuous loop in the task, It blocks and prevents rails > from continuing to startup. Is there a way to do what I'm trying to do? > > Thanks! Dustin > > -- > 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/d/optout. >

Hi Ivan,

Thanks for getting back to me so quickly. I changed my code from earlier, I
wasn't using suspend so it was continuing to run, preventing rails from
starting. I updated the action so that it uses the Dynflow::Action::Polling module
instead since it seemed to fit. Here's the contents of the action
currently:

However, there's one issue I'm still having difficulty with. I'm unable to
stop the rails server with ctrl-c. The job continues to run in the
background and I kill the process in order for rails to stop. Is there a
way to stop the job when rails stops?

  • Dustin
··· On Tuesday, July 8, 2014 8:43:49 AM UTC-7, Ivan Necas wrote: > > How does the action look like? Also, it should be ::Actions::Katello, not > ::Katello::Actions (as this one is deprecated) > > -- Ivan > > ----- Original Message ----- > > Hi, > > > > In the Katello plugin, > > I'm trying to kick of a long running async task when rails starts. > Putting > > the following snippet in lib/katello/engine.rb doesn't seem to execute > the > > the task asynchronously: > > > > initializer 'katello.subs_sync', :after => > > "katello.set_dynflow_middlewares" do |app| > > ForemanTasks.async_task Katello::Actions::SubscriptionsSync > > end > > > > Since there is a continuous loop in the task, It blocks and prevents > rails > > from continuing to startup. Is there a way to do what I'm trying to do? > > > > Thanks! Dustin > > > > -- > > 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...@googlegroups.com . > > For more options, visit https://groups.google.com/d/optout. > > >

Originally, the dynflow actions were not meant to be continuously running the whole
time the server is running and serve as the listening services. On the other hand,
I see the benefits of having this services trackes as dynflow/foreman tasks as it
can serve as the status indicator of the service.

For the issue for terminating on exit, you would need to hook to the on exit event and cause the termination. There are also better ways for managing it than just polling. Let me write some snipped to give you some pointers (I'm not sure I will get to it today though :frowning:

– Ivan

··· ----- Original Message ----- > Hi Ivan, > > Thanks for getting back to me so quickly. I changed my code from earlier, I > wasn't using suspend so it was continuing to run, preventing rails from > starting. I updated the action so that it uses the Dynflow::Action::Polling > module > instead since it seemed to fit. Here's the contents of the action > currently: > https://github.com/dustint-rh/katello/blob/1bc8dfe8829eb1bd3c3785b689e2ab288745ee5d/app/lib/actions/katello/subscription/poll_qpid_queue.rb#L16 > > However, there's one issue I'm still having difficulty with. I'm unable to > stop the rails server with ctrl-c. The job continues to run in the > background and I kill the process in order for rails to stop. Is there a > way to stop the job when rails stops? > > - Dustin > > > > > > > > On Tuesday, July 8, 2014 8:43:49 AM UTC-7, Ivan Necas wrote: > > > > How does the action look like? Also, it should be ::Actions::Katello, not > > ::Katello::Actions (as this one is deprecated) > > > > -- Ivan > > > > ----- Original Message ----- > > > Hi, > > > > > > In the Katello plugin, > > > I'm trying to kick of a long running async task when rails starts. > > Putting > > > the following snippet in lib/katello/engine.rb doesn't seem to execute > > the > > > the task asynchronously: > > > > > > initializer 'katello.subs_sync', :after => > > > "katello.set_dynflow_middlewares" do |app| > > > ForemanTasks.async_task Katello::Actions::SubscriptionsSync > > > end > > > > > > Since there is a continuous loop in the task, It blocks and prevents > > rails > > > from continuing to startup. Is there a way to do what I'm trying to do? > > > > > > Thanks! Dustin > > > > > > -- > > > 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...@googlegroups.com . > > > For more options, visit https://groups.google.com/d/optout. > > > > > > > -- > 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/d/optout. >