How a Quartz.Net job can be triggered manually? - quartz.net

I have a windows service which is responsible to create JobStoreTX instance, fetch and run the jobs persisted on database.
We need a way to trigger some jobs manually. IScheduler interface has a TriggerJob(...) method but we want to give this triggering order with using database (maybe insert or update).
Is that possible? I cannot found any way even in Quartz.Net documentation.

Related

Sidekiq query for job completion

I have an admin dashboard action in a react front end using a ruby on rails API back end. I have a sidekiq job that runs to import users from a third party. I would like to somehow trigger a refresh on the admin panel when the job is complete. What is the best way to go about this? I am using graphql-ruby. I could use start-polling on the front end maybe? Can I poll for completion of a specific job on sidekiq somehow? Any help is appreciated!
Hi Ilovebathroomlights
There are several approaches I can use, one of them I am writing below assuming you are okay to write a state to Redis, Database, or any storage you might be using and can be used to poll.
You can start by assigning a unique id to your sidekiq job, and save this id with status as "pending", at the last line inside the sidekiq job code, update the status of the unique id as "completed".
In meantime, you can poll by the unique id you generated for the particular job, and refresh the data or refresh the page.

Which Ruby / Rails Background Job Framework should I use (that works on Heroku) for dynamically adding future jobs in Rails

So I created a client-server (Rails for both client and server) system that will have many clients with one server, that interact using REST.
The clients can send / update / delete their own "Jobs" on the server, which is right now simply a table named Jobs. The Jobs belongs_to a table named Apps, which ofcourse has_many jobs (each App entry represents a client, so the client can only add / delete / update / read their jobs on the server).
The purpose of this, is so the client can add entries to the Jobs table and specify a Time of Day (in the future), that they can run a Job. The Job that gets run is a call to a 3rd party email-service to send an email.
So I need a Jobs framework, that can easily run on Heroku, and iterate through my Jobs table (say, every half-hour.. Or even every 5 minutes maybe..), and see if there are any Jobs it needs to run based on a datetime column (check if the datetime entry is equal-to, or less-than the current-time the Worker is running)
Which is the best Rails / Heroku Job framework I should use for this?
I prefer simplicity, so I was looking at:
https://devcenter.heroku.com/articles/scheduler
But, I cannot use this because it warns:
Scheduler is a “best effort” service, meaning that execution is expected but not guaranteed. Scheduler is known to occasionally (but rarely) miss the execution of scheduled jobs"
So next I looked at at https://devcenter.heroku.com/articles/scheduled-jobs-custom-clock-processes - which can be implemented using Gems like Resque or Delayed Job.. Which I am currently researching now..
Ideally, I wanted to be able to find a Job Framework that would compliment (or replace) my jobs table (So, Whenever I add something to my Jobs table or delete it, each of my Job entries would have a 1:1 relation with an actual Job in the Job framework, that I would also be adding / updating / deleting when I add / update / delete an entry on my Jobs table and / or the Jobs entry in the Job Framework). Ofcourse I would be writing the logic for all the CRUD operations on the server (once it receives a REST call from the client) - But the client needs to be able to delete and re-add all it's jobs on the server at any-moment; and I did not see any Job frameworks that would allow me to dynamically add and remove future jobs at any given time, dynamically. All the existing frameworks seem like they are created for scheduled jobs to run at specific times or time intervals, specified in a config file. Which is fine, but I wanted to check on S.O to verify that I am making the best decision when choosing my setup / framework
Sorry for the long / complex question - and I appreciate any suggestions or recommendations anyone has for me!
Thanks!!!
This sounds like a job for Resque and Resque-scheduler.
Here's a syntax example :
Resque.enqueue_in(5.days.from_now, SendFollowupEmail, argument)
If you need to delete it before it is executed :
Resque.remove_delayed(SendFollowUpEmail, :user_id => current_user.id)

Avoid simultaneous job modifications in Jenkins

I am using the Jenkins Job DSL Plugin to create template jobs.
There is a problem when two or more users are modifying the same template job (or any other job) simultaneously. The configuration of the last user to save or apply the modifications are registered and the modifications of the other user are removed because the two users were working on the same configuration version.
For example: Recently, I had to add a user to the global authorization matrix in a template job. I did that and i saved and build it. However, another user was modifying the same template job all day and he saved it at the end of the day and my changes were removed.
Is there a way to avoid this simultaneous job modifications by locking the configuration of a job for other users when that user is currently updating it?
Not currently available in core.
Full Answer

Delayed searchable jobs in Rails

Is there some background processor in ruby which would allow to find an existing not started delayed jobs by custom key?
I'm trying to solve a task with e-mail notifications, when there could be multiple changes in my model and I want to collect them in batches before sending.
So, I don't want to create another notification job when there is already an existing job, I'd rather append notification info to the existing job.
Any hint?
Thanks,
KIR
I suppose you will need an engine app
https://github.com/trevorturk/delayed_job_admin
Tested and working fine, but requires rails 3.
I think I'm trying to mix concepts here.
Delayed Job's work is to run long tasks.
What I'm looking for is a list of active notifications, which I can easily implement with a custom table.

Monitor database table for external changes from within Rails application

I'm integrating some non-rails-model tables in my Rails application. Everything works out very nicely, the way I set up the model is:
class Change < ActiveRecord::Base
establish_connection(ActiveRecord::Base.configurations["otherdb_#{RAILS_ENV}"])
set_table_name "change"
end
This way I can use the Change model for all existing records with find etc.
Now I'd like to run some sort of notification, when a record is added to the table. Since the model never gets created via Change.new and Change.save using ActiveRecord::Observer is not an option.
Is there any way I can get some of my Rails code to be executed, whenever a new record is added? I looked at delayed_job but can't quite get my head around, how to set that up. I imagine it evolves around a cron-job, that selects all rows that where created since the job last ran and then calls the respective Rails code for each row.
Update Currently looking at Javan's Whenever, looks like it can solve the 'run rails code from cron part'.
Yeah, you'll either want some sort of background task processor (Delayed::Job is one of the popular ones, or you can fake your own with the Daemon library or similar) or to setup a cronjob that runs on some sort of schedule. If you want to check frequently (every minute, say) I'd recommend the Delayed::Job route, if it's longer (every hour or so) a cron job will do it just fine.
Going the DJ route, you'd need to create a job that would check for new records, process them if there are any, then requeue the job, as each job is marked "completed" when it's finished.
-jon
This is what I finally did: Use Whenever, because it integrates nicely with Capistrano and showed me how to run Rails code from within cron. My missing peace was basically
script/runner -e production 'ChangeObserver.recentchanges'
which is now run every 5 minutes. The recentchanges reads the last looked-at ID from a tmp-file, pulls all new Change records which have a higher ID than that and runs the normal observer code for each record (and saves the highest looked-at ID to the tmp-file, of course).
As usual with monitoring state changes, there are two approaches : polling and notification. You seem to have chose to go the polling way for now (having a cron job look at the state of the database on a regular basis and execute some code if that changed)
You can do the same thing using one of the rails schedulers, there are a few out there (google will find them readily, they have various feature sets, I'll let you choose the one which suits your need if you got that way)
You could also try to go the notification way depending on your database. Some database support both triggers and external process execution or specific notification protocols.
In this case you are notified by the database itself that the table changed. there are many such options for various DBMS in Getting events from a database

Resources