run automatically - asp.net-mvc

Is it possible to run a part of code automatically in asp.net or mvc at special time. for example send mail to a group pf users exactly at 8 in the morning ( only by server and not by user)

No, but there are a few ways you could do it:
Quartz.net
A powershell script (which calls into the code you want to run) and job scheduler
A console application (which exposes and calls the code you want to run) and job scheduler

Related

Trying to run Python script without interrupting Rails server

I am trying to run a Python script from a Rails app. This script can POST progress updates to the Rails server by calling:
requests.post('http://127.0.0.1:3000/progress', data={'progress':'10'})
I've tried a few methods to get the Rails server to start the Python script and immediately continue with the rest of its work. It needs to be free to respond to the user and to receive the above progress updates.
I've tried:
In a controller method that also renders a view:
system `python3 /path/to/script.py`
out, err, st = Open3.capture3('python3', 'path/to/script.py')
Both of the above in an after_action.
Both of the above in an active_job.
In every case, as soon as the script is initiated, the server basically hangs, as if it's waiting. The test script I'm using only sends one progress update then exits, so it shouldn't be causing a major delay even if the server is waiting for it to finish.
What is going on here, and how can I run the script in background properly so my Rails server is available to respond to it?
ActiveJob should work. Try this:
in the console generate a new Job
rails g job SlowPython
move your slow python script into app/jobs/script.py
open the new file in app/jobs/slow_python_job.rb and add python3 /app/jobs/script.py in the perform function
In the controller's method you want it to run add SlowPythonJob.perform_later
Now when you open that controllers action in the browser it will queue the job and run it in the background while running the rest of the action immediately. ActiveJob also lets you run SlowPythonJob.perform_now which will run the job and wait for it to finish before running the rest of the action.
What all that does is tell rails to execute the perform method of SlowPythonJob through the Active Job Async Job queue adapter. This works well for the development environment. Keep in mind you will have to set up another queue adapter to handle the job queue in production since Active Job Async Job will drop all the jobs if there is a crash... and it isn't as fast or has as many features as the other ones.
Here is a list of queue adapters: http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html

Jenkins plugin code that should excute before any kind of job is run in Jenkins

I am new to Jenkins plugin development. M trying to write a plugin that should be executed before any Multi configuration type job runs in Jenkins.
In this plugin I want to write rules that will check what configuration parameters user has selected while submitting the job, based on selected parameters, I want to decide whether to allow the job to run or to restrict it.
User should be shown reason as to why that job cannot be run in the Console Output.
Does anyone have any ideas which class I need to extend or which interface I need to implement in order to get a hook into Jenkins job run?
You could look at the Matrix Execution Strategy which allows for a groovy script to select which matrix combinations to run. I would think if your script threw an exception it would stop the build.
For background, the multi configuration projects run a control job (or flyweight) which runs the SCM phase then starts all the actual combinations. This plugin runs after the flyweight SCM checkout.
If nothing else, this will give you a working plugin to start from
Disclaimer: I wrote this plugin
Blocked queue job plugin was what I needed
Out of the box that plugin supports two ways to block the jobs -
Based on the result of last run of another project.
Based on result of last run of the current project
In that plugin the BlockQueueItemTaskDispatcher.java extends Jenkin's QueueTaskDispatcher providing us a hook into Jenkins logic to allow or block the jobs present in the queue from running.
I used this plugin as a starting point for developing a new plugin that allows us to restrict project based on parameters selected and the current time. Ultimate goal is to restrict production migrations from running during the day.
Overriding the isBlocked() method of QueueTaskDispatcher gave access to hudson.model.Queue.Item instance as an argument to me. Then I used the Item instance's getParams method to get access to build parameters selected by the user at runtime. Parsed the lifecyle value from it. Checked the current time. If lifecycle was Production and current time was day time then restricted the job by returning non null CauseOfBlockage from isBlocked() method. If that condition was false, then returnedCauseOfBlockage as null allowing the queued job to run.

configure grid extra (groupon) with jenkins in order to run cucumber tests

I'm struggling with something for quite a while and can't find a solution,
I got a test project (cucumber, maven) I configure jenkins to pull the project from github, build and execute the code (selenium test script) on jenkins slave and that works perfect, I added few more slave, tagged them and I'm able to execute the same job parallel(the same test cases on different machines)
my next step is to use grid extra (https://github.com/groupon/Selenium-Grid-Extras) in order to use some cool features like video recording, browser updating, selenium updates etc...
now, I know that in order to use the grid I need to address it via my code and also define the desired capabilities (browser, os etc...).
currently when I'm running the same job twice, my second request will be queued till the first one ends, if I will run the same code from two developers machine it will run at 2 different nodes and the grid can handle both request.
not sure what is wrong with my jenkins configuration or my grid hub configuration, I checked it again and again and all looks good :-)
so guess I'm missing something
any advice/direction/idea will be highly appreciated.
Thanks
Ronen

How can I configure execution start between dependent jobs?

My Jenkins server is set up with two jobs A and B say.
Job A is triggered from changes in subversion, runs unit tests and if successful, creates a WAR and deploys it to another environment.
If Job A succeeds, then Job B triggers. This job runs tests against the deployed WAR.
The problem is that the deployment process takes a while and the WAR is not ready in time for when Job B starts and tries to use it.
I'm looking for ideas on how to delay Job B until the WAR is up and running.
Is there a way, once Job B is triggered to wait for x seconds? I really don't want to put it into the tests in Job B if I can avoid it.
Thanks
There is definitely a way for a job to wait - just put sleep into the first shell build step. Alternatively, you can set 'Quiet period' - it's in Advanced Project Options when you create a build.
That, however, is a band-aid solution to be employed only if other approaches fail. You may try the following: if there is a way to make the deployment process (that job A triggers) right before it finishes to touch a file that Jenkins has access to, then you can use FSTrigger Plugin. See use case 3 there.
The most reliable way to make this work would be to make job A not complete until the deployment is successful, e.g. by testing for a valid response from the URL of the deployed web app. This blog post describes one way to do that.

Update Quartz.NET Job DLL without Service Restart

I just started with Quartz.net and I have it running as a service. I created a Job and moved the resulting .dll to the Quartz folder and added a new entry to the jobs.xml file to kick it off every 3 seconds.
I updated the job .dll but it is in use by Quartz (or is locked).
Is it possible to update the .dll without restarting the Quartz service? If not what would happen to a long running job if I did stop/start the Quartz service?
You cannot update the job dll without restarting the service. Once the server has started it loads the the job dll and the loaded types stay in memory. This is how .NET runtime works. To achieve something like dynamic reloading you would need to use programmatically created app domains etc.
If you stop the scheduler you can pass a bool parameter whether to wait for jobs to complete first. Then you would be safe with jobs completing and no new ones would spawn meanwhile the scheduler is shutting down.

Resources