Rails 5.2 & Ahoy 2 - "undefined method `visitor_token' for nil:NilClass" - mongoid

I'm running Rails 5.2 and the awesome Ahoy gem, with mongoid as the ORM.
In the homepage controller, I'm calling current_visit.visitor_token, which is generating the following error:
MONGODB | ds111336.mlab.com:11336 | heroku_1f375nv7.find | STARTED |
{"find"=>"ahoy_visits", "filter"=>{"visit_token"=>"4f86bf0d-f694-4a46-
b1fb-4ff48722e5c5"}, "sort"=>{"_id"=>1}, "limit"=>1,
"singleBatch"=>true}
MONGODB | ds111336.mlab.com:11336 | heroku_1f375nv7.find | SUCCEEDED |
0.048124999999999994s
Completed 500 Internal Server Error in 297ms (ActiveRecord: 202.8ms)
NoMethodError (undefined method `visitor_token' for nil:NilClass):
The ahoy_visit value stored in the cookie is b5b4fd64-ec42-4e6d-9740-e394ed4a24da, yet Ahoy seems to be searching for a different visit_token (as above).
initializers/ahoy.rb:
class Ahoy::Store < Ahoy::DatabaseStore
end
# set to true for JavaScript tracking
Ahoy.api = true
Ahoy.server_side_visits = true
If I clear the website data from my browser (or open a new session in an incognito window), the error does not occcur until I wait another day (I'm guessing until the sessions expires).
I've searched all through the code and can not figure out why Ahoy is not creating a new visit record in the DB.
Thanks for any help in advance!

With Ahoy 2.0 you visit model need to be scoped as such
class Ahoy::Visit < ApplicationRecord
# code here
end
- another walkaround is re-install Ahoy and it will place Visit and Event in the correct location.

Related

GATSBY | MATERIAL UI | ERROR ON BUILD | WebpackError: ReferenceError: document is not defined (from plugin: gatsby-plugin-material-ui)

Creating a friend a site using Gatsby 4.0 and thought I would use the material UI template. looks nice and works in develop.
I go to build and I get the following errors, I presume its the material UI plugin with using the withStyles function but I am a noob and I can't find a solution online (If I find, at least it's recorded):
failed Building static HTML for pages - 2.794s
ERROR #95312
"document" is not available during server side rendering.
See our docs page for more info on this error: https://gatsby.dev/debug-html
72 | var _options = options,
73 | _options$window = _options.window,
74 | window = _options$window === void 0 ? document.defaultView : _options$window;
| ^
75 | var globalHistory = window.history;
76 |
77 | function getIndexAndLocation() {
WebpackError: ReferenceError: document is not defined (from plugin: gatsby-plugin-material-ui)
index.js:74
[leighton]/[history]/index.js:74:1
index.js:82
[leighton]/[react-router-dom]/index.js:82:26
index.js:22
[leighton]/[decode-uri-component]/index.js:22:1
index.js:25
[leighton]/[decode-uri-component]/index.js:25:1
index.js:31
[leighton]/[decode-uri-component]/index.js:31:1
index.js:30
[leighton]/[decode-uri-component]/index.js:30:4
index.js:41
[leighton]/[decode-uri-component]/index.js:41:1
gatsby-ssr.js:33
[leighton]/[gatsby-plugin-material-ui]/gatsby-ssr.js:33:47
api-runner-ssr.js:92
leighton/.cache/api-runner-ssr.js:92:28
static-entry.js:266
leighton/.cache/static-entry.js:266:11
dev-404-page.js:15
leighton/.cache/dev-404-page.js:15:11
WebpackError: ReferenceError: document is not defined (from plugin:
gatsby-plugin-material-ui)
The source of the issue is in the SSR (Server-Side Rendering). Summarizing a lot, when your un gatsby develop the code is interpreted by the browser, where you can play with window, document, and other global objects. However, gatsby build runs in the Node server where there's no window or document because has not even been created yet. That's why works in development and not in build mode.
This issue can by easily bypassed by adding the following condition before the usage of those global objects:
if (typeof window !== 'undefined'){
// code here
}
Or wrapping the code in a useEffect with empty deps ([]). This will ensure that the DOM tree is loaded thus there's a window (or document) available.
In your case, without any code samples or implementation of gatsby-plugin-material-ui it's impossible to know where's the code source of the issue.

camel-elasticsearch5 component is not working

My project consume messaged from activemq and store in to elasticsearch 2.4 database with technology karaf 4.0.8, Apache camel (2.18.1), camel-elasticsearch component.
I am trying to upgrade to elasticsearch 5 database and that required changes in client side. I found that new camel component camel-elasticsearch5 is there for that with apache-camel 2.19.0. I upgrade the camel. after that it looks it is not working as expected.
1. the camel commands like camel:context-list is not working.
2. The route is not working like messaged are not consumed from activemq.
Additionally there is a warning in the log.
2017-07-18 06:57:27,144 | INFO | nt Dispatcher: 1 | ElasticsearchProducer | 21 - org.apache.camel.camel-elasticsearch5 - 2.19.0 | Connecting to the ElasticSearch cluster: elasticsearch
2017-07-18 06:57:27,145 | WARN | -SNAPSHOT/deploy | BlueprintEventDispatcher | 83 - org.apache.aries.blueprint.core - 1.7.1 | Listener caused an exception, will be ignored
java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.transport.client.PreBuiltTransportClient
at java.util.concurrent.FutureTask.report(FutureTask.java:122)[:1.8.0_121]
at java.util.concurrent.FutureTask.get(FutureTask.java:192)[:1.8.0_121]
at java.util.concurrent.AbstractExecutorService.doInvokeAny(AbstractExecutorService.java:193)[:1.8.0_121]
at java.util.concurrent.AbstractExecutorService.invokeAny(AbstractExecutorService.java:225)[:1.8.0_121]
at org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper$4.call(ScheduledExecutorServiceWrapper.java:184)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper$15.call(ScheduledExecutorServiceWrapper.java:452)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.utils.threading.RWLock.runReadOperation(RWLock.java:35)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper.runUnlessShutdown(ScheduledExecutorServiceWrapper.java:447)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper.invokeAny(ScheduledExecutorServiceWrapper.java:178)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.container.BlueprintEventDispatcher.callListener(BlueprintEventDispatcher.java:199)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.container.BlueprintEventDispatcher.callListeners(BlueprintEventDispatcher.java:189)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.container.BlueprintEventDispatcher.blueprintEvent(BlueprintEventDispatcher.java:140)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:424)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:276)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:300)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:269)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:265)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:255)[83:org.apache.aries.blueprint.core:1.7.1]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[19:org.apache.aries.util:1.1.1]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[19:org.apache.aries.util:1.1.1]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[19:org.apache.aries.util:1.1.1]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[19:org.apache.aries.util:1.1.1]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[19:org.apache.aries.util:1.1.1]
at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1179)[org.apache.felix.framework-5.6.1.jar:]
at org.apache.felix.framework.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:730)[org.apache.felix.framework-5.6.1.jar:]
at org.apache.felix.framework.EventDispatcher.fireBundleEvent(EventDispatcher.java:485)[org.apache.felix.framework-5.6.1.jar:]
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4541)[org.apache.felix.framework-5.6.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2172)[org.apache.felix.framework-5.6.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)[org.apache.felix.framework-5.6.1.jar:]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1253)[4:org.apache.felix.fileinstall:3.5.6]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1225)[4:org.apache.felix.fileinstall:3.5.6]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:512)[4:org.apache.felix.fileinstall:3.5.6]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:361)[4:org.apache.felix.fileinstall:3.5.6]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:312)[4:org.apache.felix.fileinstall:3.5.6]
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.transport.client.PreBuiltTransportClient
at org.apache.camel.component.elasticsearch5.ElasticsearchProducer.doStart(ElasticsearchProducer.java:221)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:75)
at org.apache.camel.impl.DeferServiceStartupListener.onCamelContextStarted(DeferServiceStartupListener.java:49)
at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3629)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:3408)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3262)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:201)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3046)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3042)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3065)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3042)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2980)
at org.apache.camel.blueprint.BlueprintCamelContext.start(BlueprintCamelContext.java:244)
at org.apache.camel.blueprint.BlueprintCamelContext.maybeStart(BlueprintCamelContext.java:284)
at org.apache.camel.blueprint.BlueprintCamelContext.blueprintEvent(BlueprintCamelContext.java:177)
at org.apache.aries.blueprint.container.BlueprintEventDispatcher$4.call(BlueprintEventDispatcher.java:201)
at org.apache.aries.blueprint.container.BlueprintEventDispatcher$4.call(BlueprintEventDispatcher.java:199)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_121]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_121]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_121]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_121]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)[:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)[:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_121]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]
Any idea how to fix the issue?
Note : I have tried with feature available in 2.20 but it seems not working. here is the problem. I
Basically following two bundles have been used there.
Elasticsearch-Bundle mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch/5.4.3_1
Elasticsearch-Client Bundle mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch-client/5.4.3_1
In order to work with elasticsearch 5 you need TransportClient as mentioned in example which is available in Elasticsearch bundle
To get the TransportClient for first step you need to use PreBuiltTransportClient which is available in Elasticsearch-Client bundle.
Now the problem is that Elasticsearch-Client which is expected to return TransportClient does not have it and also not importing it and gives class not found exception "
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.client.transport.TransportClient not found by org.apache.servicemix.bundles.elasticsearch-client [127]"
This should be fixed with bundle version 5.3.2_1 from Servicemix and in Apache Camel 2.20.0.
In Camel 2.19.x branch we have the following feature for Karaf
https://github.com/apache/camel/blob/camel-2.19.x/platforms/karaf/features/src/main/resources/features.xml#L508-L522
While in 2.20.x branch we have a bundle for Elasticsearch client too:
https://github.com/apache/camel/blob/master/platforms/karaf/features/src/main/resources/features.xml#L566-L580
You can try with Camel 2.20.0-SNAPSHOT version.
UPDATE:
There is a JIRA issue about this: https://issues.apache.org/jira/browse/SM-3454 and we're going to fix it

Non-interactive auto-refresh stale OAuth Token with Googlesheets package

I'm trying to automatically run an r script to download a private Google Sheet every hour. It always works fine when I'm interactively using R. It also works fine during the first hour after I automate the script with launchd.
It stops working an hour after I start automating it with launchd. I think the problem is that after one hour the access token changes, and the non-interactive version isn’t waiting for the auto refreshing of the OAuth token. Here is the error that I get from the error report:
Auto-refreshing stale OAuth token.
Error in gzfile(file, mode) : cannot open the connection
Calls: gs_auth ... -> -> cache_token -> saveRDS -> gzfile
In addition: Warning message:
In gzfile(file, mode) :
cannot open compressed file '.httr-oauth', probable reason 'Permission denied'
Execution halted
I'm using Jenny Bryan's googlesheets package. Here is the code that I initially use to register the sheet, and then save the oAuth token:
gToken <- gs_auth() # Run this the first time to get the oAuth information
saveRDS(gToken, "/Users/…/gToken.rds") # Save the oAuth information for non-interactive use
I then use the following script in the file that I automate with launchd:
gs_auth(token = "/Users/…/gToken.rds")
How can I avoid this error when running the script automatically with launchd?
I don't know about launchd but I had the same problem when I wanted to run a R script automatically from the Windows task planer. Changing the 'cache' attribute value to FALSE did the trick for me [1]: https://i.stack.imgur.com/pprlC.png
You can find the solution here: https://github.com/jennybc/googlesheets/issues/262
To authenticate once in the browser in order to get a token file, I did this:
token_file <- gs_auth(new_user = TRUE, cache = FALSE)
saveRDS(token_file, "googlesheets_token.rds")
Automatic login afterwards via:
gs_auth(token = paste0(path_scripts, "googlesheets_token.rds"),
verbose = TRUE, cache = FALSE)

Broken datetime on CloudSQL + Google App Engine

So I had a lot of problems with datetimes in Django on the App Engine, but then I started tracing the error and seems like there's more serious problems. Here's what I'm seeing.
Here's my database:
mysql> select * from polls_question;
+----+---------------+----------------------------+
| id | question_text | pub_date |
+----+---------------+----------------------------+
| 1 | test | 2016-02-08 15:24:44.000000 |
+----+---------------+----------------------------+
1 row in set (0.16 sec)
And here's the code trying to read this data:
import MySQLdb
import os
import webapp2
class IndexPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
env = os.getenv('SERVER_SOFTWARE')
if (env and env.startswith('Google App Engine/')):
# Connecting from App Engine
db = MySQLdb.connect(
unix_socket='/cloudsql/<removed>:<removed>',
user='root',db='gaetest')
else:
# Connecting from an external network.
# Make sure your network is whitelisted
db = MySQLdb.connect(
host='<removed>',
port=3306,
user='root', passwd='<removed>',db='<removed>')
cursor = db.cursor()
cursor.execute('SELECT * FROM polls_question')
for r in cursor.fetchall():
self.response.write('%s\n' % str(r))
db.close()
app = webapp2.WSGIApplication([
('/', IndexPage),
])
On my computer it gives me:
(1L, 'test', datetime.datetime(2016, 2, 8, 15, 24, 44))
and when I access the remote url I get:
(1L, 'test', None)
Not sure what more I can do, this example is as simplified as it can get. Does anyone have any clue what's going on? Too bad Google is typically impossible to get hold off.
So after having spent way too much time on this I found the problem, the database was created using django's migrate function, which lead to it creating a datetime(6) (high precision), these don't work when accessing the site remotely. Normal datetimes work. So changing those makes it work.
The cause of the problem was when I used a newer mysql-python lib locally which supported datetime(6).
It was a bug with App Engine library MySQLdb 1.2.4b4, which at time of writing is also "latest". Switching the app.yaml dependency for MySQLdb from "latest" or "1.2.4b4" to "1.2.5" or "1.2.4" should fix the issue.

How to configure Search plugin in Cakephp 2.0

I was trying to incorporate Search plugin to my project and I thought I followed the instructions from the download site but whenever I access Posts it gives me these 3 lines of errors:
Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'PrgComponent' does not have a method 'startup' [CORE\Cake\Utility\ObjectCollection.php, line 110]
Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'PrgComponent' does not have a method 'beforeRender' [CORE\Cake\Utility\ObjectCollection.php, line 110]
Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'PrgComponent' does not have a method 'shutdown' [CORE\Cake\Utility\ObjectCollection.php, line 110]
Can someone help me figure this out please?
Thanks!
In Cakephp 2.0 component class extents Component not Object
So, write following code:
class PrgComponent extends Component {
}
Download site? Which download site? There is no "download site" for the 2.0 version of this plugin yet.
The 2.0 branch is here https://github.com/CakeDC/search/tree/2.0 and all tests for the PrgComponent pass.
9/9 test methods complete: 9 passes, 0 fails, 13 assertions and 0 exceptions.
Time: 0.29582810401917 seconds
Peak memory: 11,688,424 bytes
Run more tests | Show Passes | Analyze Code Coverage
Code coverage results Toggle all files
PrgComponent.php Code coverage: 99.06%
Check the 2.0 branch out from git.
Are you even talking about the CakeDC search plugin?

Resources