Possible to run (trigger) user job via api?

Post Reply
sfatula
Senior
Posts: 163
Joined: Sun Aug 09, 2015 3:51 am
Location: Calera, OK
United States of America

Possible to run (trigger) user job via api?

Post by sfatula »

This would be so powerful if this could be done! It would allow so many things to be done in an automated manner. In this case, my use is to remotely trigger a transcode for a specific video, which it then uploads to Google drive in the user job so I can more easily download it the next day. But I can think of at least a dozen uses.
User avatar
bill6502
Developer
Posts: 2307
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Possible to run (trigger) user job via api?

Post by bill6502 »

Hi,

A couple of questions first:

Just to be clear, from the command line does this do what
you want, only via a new endpoint in the Services API?

mythutil --queuejob userjob4 --chanid ... --starttime ...

Ref: mythutil --help queuejob

I'd be interested in understanding the dozen uses, remembering that there
are four User Jobs.

Do you build from source?

The understanding would be if the backend has a global address,
that anyone could cause a User Job to run.
sfatula
Senior
Posts: 163
Joined: Sun Aug 09, 2015 3:51 am
Location: Calera, OK
United States of America

Re: Possible to run (trigger) user job via api?

Post by sfatula »

I believe mythutil —queuejob would do what I want. As long as it functions identically to user jobs run via mythfrontend and passes all variables.

Add the word potential before uses, i.e. a dozen potential uses. Really, way more than that as this opens up lots of automation possibilities. I don’t lierally mean I personally have a dozen uses I want to immediately use. 😀. I see this as having huge potential use. Other examples, virtually any script in the wiki dealing with a recording could be triggered via a frontend app or an ip remote, etc. so, another use for me, archiving. Sometimes we like something so much, after watching it, we want to retain in Plex. Well, if I could trigger a user job from a frontend (non myth), then it could archive it without logging in, command line for the wife, etc. This seems like a very powerful technique for people.

Regarding global address, of course not! Would be a tunnel.

I have built from source, don’t really have any great desire to unless there’s some good reason, why do you ask? I am sure I could code it and test after I heal from surgery, maybe in June or so.

Let me know if you have further questions.
User avatar
bill6502
Developer
Posts: 2307
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Possible to run (trigger) user job via api?

Post by bill6502 »

I've only tested %JOBID% and %TITLE% and they work.

Do you have any specific %% type variables that you use?

I can pass additional arguments to the jobqueue. This is working
on my test box:

Code: Select all

curl --data UserJob=1 --data Chanid=1051 --data StartTime=2018-01-28T15:00:00 --data Args='a1 b2 c3' ofc0:6544/Dvr/AddJobQueueEntry
Not sure everyone that uses global addresses knows about
tunneling (they should.)

Was just curious if you would have been able to be a tester,
no problem.
sfatula
Senior
Posts: 163
Joined: Sun Aug 09, 2015 3:51 am
Location: Calera, OK
United States of America

Re: Possible to run (trigger) user job via api?

Post by sfatula »

Ah, ok, yes, I can be a tester. I would test on OSX most likely as I have a build environment set up there and a lot of data.

Regarding user jobs and variables, fully aware that user jobs run on the backend. Definitely %TITLE% and %SUBTITLE% are useful, scanning the wiki, %SEASON%, %RECID%, %ORIGINALAIRDATE%, %FILE%, %EPISODE%, %CHANID% seem like they would be useful. These are stored in the DB, so, when available could be populated. Of course, the user job could also acquire these, just seems like the variables should be sent ideally, whatever is the stored value.

Looks like you already have an endpoint coded since you showed your cURL command, or was it already there?

This technique could even work around other missing API functions, I have a separate request out there to allow preserve and do not autoexpire for a richer frontend from non myth "frontends". Well, if the user job call was available, one of them could simply be to set those. Of course, that puts meup to 3 of the 4 I would use, and am quite confident I would have more. If you could accept name value pairs with arbitrary names and pass them on to the userjob, then, a single userjob could function in multiple roles even. But that's a nice to have.

What would be needed is a call to obtain the user job list so something useful can be presented on the frontend as far as what it does. It appears there is a GetSettingList that might do that. Running it it seems to return all settings. Which I suppose could work, or one could do 4 GetSetting calls to get each Userjob name.

Just an FYI, the past few years, I have been a system architect for a large internet company. That ended at year end 2017, I retired from work. Though I owe one last conversion management task. Just not sure yet after rotator cuff surgery when I will be up to it! And I head to Spain in mid May, which is a scary thought right now.

I see the potential for very rich frontends that are not myth coded. Thus far, have used Kodi plugin, Plex plugin (both need work which I may do), MrMC and the Apple TV app "MythTV" from SwiftBit who I have talked to in the hope I can get some more functionality added. But it needs some API calls like this one, so, long road. Then there is the IOS app that I have not tried yet. To me, supporting those types of clients is very important and could get mythtv out there even more. Those are just examples, I am sure others exist on other platforms.

Thank you very much for your interest.
User avatar
bill6502
Developer
Posts: 2307
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Possible to run (trigger) user job via api?

Post by bill6502 »

The endpoint is complete and tested on my box only. However, there are additional
security concerns from other developers that are being discussed now - so release
of this is on hold.

Interesting that during testing I found parameters missing from the Wiki (which have
been added.)

Not all parameters are available to all User Jobs/Events as you read in the Wiki. In this case
%RECID% isn't replaced in User Jobs.
sfatula
Senior
Posts: 163
Joined: Sun Aug 09, 2015 3:51 am
Location: Calera, OK
United States of America

Re: Possible to run (trigger) user job via api?

Post by sfatula »

Thanks for the update!

I am sure you guys know this. It's available today via mythweb, which a frontend could send http to and execute in that manner. It's not an API, but it is already possible.
User avatar
bill6502
Developer
Posts: 2307
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Possible to run (trigger) user job via api?

Post by bill6502 »

Dvr/ManageJobQueue was added to v30-Pre on May 14th, 2018.
https://github.com/MythTV/mythtv/commit ... deaa0fe8f2
sfatula
Senior
Posts: 163
Joined: Sun Aug 09, 2015 3:51 am
Location: Calera, OK
United States of America

Re: Possible to run (trigger) user job via api?

Post by sfatula »

Thank you very much for this and for updating this post! Once I get back from Spain and the Canary Islands (leaving Wednesday), I'll have to update and try it out. This is just awesome.
User avatar
bill6502
Developer
Posts: 2307
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Possible to run (trigger) user job via api?

Post by bill6502 »

git log --since=5/11/2018 --author=Bill is the only documentation right now.
Wiki will follow.

Note that Myth/ManageDigestUser and Myth/ManageUrlProtection should be
used (if an application uses any POST endpoints, like this one.)
sfatula
Senior
Posts: 163
Joined: Sun Aug 09, 2015 3:51 am
Location: Calera, OK
United States of America

Re: Possible to run (trigger) user job via api?

Post by sfatula »

Looked through the commit, all makes sense. Thanks again.
Post Reply