Is it possible to republish GP-service automatically using Python?

4586
7
04-04-2016 01:45 AM
Anne_VendeløkkeOlsen
New Contributor II

Dear All.

At the moment my users place mxds in a specific folder.

1) I publish these mxd's as map services.

2) In addition I have a have a GP-service that creates cad-files based upon the content of the mxd's (the service).

I have several mxd's, meaning several map services.

I only have on GP-model, but this is used for all the different map services.

Everytime the content of the mxd is changed, the map-service is republished.

In addition I then need to republish the GP-services. Otherwise the GP-service reference the wrong map content.

Is it somehow possible using Python to do this republishing of the GP-service automatically? As it is now I have to do it manually. Everytime the mxd is republished, I have to republish the GP-service manually. Sometimes I forget, meaning when my users exports to CAD from the web, they see one content in the map, and another content in the exported CAD.

Best regards Anne.

0 Kudos
7 Replies
BillDaigle
Occasional Contributor III

Hi Anne,

Yes, it is possible to publish a GP service using python.  We use python to publish all of our GP services, but it took quite a while to set it up and configure it for our infrastructure. If you decide to go down that road, let me know.  I might be able to provide you with some samples to get you started.

Since you only have one GP service, it might not be worth the effort to automate publishing.  Your time might be better spent figuring out how to get the GP service to dynamically respond to work with the current content without having to republish each time.  What do you change each time?  Is it a layer naming issue?

Anne_VendeløkkeOlsen
New Contributor II

Hi Bill.

At the moment I have one GP-service but my plan is to increase the number of GP-services ;)

The users mainly change the map content, meaning they add or remove a layer, rename another layer etc. I would really much like to get help with samples. Me writting to this forum is simple a matter of not beleiving that this is not possible. It should be possible somehow ;)

0 Kudos
AndrewKeith3
Occasional Contributor

Yes, it is possible.  The three main tools for publishing a mxd as a service is the arcpy.mapping.CreateMapSDDraft, Stage Service (Server), and the Upload Service Definition (Server) Tool.  You can run these tools in the order mentioned above in a python script to publish the mxd files as a service.  To publish the GP service, use arcpy.CreateGPSDDraft in place of arcpy.mapping.CreateMapSDDraft and the rest is the same as publishing mxd files.

DylanKennard
New Contributor III

Anne,

Did you figure out how to "Republish" the service?  None of these answers specify the Auto-republish you originally asked.

Just wondering if I have to run that all again or if there is a separate "republish" workflow you discovered?  I have to point over 70+ services to new databases

There is lots of help on how to write scripts to auto publish services via python but not overwrite an existing Map Service and keep all the respective settings.  I wrote a python script to auto publish new Services and then use JSON and ArcGIS Admin API to configure those services to my environment.  That build process has limitations for "Republishing".

Cheers,

Dylan Kennard

0 Kudos
KevinHibma
Esri Regular Contributor

Dylan,

At 10.4 we enhanced Server in regards to updating database connections. If you're on 10.4, simply updating your datastore connection will update the reference for any service (feature, gp, etc) that referenced it.

This topic has more info: Register your data with ArcGIS Server using ArcGIS for Desktop—Documentation | ArcGIS for Server  (note that the GP Service has to have been published with 10.4 for this to work)

0 Kudos
Anne_VendeløkkeOlsen
New Contributor II

Hi Dylan.

No I haven't come up with a good solution. I'm stuck. I'm attending this upcoming UC and hopefully I will find a qualified person that can answer my question. I will give you feedback if I find the answer ;)

KevinHibma
Esri Regular Contributor

Come by the Analysis island in the Expo Tues/Wed/Thurs and look for me - we can chat about this.

I'm also presenting a Creating Geoprocesing Services session, but wont be going over exactly what you're asking.

0 Kudos