Scheduled tasks broken in web admin, can't delete with cfconfig

Good afternoon. I am attempting to set up scheduled tasks using cfconfig, and immediately ran into problems and could use some advice.

I set up the task with this:

cfconfig task save task="Test Page" url=https://www.mydomain.com/server_up.cfm?scheduledtask startDate=1/1/2018 startTime="12:00 AM" 

This caused the Web Admin page for “Scheduled Tasks” to get an error:

Lucee 5.4.4.38 Error (java.lang.NullPointerException)
Message	java.lang.NullPointerException
Stacktrace	The Error Occurred in
/admin/services.schedule.list.cfm: line 145
called from /admin/services.schedule.cfm: line 76
called from /admin/web.cfm: line 570

The task is listed here:

CommandBox:default> cfconfig task list
Task: Test Page
  URL: https://www.mydomain.com/server_up.cfm?scheduledtask
  Status: Running

I tried deleting the task with

CommandBox:default> cfconfig task delete
Enter task (name of the task) :Test Page
Scheduled task [Test Page] deleted.

And got a message that it was deleted. I restarted the server, ran cfconfig task list again, and it shows the task still there, “running” just as before. I still cannot access the Scheduled Tasks on the web admin page.

I exported my cfconfig settings this way:

CommandBox:default> cfconfig export /web/default/wwwroot/.cfconfig.json
Config transferred to /web/default/wwwroot/.cfconfig.json!

I searched through that .cfconfig.json document and found no references to any scheduled tasks.

What might I be missing here?

Scheduled tasks are ignored by the server context. You need to be running those commands against the web context.

cfconfig task list fromFormat=luceeWeb

I’m not sure about the NPE without seeing the java stack trace.

That doesn’t seem to be helping?

CommandBox:default> cfconfig task list
Task: Test Page
  URL: https://www.mydomain.com/server_up.cfm?scheduledtask
  Status: Running

CommandBox:default> cfconfig task list fromFormat=luceeWeb
Task: Test Page
  URL: https://www.mydomain.com/server_up.cfm?scheduledtask
  Status: Running

CommandBox:default> cfconfig task delete fromFormat=luceeWeb
Enter task (name of the task) :Test Page
Scheduled task [Test Page] deleted.
CommandBox:default> cfconfig task list fromFormat=luceeWeb
Task: Test Page
  URL: https://www.mydomain.com/server_up.cfm?scheduledtask
  Status: Running

CommandBox:default> server restart
Trying to stop server...
> server stop 'wwwroot'
Stopping wwwroot...
Stopped


Trying to start server...
> server start name='wwwroot' openBrowser=false debug=false --!saveSettings
 √ | Starting Server
   | √ | Setting Server Profile to [production]
   | √ | Loading CFConfig into server
 
CommandBox:default> cfconfig task list fromFormat=luceeWeb
Task: Test Page
  URL: https://www.mydomain.com/server_up.cfm?scheduledtask
  Status: Running

I did a grep to see instances where this task was in files on the computer:

sudo grep -r 'server_up.cfm' /web/default/wwwroot /home/ubuntu

I received this, in return (among many other things, of course):

/home/ubuntu/.CommandBox/server/36005F94CA4755647CD622ED9DF03372-wwwroot/lucee-5.4.4.38/WEB-INF/lucee-web/scheduler/scheduler.xml:<task name="Test Page" paused="false" startDate="{d '2018-01-01'}" startTime="{t '00:00:00'}" url="https://www.mydomain.com/server_up.cfm?scheduledtask"/></schedule>

I’m not sure why that’s showing up there? Recall that I exported my configuration to a .cfconfig.json file, like this:

CommandBox:default> cfconfig export /web/default/wwwroot/.cfconfig.json
Config transferred to /web/default/wwwroot/.cfconfig.json!
CommandBox:default> 

And nothing related to the scheduled task is showing up in that .cfconfig.json file.

One additional note: could part of this have something to do with the fact that I am starting CommandBox as a “service” using the information on this page?

When I go in to make cfconfig whatever changes, I just use a new terminal window and make the changes, then restart the server (not the service) with CommandBox:default> server restart.

Also a note: there is only one server located in /home/ubuntu/.CommandBox/server/.

For this command, the proper arg name is toFormat, not fromFormat. Please check the command docs for pointers.

It’s really hard to follow what steps you’ve taken in what order, but I’m pretty sure you’ve got the scheduled task saved under the server (where it’s ignored) and web context. And since you keep leaving off the XXFormat or using the wrong param name, you’re not dealing with the data you think you are.

The XML file you pointed out is where Lucee stores scheduled tasks in its web context.

Why wouldn’t it? That’s literally where Lucee stores it, lol.

You exported your SERVER context config, not your WEB context config. You’ll need two JSON files-- one for the server config and one for the web config. Please check the docs on the conventions CFConfig uses for auto-loading these JSON files:

Correct, because Lucee doesn’t store your tasks in the server context’s XMl file! Scheduled tasks go in the web context folder in a different XML file than the rest of the web context settings.

No

That’s fine, but you do want to have your CommandBox home location pinned to the same folder for all users so your user “sees” the same servers that your service’s user “sees”.

Just because there’s only one server defined in that commandbox home doesn’t mean you don’t’ have more than one commandbox home for different users :slight_smile:

No offense, but where? In another thread you mentioned the criticality of this particular argument (despite it only having five (5) google results) but I only see it substantively mentioned here and, even then, that’s kind of vague given how apparently quite important it is?

First, you saw that the task is saved in the scheduler.xml task right?

So, I take it you already know that it’s not being saved in my server? Or is it? How can it be saved in the server configuration when it’s apparently being saved in scheduler.xml?

As for the sequence, I listed all the steps I took in order in my original post. I left off the XXFormat because your documentation said to do so on this page:

All CFConfig commands when run against a Lucee server will default to the fromFormat or toFormat to luceeServer . These commands are a notable exception-- since scheduled tasks can only be imported into a Lucee web context, all commands in the cfconfig task namespace will default to the luceeWeb for Lucee servers.

So, is the fromFormat & toFormat thing actually required, or is it not? The documentation told me that all cfconfig task commands default to luceeWeb.

Regardless, despite all of this, this scheduled task continues to show up when I run all the variations of this command, and the scheduled tasks page in the administrator is still giving me the error.

CommandBox:default> cfconfig task delete toFormat=luceeWeb
Enter task (name of the task) :Test Page
Scheduled task [Test Page] deleted.
CommandBox:default> cfconfig task delete fromFormat=luceeWeb
Enter task (name of the task) :Test Page
Scheduled task [Test Page] deleted.
CommandBox:default> cfconfig task delete toFormat=luceeServer
Enter task (name of the task) :Test Page
Scheduled task [Test Page] deleted.
CommandBox:default> cfconfig task delete fromFormat=luceeServer
Enter task (name of the task) :Test Page
Scheduled task [Test Page] deleted.
CommandBox:default> cfconfig task list toFormat=luceeWeb
Task: Test Page
  URL: https://www.chrisrodkey.com/server_up.cfm?scheduledtask
  Status: Running

CommandBox:default> cfconfig task list fromFormat=luceeWeb
Task: Test Page
  URL: https://www.chrisrodkey.com/server_up.cfm?scheduledtask
  Status: Running

CommandBox:default> cfconfig task list toFormat=luceeServer
Task: Test Page
  URL: https://www.chrisrodkey.com/server_up.cfm?scheduledtask
  Status: Running

CommandBox:default> cfconfig task list fromFormat=luceeServer
No scheduled tasks defined.
CommandBox:default> cfconfig task list
Task: Test Page
  URL: https://www.chrisrodkey.com/server_up.cfm?scheduledtask
  Status: Running

That’s a sequence of all combinations for to/from & Server/Web. None seem to be dropping the task. And, still, I can’t access the Scheduled Tasks page in the web admin.

Is there information about how this can be accomplished somewhere?

I’m just confused about how this test task just sticks around and won’t get deleted and is screwing up my web administrator.

I will also add that I ran this command:

CommandBox:default> cfconfig export to=/web/default/wwwroot/.cfconfig-web.json fromFormat=luceeWeb
Config transferred to /web/default/wwwroot/.cfconfig-web.json!

I then went into that file, with

sudo nano /web/default/wwwroot/.cfconfig-web.json

I found this text:

"scheduledTasks":{
        "Test Page":{
            "startDate":"01/01/2018",
            "startTime":"12:00:00 AM",
            "status":"Running",
            "task":"Test Page",
            "url":"https://www.mydomain.com/server_up.cfm?scheduledtask"
        }
    }

So I manually deleted that section from the cfconfig-web.json using my text editor, and then did server stop and server start.

When the server restarted, I checked the .cfconfig-web.json file again. The scheduled task information was still not there.

Yet, it still shows up here:

CommandBox:default> cfconfig task list
Task: Test Page
  URL: https://www.chrisrodkey.com/server_up.cfm?scheduledtask
  Status: Running

And, when I go to look at the .cfconfig-web.json file, again, in nano, the scheduled task is back.

So – it’s being populated from somewhere, I don’t know where. Everything I do to try to delete it results in nothing. When I try to restart the server with these .cfconfig-server.json and .cfconfig-web.json documents in the web root, the task still shows up on the server.

So … what’s going on here.

I even tried editing that scheduled task out of the exported .cfconfig-web.json file, and then running cfconfig import from=/web/default/wwwroot/.cfconfig-web.json toFormat=luceeWeb, but the task is still showing up when I run cfconfig task list. And I still can’t access the Web Administrator page for Scheduled Tasks.

So, this scheduled task is saved … somewhere? And CommandBox/CFConfig just keep forcing it into the server, no matter what?

Here:

and here in the command help

cfconfig task list ?

I don’t know what you expect me to do about Google’s search results. Create a blog and blog about this so there’s 6 results. Honestly, if you want to figure this out, I’m here to help. If you just want to complain about how hard it was, I’m not too interested. Thousands of people use CFConfig every day and they somehow figured it out.

It’s not vague-- it covers all there is and it’s just a simple topic. There is an expectation that you have a basic idea of how the CF engines work and store their config.

It would appear not. To be honest, I forgot the task commands defaulted to the web context. That said, it certainly doesn’t hurt to provide it if you’re unsure.

And I’m still waiting for you to provide the full Java stack trace. Don’t bother-- I just took the time to try it locally. Lucee requires an internal, which you didn’t provide and apparently Lucee has poor error messages. I added a bit of additional validation to CFConfig to try and catch this. This version of your command works fine:

cfconfig task save task="Test Page" url=https://www.mydomain.com/server_up.cfm?scheduledtask startDate=1/1/2018 startTime="12:00 AM" interval=daily

Lucee did log a useful error that told you what the issue was in this log file inside its web context:

\WEB-INF\lucee-web\logs\application.log

The Lucee error was

lucee.runtime.schedule.ScheduleException: invalid interval definition “”, valid values are [once, daily, monthly, weekly or number]

Congrats you found a bug. Apparently Lucee tasks weren’t saving when there are zero tasks. The logic to write the file was inside of the loop so it only ran if there was at least one task. Support for Lucee scheduled tasks has been in CFConfig a little over a year and I guess no one ever tried to delete all their tasks until now. I have fixed this.

Yes, here: Installation - CommandBox : CLI, Package Manager, REPL & More

This makes no sense unless you’ve configured CFCOnfig to export on server stop or you manually ran the export command again. Just restarting Lucee shouldn’t affect the contents of any JSON files.

Excellent. I am happy to hear that I was able to highlight a bug.

As for the documentation item:

From the documentation (emphasis mine):

Every command with a to and/or from parameter also has a matching toFormat and/or fromFormat parameter. In most cases, you don’t need to provide this.

For such a “simple” topic, it’s been at the root of a lot of my struggles so far, yet the documentation seems to portray this toFormat/fromFormat issue as a negligible one. Just an observation.

In any case, it doesn’t sound like the toFormat/fromFormat item was at the root of this problem, anyway.

One question I do have: when adding a task via cfconfig task save, I am able to see the task appropriately added by checking cfconfig task list, but I don’t see it showing up in the lucee Web Administrator’s Scheduled Tasks page. Any idea why that might be? Am I required to export the settings to the cfconfig-web.json before restarting the server?

That’s because your use case is honestly fringe. Valid, but uncommon. Half (or more) of all CFers use Adobe CF, where there is no distinction between server and web so it doesn’t apply to them. And schedule tasks don’t seem to be that common amongst Lucee users using CFConfig-- who tend to be doing more scalable, automated Docker-type installs. And since CommandBox only has a single web context in most use cases, the purpose of the web context almost entirely goes away with the exception of for scheduled tasks. I’d say most CFConfig users go their entire life not even realizing there are other formats they can specify because prolly 90-95% of CFConfig users never check all the boxes to ever need it. That’s why you don’t see a lot of people talking about it.

That part worked for me in my tests last night. I needed to restart Lucee to pick it up, but then it showed up just fine.

I’ll also note, while there’s nothing at all wrong with using the CLI to create your config, it may help to know the typical workflow followed by most people is to create their config-- at least the first time-- in the web admin interface where it’s more familiar and the CF engine’s validation can help ensure they get it right. Then, they export what they created to the JSON file and go from there.

Maybe. If you don’t have a .cfconfig-web.json at all, then there’s no issue. Using the ClI to directly create settings in the Lucee XMl files just requires a restart of Lucee (or configuring Lucee to watch for changes). However, if you DO have a .cfconfig-web.json file, then that file will get auto-imported every time you start the server and will OVERWRITE your Lucee settings with its contents. So in that case, if you directly add config to Lucee’s XML files, but leave that new config out of the JSON files, then on the next restart, the JSON files will effectively “revert” your config back to their version. This is a common mistake-- you just have to think of it like this-- once you start using the JSON files, they become the “source of truth” regarding what config Lucee will have.