Sidekiq remove schedule documentation - ruby

There are 2 methods in the documentation of gem 'sidekiq-scheduler' to work with dynamic schedule (https://github.com/moove-it/sidekiq-scheduler#dynamic-schedule):
Sidekiq.set_schedule('heartbeat', { 'every' => ['1m'], 'class' => 'HeartbeatWorker' })
Sidekiq.get_schedule
But I can't find any method to remove the schedule that was already set before.
Is there a way to find documentation with a full list of methods of the Sidekiq (with method description)?

You can use remove_schedule(name) to remove a schedule that has been set already. You can find more information, including the available methods in the RubyDocs v2.0.20 or v3.0.0.

Related

Padrino route optional parameter

I am trying to do some tricks with routes. And I need to use optional route parameter in Padrino. I googled that solution for this are "()" parenthesis. I couldn't find in docs.
But when I try to use
get :sort, :with => [:order, :asc, '(:search)'] do
them, mustermann is giving me classic error for missing parameter
cannot expand with keys [:asc, :order], possible expansions: [:asc, :order, :search]
when I try to call
url(:sbirka, :sort, :order => "id", :asc => #asc)
I also tried different style
get :sort, "/:order/:asc/(:search)" do
with the same result
Please any suggestions how to do this?
Since Padrino is based on Sinatra, every routing pattern possible with Sinatra should be possible in Padrino as well. From Sinatra's excellent README file, introductory 'Routes' section:
Route patterns may have optional parameters
In your case, assuming :search is optional, I would try:
get '/:order/:asc/:search?' do
# your code
end

What options does the asana api expect in tasks.find_by_id

I'm using the asana gem to access the asana api.
The client documentation for the class method find_by_id exposed on the tasks resource (i.e. Asana::Task) says that it will take a hash of options. As far as I can tell looking at the little code snippet, it should be the same options as are listed on https://asana.com/developers/documentation/getting-started/input-output-options#paths
However, when I do client.tasks.find_by_id(123456, :fields => "this.assignee.email"), for example, I get an ArgumentError: unknown keyword: fields.
What am I doing wrong? How should this work?
Also: it's unclear to me from the above page when I should be using this in my field specifications and when it is unnecessary.
EDIT: SOLVED!
The correct syntax is client.tasks.find_by_id(123456, :options => { :fields => "this.assignee.email" })
Both :fields and "fields" work.
Judging from the code in the ruby client library: https://github.com/Asana/ruby-asana/blob/423f76c14792bd4712c099161a14a10ce941b2d9/lib/asana/http_client.rb#L42
Perhaps something like client.tasks.find_by_id(123456, {"fields" => "this.assignee.email"}) might work. Could you try that?

How can I call a Chef resource from an HWRP?

Maybe this is really simple, and I'm just not understanding something. I want to invoke a Chef resource from within an HWRP that I wrote. In my scenario, I'd like to invoke the reboot resource. How should I go about doing so?
I have tried something like the following:
def reboot_system
wu_reboot = Chef::Resource::Reboot.new('wu_reboot', :reboot_now)
wu_reboot.run_action(:reboot_now)
end
A few things. I am not sure if I should be creating an instance of Chef::Resource::Reboot or Chef::Provider::Reboot. I also don't really understand the second argument listed above..this is supposed to be the "run_context", but I don't know what that is. Finally, I do not know how to set attributes or invoke an action.
I tried using this as a format to go by, but I haven't been able to get it to work so far. Any help understanding would be much appreciated.
EDIT:
I looked at the source code and I could just execute this:
node.run_context.request_reboot(
:delay_mins => #new_resource.delay_mins,
:reason => #new_resource.reason,
:timestamp => Time.now,
:requested_by => #new_resource.name
)
However, I don't think this is the best solution. I would like to know how to accomplish invoking the resource instead of bypassing it this way.
You can find an example of using Chef-Resources inside a HWRP in an older revision of the official Jenkins cookbook (was converted to LWRP in the meantime):
https://github.com/opscode-cookbooks/jenkins/blob/v2.0.2/libraries/plugin.rb#L138-L141
Keep in mind, that the Reboot resource is rather new (Chef 12+)
You can do it the same way you would in a recipe. If you need it to run immediately, then you would do:
reboot 'now' do
action :nothing
end.run_action(:reboot_now)
Within Ruby classes, you don't have access to the Chef DSL, so you have to access the underlying implementation of the resource as a class. The name of the class will be the camelcase-conversion of the resource name. You invoke the action with the run_action method.
Your original version actually was pretty close. You only use the resource, not the provider (because the provider may not even always be the same, depending on your platform).
The run_context is an object that chef uses to pass information to the resource - for instance, you can access node attributes through run_context.node['attributename']. It is already a member variable in your provider (and I think also in the resource object); you can simply pass it in to the constructor for your new resource.
You set attributes through member variables by the same name, and you trigger the actual action with the run_action method.
r = Chef::Resource::Reboot.new("wu_reboot", run_context)
r.reason("Because we need a reboot")
r.run_action(:reboot_now)

how to use fireAnbu in laravel 3?

I've installed the bundle fireAnbu in my local laravel 3 app, but I can't figure out how to use it! (feeling silly)
I've got 'fireanbu' => array('auto' => true), in bundles.php and 'profiler' => true, in fireanbu/config/fireanbu.php, and I've tried:
fireanbu::log('something');
$fireanbu->log('something');
FirePHP::log('something');
$FirePHP->log('something');
FB::log('something');
$fb->log('something');
I've had a look in fireanbu/start.php for clues, but I'm guessing :(
The best clue I've had so far is:
Non-static method FirePHP::log() should not be called statically, assuming $this from incompatible context
I've looked at http://www.firephp.org/HQ/Use.htm and it looks like fireanbu is using the OO API..
What am I doing wrong / how should I call it within my controllers?
I also created a Laravel 4 version for this if anyone finds this thread looking for a L4 version (like I did, and in the absence of finding one created my own):
https://packagist.org/packages/p3in/firephp
There no need to do anything. It would listen to event from Laravel's own Log class and attach it to FirePHP.
Log::info('foo'); would just work nicely.

How to do an upsert / push with mongoid / moped

I'm using Mongoid (v3) to access MongoDB, and want to perform this action:
db.sessionlogs.update(
{sessionid: '12345'}, /* selection criteria */
{'$push':{rows: "new set of data"}}, /* modification */
true /* upsert */
);
This works fine in the mongo shell. It's also exactly what I want since it's a single atomic operation which is important to me as I'm going to be calling it a lot. I don't want to have to do two operations -- a fetch and then an update. I've tried a bunch of things through mongoid, but can't get it to work.
How can I get MongoID out of the way and just send this command to MongoDB? I'm guessing there's some way to do this at the Moped level, but the documentation of that library is basically non-existent.
[Answer found while writing the question...]
criteria = Sessionlogs.collection.find(:sessionid => sessionid)
criteria.upsert("$push" => {"rows" => datarow})
Here is one way to do it:
session_log = SessionLog.new(session_id: '12345')
session_log.upsert
session_log.push(:rows, "new set of data")
Or another:
SessionLog.find_or_create_by(session_id: '12345').
push(:rows, "new set of data")
#push performs an atomic $push on the field. It is explained on the
Atomic Persistence page.
(Note: the examples use UpperCamelCase and snake_case as is Ruby convention.)
Don't go down to moped just yet, you can use find and modify operation to achieve the same thing (with all the default scope and inheritance goodies)
Sample to save an edge in a graph if not existed
edge = {source_id: session[:user_id],dest_id:product._id, name: edge_name}
ProductEdge.where(edge).find_and_modify(ProductEdge.new(edge).as_document,{upsert:true})

Resources