<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Where should I put my script so it can run at night? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1048223#M60823</link>
    <description>&lt;P&gt;The geoprocessing script I need to add to the database script I posted just appends fields of one attribute table to another layer's attribute table, but my supervisor wants it to run at night at a given interval of time (probably once a week).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I don't have any experience on arcpy database maintenance functions and feel timid to write my own database maintenance scripts because of my lack of knowledge in that area. Could you link some beginner friendly resources on how I could learn?&lt;/P&gt;&lt;P&gt;Also, for a quick solution, do you think I can take on my geoprocessing script (basically just table to table, and cursor functions) to the database script I was given, then set a schedule using task scheduler? If so, where should I put the geoprocessing script within the db script?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
    <pubDate>Fri, 16 Apr 2021 17:27:50 GMT</pubDate>
    <dc:creator>GeoDev</dc:creator>
    <dc:date>2021-04-16T17:27:50Z</dc:date>
    <item>
      <title>Where should I put my script so it can run at night?</title>
      <link>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1047588#M60802</link>
      <description>&lt;P&gt;I'm creating a geoprocessing script and was told I should make it run at night when everyone is clocked out by communicating with the database. I haven't done that before so I asked for documentation for help. My supervisor gave me the below script that would allow me to do this; however, I'm confused as to where I am supposed to put my geoprocessing script within this database connection script. Here is the script that is supposed to communicate with the database and allow my script to be run at night:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;# import packages&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;os&lt;SPAN&gt;, &lt;/SPAN&gt;arcpy&lt;SPAN&gt;, &lt;/SPAN&gt;time&lt;SPAN&gt;, &lt;/SPAN&gt;smtplib&lt;BR /&gt;&lt;SPAN&gt;# setup workspace and SDE databases in folder&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;for &lt;/SPAN&gt;dirpath&lt;SPAN&gt;, &lt;/SPAN&gt;dirnames&lt;SPAN&gt;, &lt;/SPAN&gt;filenames &lt;SPAN&gt;in &lt;/SPAN&gt;os.walk(&lt;SPAN&gt;r'//10.0.8.36/GIS/Software/Connection_dir/Test/'&lt;/SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;    &lt;SPAN&gt;for &lt;/SPAN&gt;file &lt;SPAN&gt;in &lt;/SPAN&gt;dirpath:&lt;BR /&gt;        &lt;SPAN&gt;print&lt;/SPAN&gt;(filenames)&lt;BR /&gt;        string = &lt;SPAN&gt;r'//10.0.8.36/GIS/Software/Connection_dir/Test/'&lt;BR /&gt;&lt;/SPAN&gt;        new_list = [string + x &lt;SPAN&gt;for &lt;/SPAN&gt;x &lt;SPAN&gt;in &lt;/SPAN&gt;filenames]&lt;BR /&gt;        &lt;SPAN&gt;print&lt;/SPAN&gt;(new_list)&lt;BR /&gt;        &lt;SPAN&gt;for &lt;/SPAN&gt;database &lt;SPAN&gt;in &lt;/SPAN&gt;new_list:&lt;BR /&gt;            &lt;SPAN&gt;# Email users in database(s)&lt;BR /&gt;&lt;/SPAN&gt;            userList = arcpy.ListUsers(database)&lt;BR /&gt;            &lt;SPAN&gt;print&lt;/SPAN&gt;(userList)&lt;BR /&gt;            &lt;SPAN&gt;# Block new connections to the database.&lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;'The database is no longer accepting connections.format{}'&lt;/SPAN&gt;.format(database))&lt;BR /&gt;            arcpy.AcceptConnections(database&lt;SPAN&gt;, False&lt;/SPAN&gt;)&lt;BR /&gt;            &lt;SPAN&gt;# Disconnect all users from the database.&lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"Disconnecting all users"&lt;/SPAN&gt;)&lt;BR /&gt;            arcpy.DisconnectUser(database&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"ALL"&lt;/SPAN&gt;)&lt;BR /&gt;            &lt;SPAN&gt;# Run the compress tool.&lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"Running compress"&lt;/SPAN&gt;)&lt;BR /&gt;            arcpy.Compress_management(database)&lt;BR /&gt;            &lt;SPAN&gt;# Allow the database to begin accepting connections again&lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"Allow users to connect to the database again"&lt;/SPAN&gt;)&lt;BR /&gt;            arcpy.AcceptConnections(database&lt;SPAN&gt;, True&lt;/SPAN&gt;)&lt;BR /&gt;            &lt;SPAN&gt;# Rebuild indexes in database(s)&lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"Rebuilding indexes on the system tables"&lt;/SPAN&gt;)&lt;BR /&gt;            arcpy.RebuildIndexes_management(database&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"SYSTEM"&lt;/SPAN&gt;)&lt;BR /&gt;            &lt;SPAN&gt;# Updating statistics in database(s)&lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;'Updating statistics on the system tables.format{}'&lt;/SPAN&gt;.format(database))&lt;BR /&gt;            arcpy.AnalyzeDatasets_management(database&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"SYSTEM"&lt;/SPAN&gt;)&lt;BR /&gt;            &lt;SPAN&gt;print &lt;/SPAN&gt;(&lt;SPAN&gt;"Finished"&lt;/SPAN&gt;)&lt;BR /&gt;        &lt;SPAN&gt;break&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    break&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm assuming my geoprocessing script would go after all of the code within the third for loop.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 15:15:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1047588#M60802</guid>
      <dc:creator>GeoDev</dc:creator>
      <dc:date>2021-04-15T15:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Where should I put my script so it can run at night?</title>
      <link>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1047614#M60803</link>
      <description>&lt;P&gt;&lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-pro/analytics/schedule-a-python-script-or-model-to-run-at-a-prescribed-time-2019-update/" target="_blank"&gt;Schedule a Python script or model to run at a prescribed time: 2019 update (esri.com)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 15:35:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1047614#M60803</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-04-15T15:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: Where should I put my script so it can run at night?</title>
      <link>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1047652#M60805</link>
      <description>&lt;P&gt;It would, as long as it is indented so as not to be included in any of those for loops.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 16:17:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1047652#M60805</guid>
      <dc:creator>Kara_Shindle</dc:creator>
      <dc:date>2021-04-15T16:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: Where should I put my script so it can run at night?</title>
      <link>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1047685#M60807</link>
      <description>Thanks for the reply. So are you saying the geoprocessing script should go&lt;BR /&gt;after all the above code I posted? if so, wouldn't it not have any&lt;BR /&gt;indentation because its going after all the for loop code blocks?&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Apr 2021 17:02:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1047685#M60807</guid>
      <dc:creator>GeoDev</dc:creator>
      <dc:date>2021-04-15T17:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Where should I put my script so it can run at night?</title>
      <link>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1047696#M60808</link>
      <description>&lt;P&gt;It depends what your geoprocessing script does. Is it part of database maintenance? That script code you posted is performing database maintenance operations that should all happen together without interference of anything else. However, the logic of that script is strange because the compress operation is in a loop but the unconditional break statement will exit the loop after the first iteration.&lt;/P&gt;&lt;P&gt;A better way to do it is &lt;A href="https://esriaustraliatechblog.wordpress.com/2020/12/22/basic-enterprise-geodatabase-maintenance/" target="_self"&gt;like this&lt;/A&gt; where it connects as SDE to perform compress, then does analyze and indexes as owner of the objects (different database connections).&lt;/P&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/en/arcmap/latest/manage-data/geodatabases/using-python-scripting-to-batch-reconcile-and-post-versions.htm" target="_blank"&gt;Use Python scripting to batch reconcile and post versions—ArcMap | Documentation (arcgis.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Additionally, I found that I needed to use &lt;A href="https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-functions/setloghistory.htm" target="_self"&gt;arcpy.SetLogHistory(False)&lt;/A&gt; so as not to fill up the geodatabase metadata with this nightly task, which seemed to keep slowing down the performance of the script each time.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 17:23:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1047696#M60808</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-04-15T17:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Where should I put my script so it can run at night?</title>
      <link>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1048223#M60823</link>
      <description>&lt;P&gt;The geoprocessing script I need to add to the database script I posted just appends fields of one attribute table to another layer's attribute table, but my supervisor wants it to run at night at a given interval of time (probably once a week).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I don't have any experience on arcpy database maintenance functions and feel timid to write my own database maintenance scripts because of my lack of knowledge in that area. Could you link some beginner friendly resources on how I could learn?&lt;/P&gt;&lt;P&gt;Also, for a quick solution, do you think I can take on my geoprocessing script (basically just table to table, and cursor functions) to the database script I was given, then set a schedule using task scheduler? If so, where should I put the geoprocessing script within the db script?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 17:27:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1048223#M60823</guid>
      <dc:creator>GeoDev</dc:creator>
      <dc:date>2021-04-16T17:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Where should I put my script so it can run at night?</title>
      <link>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1048228#M60824</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/474149"&gt;@GeoDev&lt;/a&gt;&amp;nbsp;I would recommend you do not attempt to integrate your new script into this existing script for geodatabase maintenance. These should be two separate scripts run at two separate times; preferably staggered enough so one has enough time to complete before the other starts.&lt;/P&gt;&lt;P&gt;This is accomplished by saving your new script as a .py file and then scheduling it to run on a destkop or server machine that will be powered reliably to run this task at the scheduled time.&lt;BR /&gt;&lt;A href="https://desktop.arcgis.com/en/arcmap/latest/analyze/executing-tools/scheduling-a-python-script-to-run-at-prescribed-times.htm" target="_blank"&gt;Scheduling a Python script to run at prescribed times—ArcMap | Documentation (arcgis.com)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 17:42:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1048228#M60824</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-04-16T17:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: Where should I put my script so it can run at night?</title>
      <link>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1048270#M60825</link>
      <description>&lt;P&gt;Ok thank you for the help. I'm very glad you told me that before I combined them. It makes sense now why they would be separate. I will do my research with the links you provided so I can better understand databases from a gis dev perspective&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 18:51:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-should-i-put-my-script-so-it-can-run-at/m-p/1048270#M60825</guid>
      <dc:creator>GeoDev</dc:creator>
      <dc:date>2021-04-16T18:51:23Z</dc:date>
    </item>
  </channel>
</rss>

