Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Set up a scheduled task using the deployer #51

Closed
dmcassel opened this issue Oct 22, 2012 · 2 comments
Closed

Set up a scheduled task using the deployer #51

dmcassel opened this issue Oct 22, 2012 · 2 comments
Assignees

Comments

@dmcassel
Copy link
Collaborator

Modify the deployer so that bootstrap will set up a scheduled task.

Note: I'm not sure whether it will work to have this as part of bootstrap, since the source code might not be deployed yet. If that doesn't work, then it might need to be a different command (ml {env} deploy tasks), but hopefully it can be part of bootstrap.

@ghost ghost assigned ameydhavle Oct 22, 2012
@dmcassel
Copy link
Collaborator Author

Thinking about this more, I think it makes sense to have an "ml {env} deploy tasks" command over doing this as part of bootstrapping.

@dmcassel
Copy link
Collaborator Author

Until I get around to adding this feature, here's an example of doing it using deploy/app_specific.rb:

class ServerConfig

  def create_scheduled_dictionary()
    r = execute_query %Q{
      xquery version "1.0-ml";
      import module namespace admin = "http://marklogic.com/xdmp/admin" 
          at "/MarkLogic/admin.xqy";

      let $config := admin:get-configuration()
      (:
        admin:group-hourly-scheduled-task(
          $task-path as xs:string,
          $task-root as xs:string,
          $task-period as xs:positiveInteger,
          $task-minute as xs:nonNegativeInteger,
          $task-database as xs:unsignedLong,
          $task-modules as xs:unsignedLong,
          $task-user as xs:unsignedLong,
          $task-host as xs:unsignedLong?,
          [$task-priority as xs:string?]
      :)

      let $task := admin:group-hourly-scheduled-task(
        "/app/lib/scheduled-dictionary.xqy",
        "/",
        2,
        30,
        xdmp:database("ClientOnBoarding-content"),
        xdmp:database("ClientOnBoarding-modules"),
        xdmp:user("admin"), 
        0)

      let $addTask := admin:group-add-scheduled-task($config, 
        admin:group-get-id($config, "Default"), $task)

      return 
        admin:save-configuration($addTask)

      (: Creates an hourly scheduled task and adds it to the "Default" group. :)


      (:  =====  "/lib/scheduled-dictionary.xqy"
        xquery version "1.0-ml";
        (: Create our own dictionary :)
        import module namespace spell = "http://marklogic.com/xdmp/spell" 
          at "/MarkLogic/spell.xqy";

        declare namespace xhtml = "http://www.w3.org/1999/xhtml";
        let $dict :=
          for $word in  cts:tokenize((cts:values(cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityName"]/@content',
            ("collation=http://marklogic.com/collation/")))))
          return 
            if ($word instance of cts:word) then
              $word
            else ()
        return
          spell:insert(
            "/reference/dictionary/entityName.xml",
            spell:make-dictionary($dict)
          )
        ;

        spell:suggest("/reference/dictionary/entityName.xml", "")

      ==== :)
    },
    { :db_name => @properties["ml.content-db"] }
  end

  def delete_scheduled_dictionary()
    r = execute_query %Q{
      xquery version "1.0-ml";
      import module namespace admin = "http://marklogic.com/xdmp/admin" 
        at "/MarkLogic/admin.xqy";
      declare namespace gr  = "http://marklogic.com/xdmp/group";

      let $config := admin:get-configuration()
      let $tasks := admin:group-get-scheduled-tasks($config, admin:group-get-id($config, "Default"))
      let $task := for $t in $tasks return $t[//gr:task-path="/app/lib/scheduled-dictionary.xqy"]

      let $delTask := admin:group-delete-scheduled-task($config, 
        admin:group-get-id($config, "Default"), $task)

      return  
        admin:save-configuration($delTask)

      (: Deletes a task. :)
    },
    { :db_name => @properties["ml.content-db"] }
  end

end

@ghost ghost assigned paxtonhare Nov 22, 2013
paxtonhare added a commit that referenced this issue Dec 9, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants