1

I'd like to automate an Approve/Publish in Crafter 2.5.2. Basically, I've got some approved static content that gets dropped into the repository by a separate service and I'd like to push that out to my publishing endpoints for a particular site.

I don't see any way through simple configuration to do this, so I assumed that I should create a job and configure it in my site's /config/site.xml. Looking around for an example, I see content-monitoring.groovy in default-site, so I copied and updated the code. However, when it runs, I get a groovy compile time error about not being able to import the CronJobContext.

I assumed that I need to get a ticket and set the CronJobContext in the same way that content-monitoring.groovy does it which is why I have that import. Any suggestions what I should do to fix this or a better way to automate my publish would be awesome.

Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: mysite:/scripts/jobs/jobBulkPublish.groovy: 2: unable to resolve class org.craftercms.studio.api.v1.job.CronJobContext @ line 2, column 1. import org.craftercms.studio.api.v1.job.CronJobContext;

My code is

import org.apache.commons.lang.StringUtils;
import org.craftercms.studio.api.v1.job.CronJobContext;

def context = applicationContext
def sercurityService = context.get("cstudioSecurityService")
def deploy = context.get("cstudioDeploymentService")
def job = context.get("cstudioDeployContentToEnvironmentJobs")

def user = job.userName
def pw = job.password

def ticket = sercurityService.authenticate(user, pw)
if (StringUtils.isNotEmpty(ticket)) {
    CronJobContext cronJobContext = new CronJobContext(ticket)
    CronJobContext.setCurrent(cronJobContext)

    // publish for site = mysite environment= Production path = /static-assets/tie
    logger.info("publishing mysite /static-assets/tie")
    deploy.bulkGoLive("mysite","Production","/static-assets/tie")

    CronJobContext.clear()
}
else {
    logger.error("Not able to authenticate user for cron job.")
}

EDIT Now that I think of this more, I wonder if the issue is that this is running in my deployed site context and that's why the import fails. I want this to run from Crafter Studio and not in my site's preview/deployed engine as it's purpose is to publish. If that's true, how would I create a job that is supposed to run in the craftercms site? I was able to drop my groovy script into my exploded war at webapps/studio/default-site/scripts/jobs/every-5-minutes and restart and it got loaded and worked. However, I would presume that overwriting the studio WAR is a bad idea. Is there some clean way to add a script and configure a job to run in the craftercms/default-site context such as updating a context file in tomcat/share/classes/studio/... and adding files out there?

Paras
  • 804
  • 1
  • 10
  • 25
Jeff R.
  • 188
  • 7

1 Answers1

0

Since this is a Studio job I would place the job in the Studio war. I do not know if there is an extension point for this.

gbags
  • 193
  • 5