Cold Fusion Where do place the code for cfschedule? - coldfusion

I want to set up a simple scheduled task in ColdFusion. I will not have access to the Administrator. So I plan to use<cfschedule. The web is teeming with examples of how to write a cfschedule tag. But I cannot find any explanation of where to put the code.
Do I place it on any .cfm page? Must it go in the index.cfm or Application.cfm? Or what?
I also could not find any explanation of how the scheduling code is initiated. Is it sufficient that the cfschedule code should be somewhere in the application? And if not, what should I do to make sure it runs.
These questions feel stupid to me, but I just can't find answers. Can anyone enlighten me?.cfm

Off the top of my head I didn't know, so I googled cfschedule example and looked at this page.
The first example was to create or update a task. It says, tell ColdFusion to run 'importData.cfm' daily at 7AM
<cfschedule
action="update"
task="importMyCSVFileToDB"
operation="HTTPRequest"
startDate="5/12/2016"
startTime="7:00 AM"
url="http://www.example.com/scheduled/importData.cfm"
interval="daily" />
My interpretation of that is that you put a <cfschedule> tag with a action="update" attribute on a page on the relevant server, and run it once. If it was me, I'd make it page with only the <cfschedule> tag followed by the word, done.
To test this theory, write a page that sends you a simple email. Then schedule that page as I just described and see if you get the email at the scheduled time.

Related

content empty when using scrapy

Thanks for everyone in advance.
I encountered a problem when using Scrapy on Python 2.7.
The webpage I tried to crawl is a discussion board for Chinese stock market.
When I tried to get the first number "42177" just under the banner of this page (the number you see on that webpage may not be the number you see in the picture shown here, because it represents the number of times this article has been read and is updated realtime...), I always get an empty content. I am aware that this might be the dynamic content issue, but yet don't have a clue how to crawl it properly.
The code I used is:
item["read"] = info.xpath("div[#id='zwmbti']/div[#id='zwmbtilr']/span[#class='tc1']/text()").extract()
I think the xpath is set correctly and I have checked the return value of this response and it indeed told me that there is nothing under this directory. Results shown here:'read': [u'<div id="zwmbtilr"></div>']
If it has something, there should be something between <div id="zwmbtilr"> and </div>.
Really appreciated if you guys share any thoughts on this!
I just opened your link in Firefox with NoScript enabled. There nothing inside the <div #id='zwmbtilr'></div>. If I enable the javascripts, I can see the content you want. So, as you already new, it is a dynamic content issue.
Your first option is try to identify the request generated by javascript. If you can do that, you can send the same request from scrapy. If you can't do it, the next option is usually to use some package with javascript/browser emulation or someting like that. Something like ScrapyJS or Scrapy + Selenium.

CFCLIENT: Doc examples do not work; Can't get anything to work?

So I realize that the new CF11 mobile features have been received with some very mixed reviews, but I wanted to try them out to see if I could use them for some really simple device detection, however I cannot get anything to actually work.
For example, I am looking at the doc for cfclientsettings, specifically at the first example on the page under the "Device detection" heading. Here's the code for reference (I formatted it a little to ensure it's easy to read here):
<cfClientSettings detectDevice=true />
<cfclient>
<cffunction access="public" name="showCanvasSupport" returntype="void">
<cfset evalStr = "document.getElementById('canvas').innerHTML='" & cfclient.canvas & "'">
</cffunction>
</cfclient>
Canvas support -<b id="canvas"></b><br>
<button onclick="invokeCFClientFunction('showCanvasSupport',null)">Show canvas support</button>
Creating a new .cfm page and adding this code produces the text and button on the page, but clicking the button throws a JS error in Chrome: "Uncaught The function signature is invokeCFClientFunction(functionName [, arg1, arg2, arg3, ...], successCallback, failureCallback). The functionName, successCallback and failureCallback are mandatory. If you don't have a successCallback or failureCallback, null can be passed as the value."
Ok, not great. So I checked some more docs and decided to add another null argument to the invokeCFClientFunction() call to fix the missing callback. This at least corrects the JS error, but now nothing at all happens when clicking the button.
So after some more fussing, I arrived at the following code, which still does not work, but seems closer:
<cfClientSettings detectDevice=true />
<cfclient>
<cffunction access="public" name="showCanvasSupport" returntype="void">
<cfscript>
document.getElementById('canvas').innerHTML=cfclient.canvas;
</cfscript>
</cffunction>
</cfclient>
Canvas support -<b id="canvas"></b><br>
<button onclick="invokeCFClientFunction('showCanvasSupport',null,null)">Show canvas support</button>
So this code, when you click the button, sets the innerHTML of the canvas element to "undefined". Awesome.
Honestly, I've been trying every example I can find for using cfclient and NONE of them work. Is there some secret I'm missing? I have a sneaking suspicion that if I'm not creating a 'Mobile Project' in CFBuilder that this stuff doesn't work? If so that's stupid and they don't state that in the docs really.
What I'm trying to do, in the end, is simply use cfclient for some basic device detection and to grab the width of the browser/device to do some basic media query style detection very much like in the "Using media queries" section of the cfclientsettings doc. I just want to grab the width and then set a session variable based on it.
I am running a fully patched developer version of CF11 on my Win7 machine setup with IIS. Any and all support is welcome.
Cross post on Adobe Forums: https://forums.adobe.com/thread/1929387
After bashing my head on my keyboard for a while more, I've gotten the cfclient scope working.
I finally found this page in the docs: Device Detection
At first glance, this page seems almost identical to the cfclientsettings doc page, even having the same code examples.
However, where the cfclientsettings doc uses the scope like this:
cfclient.canvas
The Device Detection doc page writes it like this:
cfclient.properties.canvas
Boom. That's of course all it took. What a waste of time. All the cfclient scoped variables work just fine if you add ".properties" in there.
I'm still not sure if the cfclientsettings doc is just plain wrong, or if it's referencing it in a different context. I'll definitely add a comment to it on that point.
(Also, the JavaScript still fails for this example on both doc versions, so there's that.)
Hope this helps somebody who wants to do simple ColdFusion client device detection.
Let me preface this answer by stating that I have never used cfclient and I am only relaying the documentation that I found online for it's use. This was too long for a comment.
You stated:
I have a sneaking suspicion that if I'm not creating a 'Mobile Project' in CFBuilder that this stuff doesn't work? If so that's stupid and they don't state that in the docs really.
I think they do state that in the documentation actually. Here is what I found. At the beginning of the Client-side CFML (for mobile development) document it states:
Before you begin – To try out the examples provided in this document, you need to set up the ColdFusion mobile development environment. See Configuring the development environment.
I am not going to repeat all of the information here as it is fairly substantial but the Configuring the development environment page mentions that you must install ColdFusion Server 11, install ColdFusion Builder and then create a 'ColdFusion Mobile Project' within Builder to help you along.
However that page also states that you can convert an existing ColdFusion project automatically by following the steps under Migrating existing projects where you 'Apply CF Mobile Nature' to the project from within ColdFusion Builder. This may be the piece that you are missing.
I think if you read through the documents that I referenced it may get you going. Also here is a link to their Building Mobile Applications documentation which contains an overview of the entire process.

Select all frames at once in Selenium

This could be a stupid questions for some. But its truly important for me.
I know how to switch frames using selenium webdriver.
However, is there a way to download all the page_source of the entire page for all the frames at once.
Instead of switching them again and again?
Could someone please let me know the command if it exists?
If not then please say there is none. And that should answer my question.
Thanks in advance
Webdrivers' getPageSource will return some state in some formatting of the last page the driver was on.
From the (java)docs, but most probably applies to other languages:
getPageSource
java.lang.String getPageSource()
Get the source of the last loaded page. If the page has been modified
after loading (for example, by Javascript) there is no guarantee that
the returned text is that of the modified page. Please consult the
documentation of the particular driver being used to determine whether
the returned text reflects the current state of the page or the text
last sent by the web server. The page source returned is a
representation of the underlying DOM: do not expect it to be formatted
or escaped in the same way as the response sent from the web server.
Think of it as an artist's impression.
Returns:
The source of the current page
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#getPageSource%28%29

cflocation no longer working in CF10

I’ve been battling with a bug with cflocation ever since I upgraded from CF9 to CF10. I’ve worked on it a number of times but always give up but today it’s finally annoyed me enough that it’s time to solve the problem (I hope).
Firstly, apologies as I have tried to write a simple test case to reproduce this problem but so far I’ve been unable to reproduce it outside of original code.
I have a multi-step import process that should run overnight. The process is made up of about 10 files that chain together. When calling the process via a scheduled task a URL parameter (scheduledtask) is also passed. If the parameter does not exist, at the end of each step it stops and waits for the user to click a link to the next step. If the parameter does exist it uses cflocation to move to the next step.
Of all the steps, the 2nd one is the most complex and time consuming (data from multiple web service requests that then need joining, cleaning and inserting into a database). It’s this second step that has a problem after moving to CF10. The page seems to work fine as it’s getting to the very bottom of the page where the cflocation tag is but it never fires cflocation. I’ve added in a cfmail tag to email me as the cflocation is being called, which is always sent, but again cflocation doesn’t fire.
It can’t get much more basic than:
<cfif scheduledtask EQ "true">
<cfmail from="xxxxx” to="xxxx” subject="About to call duplicate" type="text/html">
<p>calling duplicate check - scheduledtask</p>
</cfmail>
<cflocation url="importDupCheck.cfm?scheduledtask=true" addtoken="false">
</cfif>
I know that there is a problem with cfflush and cflocation and I’ve already checked for that.
As a test I tried moving the above logic up the page to just after all the data is retrieved by the webservice but before it’s processed and this time the cflocation worked. I thought maybe it’s a timeout problem where the scheduled task engine has given up waiting even though the page is being allowed to fully load. I tried testing this by having a basic file that had:
<cfset sleep(240000)>
* 4 minutes
before it called cflocation but it worked fine.
The other steps in the process are working as expected with cflocation, just not this one. All this code runs fine under CF9, just failing with CF10.
Does anyone has some pointers on where I should be looking?
Regards
Mark
* Update *
So I’ve now worked out how to easily reproduce this in a few lines of code. Turns out it has nothing to do with scheduled tasks.
index.cfm
<h1>Testing cflocation</h1>
<cfloop index="i" from="1" to="7000" ><!--- For me it stops working once the loop goes beyond 6808 rows --->
row <cfoutput>#i#</cfoutput>: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789<br/>
</cfloop>
<p>Now loading resultpage via cflocation</p>
<cflocation url="resultpage.cfm" addtoken="false">
resultpage.cfm
<h1>Made it!</h1>
<p>Reload the first page</p>
In my testing I found that if I looped 6808 times it works but 6809 times fails. With 7000 records we are only talking about a 36 KB file….why is this failing only in CF10?
One last thing I should note in case it has an impact- everything I do is done via https.
Ok I worked it out
In CF Administrator
Maximum Output Buffer size 1024
After which a flush will occur which will stop cflocation working.
Increase it and it works.
I have no idea why your code as it stands doesn't work, I'm afraid. At a guess, it's down to ColdFusion 10's replacement of the scheduled task engine, and it not liking some vagary of client-side redirects.
However maybe you can bypass the situation anyhow.
ColdFusion 10's scheduler has a concept of chaining tasks, so that when a task finishes, another one is kicked off. You could conceivably revise your scheduler to leverage that instead?
I had a similar issue, but I was using the location() function in a cfscript. But I suspect the same principle applies.
Prior to the location() function, we were calling a function that was not wrapped in <cfsilent> tags. As a result, every line of the function, including loops, was being output as an empty line of HTML. When I viewed the source code, there were over 20,000 lines of empty HTML code. That is probably enough to reach the 1024 kb buffer limit and trigger the flush that aborts the redirect.
By adding <cfsilent> tags to the custom function, I reduced the number of empty lines of HTML to 39, and now the location() function works as expected.
To determine if this is the issue you are having, add abort; (or <cfabort>) just ahead of the location(), then view the source code of the resulting - presumably empty - page.
Have you tried adding CFABORT after CFLOCATION? That's what I always do - as the code after CFLOCATION should not be executed.
If you check the response from the server (using Charles proxy, Fiddler or something similar) you may find something in the HTML/JS that's preventing the redirection.

Dajaxice: Having trouble getting Dajaxice working

I know, I know, the first thing you are thinking is to check all of the instructions online and on dajaxproject.com
Well I have checked and checked and rerun this installation and I cannot figure out what the problem is. I assume it has something to do with the version of Dajaxice I am using and the version the installation instructions are, but those details are usually missing.
At this point in the process, I have everything setup to accomplish a very simple task. Load a webpage from the IP:8000 (ie 1.2.3.4:8000) and have that page load a simple html form button. Once that button is pressed, the page should then send a mesage (using dajaxice) to the server, and once it returns an alert box will pop up, proving that the dajaxice install is working.
So, I have:
Installed Dajaxice (and dajax for that matter), by getting the zip from here: github [dot] com/jorgebastida/django-dajaxice/
Changed everything in a basic Django project to follow the details in this tutorial: http://django-dajaxice.readthedocs.org/en/latest/installation.html
I have setup all of the details of ajax.py, and index.html to work with this example: django-dajaxice [dot] readthedocs [dot] org/en/latest/quickstart.html
PS Sorry for the "[dot]"s, but being a new registered user they limit you to 2 per post, so I tried to give you the best links clickable.
I am stumped. I have been trying many different things, but the documentation available seems so sporadic. It's gotta be something simple I am messing up, but I cannot seem to find it.
Currently, the "Say Hello!" button shows up on the screen, but nothing happens when you press it. Any ideas?
Here is a link to the zip file of the Django project I am working with here: https://docs.google.com/open?id=0B5rzYk6W5HlrYk9veVRfM3JkTGc
The way I have it all organized, DjangoAjax is just the folder containing the Django project. ajax_prac is the project, and practice is an app. Also you'll see a folder called django_media...that's pretty self explanatory, it just holds all the "media" for my Django projects, including jquery.js and jquery.dajax.core.js
If there are some details that I have smudged in the code, contrary to the installation guide, I apologize. I have been working through so many iterations of this, that it is likely I could've forgotten to change something back when making this post.
Can anyone help?
All the documentation weirdness is probably related with the new release I made yesterday (8 hours ago). Probably you was using an old version of dajaxice reading the new documentation.
I've release django-dajaxice (0.5) and django-dajax (0.9.1), both fully compatible with the last version of Django (1.4.1).
django-dajaxice: http://pypi.python.org/pypi/django-dajaxice
django-dajax: http://pypi.python.org/pypi/django-dajax
For this release I've also rewrite both documentations and hosted them on readthedocs. Also, http://dajaxproject.com code is now opensource so everybody can read the code and see how dajaxice works in production.
django-dajaxice: http://django-dajaxice.readthedocs.org/en/latest/
django-dajax: http://django-dajax.readthedocs.org/en/latest/
example project: https://github.com/jorgebastida/dajaxproject.com
Could you please upgrade to django-dajaxice (0.5) follow the new installation steps (quite similar http://django-dajaxice.readthedocs.org/en/latest/installation.html) and post here any traceback/issue you could have?
Thanks
In your example code ( DjangoAjax / ajax_prac / templatedirectory / practice / index.html):
<input type="button" value="Send message to server!"
onclick="Dajaxice.ajax.sayhello(my_js_callback);">
Should be:
<input type="button" value="Send message to server!"
onclick="Dajaxice.ajax_prac.practice.views.sayhello(my_js_callback);">
I.e. It must reference a Python module that contains your registered Dajaxice view. And according to your sample code, ajax_prac.practice.views exists while ajax.sayhello does not.
Also the Python module must be prefaced with "Dajaxice" (which is probably a significant source of confusion).