Just want to verify about searchkick callback :async - ruby-on-rails-4

I'm just curios what really happening when you choose callback :async? Is it really creating a job worker to execute on the background?
Is this response really going to background jobs?
Performed Searchkick::ReindexV2Job from Inline(searchkick) in 34.64ms Enqueued Searchkick::ReindexV2Job (Job ID: 8f7cfec0-1c3b-4bae-8902-7f6ff6d7b3e8) to Inline(searchkick) with arguments: "Product", "175434", nil, {:routing=>nil}
I tried checking on the sidekiq dashboard but it didn't appear.
Can someone know this? Thanks
Validating if callback: :async is running in background or not
searchkick version: v3.1.3

Related

Is it possible to pause the django background tasks?

For example I have a django background task like this.
notify_user(user.id, repeat=3600, repeat_until=2020-12-12 00:00:00)
Which will repeat every 1 hour until some datetime.
My question is :
Is it possible to pause/resume this task? (if not possible to resume then restart the task again would be fine also).
Is there someone who is experienced with django background tasks ?
There doesn't appear to be a documented way of achieving this, but you can always delete the task from the DB.
For example:
from background_task.models import Task
task = notify_user(user.id, repeat=3600, repeat_until=2020-12-12 00:00:00)
instance = Task.objects.get(id=task.pk)
instance.delete()
Now just call the task again to restart it:
task = notify_user(user.id, repeat=3600, repeat_until=2020-12-12 00:00:00)

Django Signals for task plannification

I try to found the best way to manage this issue with Django Signals:
I created a datamodel with a table ExecutionPlan
In this table I simply store task to execute at a "startDate" value.
I would like to be "signaled" when a "execution line" have a "startDate < Now"
I read Django documentation on signals but I didn't found any case where a signal is send for "a data value check", in my case when a startdate is outpassed.
So my question is more methodic than technical:
Do you think that Django Signals is designed for that case ?
Should I design my own event loop ?
Thanks in advance.
Cyril
You can create a cronjob that runs every X minutes (using django-cron for example) that checks if now>startDate and starts the task if needed.

Check if SKNode has a certain action running

I have a SKNode that is running different actions.
Depending on the running action I want to trigger other behaviours. For that I would need to find out how to check which action is currently running on my SKNode.
I know of .hasActions() but this is returning a general true/false value, which does not help me in my situation.
Does anyone have a better solution?
Thanks in advance
When you start running an action, you assign a key to it using this method:
yourNode.run(someAction, withKey: "someKey")
You can then get the action with your key using:
yourNode.action(forKey: "someKey")
If the above cal returns nil, that means the node is not running the action!

Ruby on Rails working in background [resque + resque-status]

I am building a webapp using ruby on rails that requires running C++ exe programs in the background. I compared 3 most frequently used gems for this(Delayed_Jobs, Resque, Sidekiq) and found that resque is the most suitable for me.
In Countroller I have create method like this
def create
#model = Model.create(model_params)
# resque processe the file from the #model
Resque.enqueue(JobWorker, #model.file.url)
redirect_to model_path(#model.id)
end
In Worker class I have
class JobWorker
#queue = :file
def perform file_to_process
# calling time consuming C++ here which generates 2 image files.
system('my_file_processing_program "#{file_to_process}"')
end
end
Now my question is how should I detect that job has finished? I want to send gemerated image file to client once images are generated by C++ application.
which usercan view/download.
As redirect_to model_path(#model.id) will return after Resque.enqueue(JobWorker, #model.file.url) in the create in controller.
I tried using resque-status but that requires polling in the controller to check the status like...
while status = Resque::Plugins::Status::Hash.get(job_id) and !status.completed? && !status.failed?
sleep 1
puts status.inspect
end
Any suggestions?? Thank you in Advance...
If you want to go asynchronous system like faye(http://faye.jcoglan.com/ruby.html) so you can send a message to the frontend when the process is done. Write the code to publish a message after your system code finishes execution.
Another simple step, though might not be feasible for you is to send an email at the end of the process. You can send an email to the client letting them know "that the process is complete visit link to see the result."

libPusher pod issues - Disconnection during channel subscription

I'm using the libPusher pod in a Ruby Motion project but running into an issue where my code works when used in the REPL but not in the app itself.
When I try this code in a viewDidAppear method it connects successfully and then disconnects during the channel subscription call.
When I try it in the console, it connects and subscribes perfectly. (same code)
I'm trying to figure out:
Why this is happening
What should I change to alleviate the issue?
I'm using v 1.5 of the pod v2.31 of Ruby Motion
For reference, I'm also using ProMotion framework but I doubt that has anything to do with the issue.
Here's my code:
client = PTPusher.pusherWithKey("my_pusher_key_here", delegate:self, encrypted:true)
client.connect
channel = client.subscribeToChannelNamed("test_channel_1")
channel.bindToEventNamed('status', target: self, action: 'test_method:')
Well I got it working by separating the connection and subscription calls into separate lifecycle methods.
I put:
client = PTPusher.pusherWithKey("my_pusher_key_here", delegate:self, encrypted:true)
client.connect
into the viewDidLoad method
and:
channel = client.subscribeToChannelNamed("test_channel_1")
channel.bindToEventNamed('status', target: self, action: 'test_method:')
into the viewDidAppear method.
I can't say I know exactly why this worked but I assume it has to do with the time between the calls. The connection process must need a little time to complete.