Change TIme Zone in Meteor synced-cron - meteor

I am using percolate:synced-cron in Meteor 1.2
I need to change the timezone 'Asia/Dubai'.
I have tried
SyncedCron.config({
utc: false, (true/false both)
timezone: 'Asia/Dubai'
});
and also in
SyncedCron.add({
name: ....
timezone: 'Asia/Dubai',
.........
});
But no luck.
Thanks in advance
UPDATE:
I have found another fork package where can I use timezone
saucecode:timezoned-synced-cron

From the code in the package:
Meteor.startup(function() {
var options = SyncedCron.options;
log = createLogger('SyncedCron');
['info', 'warn', 'error', 'debug'].forEach(function(level) {
log[level] = _.partial(log, level);
});
// Don't allow TTL less than 5 minutes so we don't break synchronization
var minTTL = 300;
// Use UTC or localtime for evaluating schedules
if (options.utc)
Later.date.UTC();
else
Later.date.localTime();
// collection holding the job history records
SyncedCron._collection = new Mongo.Collection(options.collectionName);
SyncedCron._collection._ensureIndex({intendedAt: 1, name: 1}, {unique: true});
if (options.collectionTTL) {
if (options.collectionTTL > minTTL)
SyncedCron._collection._ensureIndex({startedAt: 1 },
{ expireAfterSeconds: options.collectionTTL } );
else
log.warn('Not going to use a TTL that is shorter than:' + minTTL);
}
});
You'll notice it either uses utc or defaults to local time. There is no way to specify a specific timezone.

Related

Fullcalendar and Scheduler Issues with versions

I've a problem with FullCalendar (FC) and it's plugin Scheduler (S).
Since some some months I use the version 1.2.0 (S) together with 2.6.0 (FC).
It's ok, but a new request from our users (enable/disable grouping of resources) would be greatly satisfied using the feature 'get / set options dynamically'. So I've downloaded the new versions of the libraries, 1.4.0 (S) and 3.0.1 (FC).
Here come the problems: with the normal scheduler day view it works great. But, when I open a new page, where I use the weekly view, no data is show.
I've tried everything:
changed the versions, using the 2.7.3 (FC) with 1.3.2 (S).
used the version of (FC) packed in the zip together with (S).
having made some changes, I've deleted them, but the fault seems to lie in the way the libraries operate together.
I would post some code, but it's a bit complex... The scheduler is encapsulated inside a "class" and is activated using events. The whole infrastructure is part of a kind of framework and I cannot simply take a part of the code. What I'm sure is that the whole works with the older version, but no way with the new.
Up to now the only working solution is to use two versions, one for each page. But, of course, this is a kind of hack, not nice and not good for maintenance.
Here is the code used to generate the scheduler. _schedulerType is used to crate a daily or weekly view. Two "containers", _schedulerOptions and _schedulerServices are created outside and used to define how the scheduler is created.
_schedulerContainer.fullCalendar({
local (or lang): _schedulerOptions.language,
allDaySlot: false,
now: _currentDay,
selectable: true,
editable: false,
aspectRatio: _schedulerOptions.aspectRatio,
scrollTime: '07:30',
slotDuration: '00:15:00',
slotLabelInterval: '01:00:00',
slotLabelFormat: _schedulerOptions.slotLabelFormat,
slotWidth: _schedulerOptions.slotWidth,
nowIndicator: true,
customButtons: (_schedulerServices.schedulerHeader !== null) ?
_schedulerServices.schedulerHeader.createCustomButtons() :
null,
header: (_schedulerServices.schedulerHeader !== null) ?
_schedulerServices.schedulerHeader.createHeader() :
false,
defaultView: _schedulerType,
-------------------REMOVE-----------------------------------------
resourceLabelText: 'Rooms',
resourceGroupField: _defaultOptions.groupBy,
resourceOrder: _defaultOptions.orderBy,
resources:
function (callback) {
if (_schedulerServices.rscCallback !== null) {
if (log) {
console.log("reload resources inside scheduler");
}
callback(_schedulerServices.rscCallback.getResources());
}
},
------------------------------------------------------------------
events:
function (start, end, timezone, callback) {
if (_schedulerServices.evtCallback !== null) {
if (log) {
console.log("reload events inside scheduler");
}
callback(_schedulerServices.evtCallback.getEvents());
}
},
-------------------REMOVE-----------------------------------------
resourceRender:
function (resourceObj, element) {
if (_schedulerServices.rscViewManager !== null) {
return _schedulerServices.rscViewManager.requestRender(resourceObj, element);
}
},
------------------------------------------------------------------
eventRender:
function (eventObj, element) {
if (_schedulerServices.evtViewManager !== null) {
return _schedulerServices.evtViewManager.requestRender(eventObj, element);
}
}
});
Any help would be appreciated!
Thanks
Solved!!!
After version 2.6.0, the unused options fields of the options should not be used. In my case, removing all the fields related to Resources solved the problem.

meteor autocomplete server-side

I'm writing a meteor app and I'm trying to add an autocomplete feature to a search box. The data is very large and is on the server, so I can't have it all on the client. It's basically a database of users. If I'm not wrong, the mizzao:autocomplete package should make that possible, but I can't seem to get it to work.
Here's what I have on the server:
Meteor.publish('autocompleteViewers', function(selector, options) {
Autocomplete.publishCursor(viewers.find(selector, options), this);
this.ready();
});
And here are the settings I use for the search box on the client:
getSettings: function() {
return {
position: 'bottom',
limit: 5,
rules: [{
subscription: 'autocompleteViewers',
field: '_id',
matchAll: false,
options: '',
template: Template.vLegend
}],
};
}
But I keep getting this error on the client:
Error: Collection name must be specified as string for server-side search at validateRule
I don't really understand the problem. When I look at the package code, it just seems like it's testing whether the subscription field is a string and not a variable, which it is. Any idea what the problem could be? Otherwise is there a minimum working example I could go from somewhere? I couldn't find one in the docs.
Error: Collection name must be specified as string for server-side search at validateRule
You get this error because you don't specify a Collection name in quotes.
getSettings: function() {
return {
position: 'bottom',
limit: 5,
rules: [{
subscription: 'autocompleteViewers',
field: '_id',
matchAll: false,
collection: 'viewers', // <- specify your collection, in your case it is a "viewers" collection.
options: '',
template: Template.vLegend
}],
};
}
For more information please read here.
Hope this helps!

how to write synced-cron job that executes 20 seconds later - SyncedCron Meteor

I want to create a synced-cron job which runs only once and the execution time will be 20 seconds later as soon as the job is created. How would I write the parser?
Meteor.setTimeout can be run on the server
If you want something that runs 20 seconds after server startup, you can do this
if(Meteor.isServer){
var job = function(){};
Meteor.startup(function(){
Meteor.setTimeout(job, 20000);
});
}
If you are set on using synced-cron, you can use SyncedCron.remove(jobName). See Advanced section of Synced Cron Docs
if(Meteor.isServer){
SyncedCron.add({
name: 'Run in 20 seconds only once',
schedule: function(parser) {
// parser is a later.parse object
return parser.text('every 20 seconds');
},
job: function() {
// do something important here
SyncedCron.remove('Run in 20 seconds only once');
}
});
Meteor.startup(function(){
SyncedCron.start();
});
}
According to the doc:
To schedule a once off (i.e not recurring) event, create a job with a
schedule like this parser.recur().on(date).fullDate();
So you can set something like parser.recur().on(new Date()+1000*20).fullDate() to execute the job once.

Update Mongo on the client using document ID, but limiting search with another field

When updating a document which contains an array of objects, I have this function:
Template.editCompetition.events = {
'click button.promote': function() {
Competitions.update({_id: Session.get('competition_id'), 'players.user_id': this.user_id}, {$set: {'players.$.supervisor': true}});
},
};
I am seeing the error:
Uncaught Error: Not permitted. Untrusted code may only update documents by ID.
My document looks like this:
{
_id: 'aaaabbbbb',
title: 'ccccdddddd',
players: [
{
username: 'wwwww',
user_id: 'xxxxx',
supervisor: false
},
{
username: 'yyyyy',
user_id: 'zzzzz',
supervisor: false
}]
}
Isn't my query updating the document by the ID, but also searching for that array position to use the .$ notation.
How can I achieve this without using a method, which seems a bit hacky...?
You are also trying to use the player.user_id as second parameter for update query
Other option you can have to use Meteor.method.
Move Collection update code to Meteor server side method and call it from client side
On Server side,
Meteor.methods({
`update_players`: function(competition_id){
user_id = this.userId
Competitions.update({_id: competition_id, 'players.user_id': user_id}, {$set: {'players.$.supervisor': true}});
}
})
In in above code, understand use of how we fetched current userId with this.userId
and now from your click handler call this meteror method
Meteor.call('update_players')
Hope this helps

How to use reactive vars on server side

I want to use a reactive counter var on server side. But I can not guess how to do it without using collections.
I expect {{count}} will be updated after server count var changed without refresh a page or how to send a client that the count was changed?
<body>
{{> test }}
</body>
<template name="test">
{{count}}
</template>
client:
Meteor.call('count', function(err, result) {
console.log(result)
Session.set('count', result)
})
Template.test.helpers({
count: function () {
return Session.get('count')
}
});
server:
var count=0
Meteor.startup(function () {
Meteor.setInterval(function() {
count++
}, 1000)
});
Meteor.methods({
count: function() {
return count
}
})
My code on MeteorPad
I want to see what I expect:
Client:
Meteor.subscribe('count')
Template.test.helpers({
count: function () {
return Counter.findOne().count
}
});
Common:
Counter = new Mongo.Collection('count')
Server:
Meteor.publish('count', function() {
return Counter.find()
})
Meteor.startup(function () {
if(Counter.find().count() === 0) {
Counter.insert({count: 0})
}
Meteor.setInterval(function() {
Counter.update({}, {$inc: {count: 1}})
}, 1000)
});
Example on meteorpad
It depends on how you plan to scale your application. If you plan to scale to multiple server instances then you cannot rely on the servers sharing information automatically. In this case it would be best to create a collection named something like "ApplicationState". Then every instance of your application can use a consistent state, and you can make use of the built in subscriptions.
If you plan to only use a single server instance then you should checkout the documentation on Tracker: http://manual.meteor.com/#tracker. This allows you to defined custom dependencies on data. I have not had the chance to play with it yet, but I am pretty sure that you can create something similar to subscriptions: http://manual.meteor.com/#deps-creatingreactivevalues
Your code does not work as the way you want it because regular plain vars are not reactive data sources. The docs has a list of reactive data sources here http://docs.meteor.com/#/full/reactivity - So for your example to work you'd want to use Session or ReactiveVar - but these only works on the client so they wont help you here.
Your best bet is to create a manual publish function and subscribe to it from the client (or as other people has proposed, use a Collection - which would work across multiple servers as well). Hope that helps!

Resources