jobbrIO / jobbr-server

Jobbr is a non-invasive .NET JobServer
https://jobbr.readthedocs.io
GNU General Public License v3.0
50 stars 5 forks source link

Configure .WithTrigger as instant trigger #74

Closed doorman02 closed 2 years ago

doorman02 commented 2 years ago

I am triggering a job via the api and I was wondering if it is possible to specify an instant trigger using the .WithTrigger(); syntax? e.g.

jobbrBuilder.AddJobs(repo =>
{
    // define one job with two triggers
    repo.Define("SampleJob", "Quickstart.SampleJob")
        .WithTrigger(instant trigger syntax) /* run only when */
});
linkdotnet commented 2 years ago

What would be your use case? What would be your expectation? If you would create an InstantTrigger via AddJobs that would mean the job would run immediately once the server starts?

doorman02 commented 2 years ago

@linkdotnet thanks for your quick reply. Basically I want to be able to trigger the job via the API. So I am using the following endpoint: $url = "http://localhost:port/jobs/$jobId/triggers/$triggerId"

However, I assume I will need the Id of the instant trigger to be able to trigger the job using the endpoint? or is there another way to trigger the job via api?

linkdotnet commented 2 years ago

There is a package called jobbr-webapi: https://github.com/jobbrIO/jobbr-webapi

If you want to map the request on your own you can have a look into the code of tje webapi: https://github.com/jobbrIO/jobbr-webapi/blob/cf8a2491a3f055e97ed543befdf15e574582e42a/source/Jobbr.Server.WebAPI/Controller/TriggerController.cs#L110

doorman02 commented 2 years ago

Thanks, for now I think I will just create the instant trigger from the dashboard and afterwards trigger it from the endpoint.

linkdotnet commented 2 years ago

Ok. @doorman02 but you could do this via Web API. The url in the second link would be your target. Alternatively install the Jobbr.WebAPI nuget package and use the strongly typed library. Are you fine when I close the issue?

linkdotnet commented 2 years ago

To recap: Only the Job has to be defined. Once this is done you can create an instant trigger via Dashboard / URL (HTTP POST( or the Jobbr WebAPI (which is a wrapper for all API Requests). This will create a JobRun which actually does your stuff

doorman02 commented 2 years ago

@linkdotnet thanks for the clarification. Since I may be posting a new instant job multiple times is it possible to delete older instant triggers via the api? or even better is there a way to re-trigger an already defined instant trigger?

linkdotnet commented 2 years ago

Hey @doorman02 could you descirbe what you mean with "is it possible to delete older instant triggers via the api" Once an Instant Trigger is older than DateTime.Now it will not be picked up by the scheduler.

There is no endpoint for retriggering and old trigger, so I would advice you the have some logic in your program which saves the HTTP POST Request to the jobbr-server which creates the trigger in the first place. Basically you can just send the same request again.

doorman02 commented 2 years ago

@linkdotnet thanks this works. If I understand it correctly each time I call post a new instant trigger is created in the trigger list. My only concern was that the list would grow very large in the long run but it's maybe not that critical.

linkdotnet commented 2 years ago

Yes. The list will grow over time that is correct. If this every becomes a problem you can just create a recurring job which delete "old" JobRuns / Triggers on the database level. If you have any other questions let me know @doorman02 .

Are you fine with closing the issue?

doorman02 commented 2 years ago

yes, thanks