I am trying to make a bot that sends quotes in servers at different intervals of time (defined by the server admins) by storing the channel id and the time interval (in seconds) inside a db. I managed to get it working for a constant amount of time (say 10 minutes) with #tasks.loop() but I cant figure out how to make it post at different intervals.
Task loops have a method called change_interval which can, as you'd expect, change the interval, you can find out more on here
Related
Im using react and node.js
Im trying to build a site that has multiple countdown timers where an user can join in before it hits 0. These countdown timers are displayed based on a pre-set datetime value in the database. When the time hits 0 (datetime is reached) i need that specific timer to become disabled and trigger a function to send out something (like an email) to all those that entered.
I tried looking around but im not sure whats best used for this (must be reliable). I saw cron-scheduler, cron, cron-node etc but maybe im looking at it from the wrong angle... The only requirements are that it needs to trigger at the given datetime and send out a message (like an email, seperately).
Usually timers run for a couple days to maximum a week
We use Django and Celery for our backend serving our APIs. For scheduled tasked we use django-celery-beat. We are running Postgresql for the database and django-celery-beat includes all of the models for the tasks and includes cron.
I know this question is a bit generic but bear with me. I have an app which basically posts to website based on a user schedule. Now the app works great locally I m using moment js to compare the scheduled date/time with the current time and then if current time has exceeded scheduled time then that means it should start the auto posting process. The problem arises when I deploy the app to production the time there is different to the time here because of different timezone. How do I ensure (in moment js) that whatever time user schedules at whatever corner of the world the server posts it accordingly and does not start checking on what time it has there. To give you an example at the time of writing this it is Saturday 08/08/2020 00:48 here in PST, the server time is Friday 7/08/2020 19:47. So if I schedule here for say 1am, its only 10 mins to 1am here but for the server there is several hours. how do I manage that? Any ideas or pointing me in the right direction would be really helpful thank you for your time.
You could use moment.utc() on your datetime variable and then you would have 2 options.
Make your system works based on utc timezone always or convert the utc datetime to any timezone you want using the moment timezone library.
https://momentjs.com/timezone/
There could be multiple approaches to solve this problem statement.
One approach is you can calculate the number of seconds from the created time(the current time) to post the content instead of the exact time at the browser from the chosen time by the user and send that to the server to store and run the logic accordingly at the server.
The title isn't accurate because based on what I have found in my research there doesn't seem to be a way to make a function atomic in nodejs, but I will lay out my problem to see if you people can come up with something that I have not been able to think about.
I am trying to setup a scheduler where I can set my appointment time slots say 1 hr long each and when someone makes an appointment I want to make sure that the time slot is not taken before scheduling it.
So for example I decide that I will be working from 9 am to 2 pm with a time slot of one hour. Then my schedule would be 9-10, 10-11, 11-12, 12-1, 1-2.
An appointment will come in with a start time of 11 and end time of 12. I need to make sure that slot isn't already taken.
I am using mongodb with nodejs and restify.
I understand that in my appointments collection I can set an index on a combination of values like start time and end time, as discussed here Creating Multifield Indexes in Mongoose / MongoDB.
But if I decide to change my time slot from 1 hour to say 1.5 hours then I will have scheduling conflicts as the start time and end time of entries in the database will not match up with the new interval
Currently I have a function which checks to make sure that the new appointment will not conflict but I am not sure if it will work out well when I have multiple requests coming in. This is a nodejs and restify app so basically an api with a mongodb that it talks to, to handle appointments.
I am running it with multiple workers, so I am worried that at a certain point two requests will come in at the same time, handled by two different workers for the same time slot. When my conflict checking function executes it will return saying that the slot is open for both of them since no appointment has been made yet and then there will be a scheduling conflict.
Any ideas on how to combat this, or is there something in the way javascript executes so that I shouldn't have to worry about it this? All input will be appreciated
Thanks!
I ended up using https://github.com/Automattic/kue, to queue my requests and added another endpoint where you can check the status of your request. So when you want to make an appointment your request ends up in the job queue, and you can then periodically check the status of your request. This way only one appointment request gets processed at a time so no concurrency issues.
I am saving a counter number in user storage.
I want to provide some content to the user which changes daily using this counter.
So every time the counter increases by 1 the content will change.
The problem is the timezone difference.
Is there anyway to run a function, daily which will increase this counter by 1. I could use setInterval() which is a part of the NodeJs library but that won't be an accurate "daily" update for all users.
User storage is only available to you as a developer when the Action is active. This data is not available once the Action is closed, so you wouldn't be able to asynchronously update the field. If you do want asynchronous access, I'd suggest using an external database and only storing the database row key in the user's userStorage. That way you can access the data and modify it whenever you want.
The setInterval method will run a function periodically, but may not work in the way you want. It only runs the function while the runtime is active. A lot of services will shut down a runtime after a period. Cloud Functions, for example, run sometimes but then will shut down when not used. Additonally, Cloud Functions can be run several times in parallel instances, executing a setInterval function several times in parallel. That would increment the counter more times than you want.
Using a dedicated Cron service would help reduce the number of simultaneous executions while also ensuring it runs when you want.
You are unable to directly access the user's timezone within the Action, meaning you won't be able to determine the end of a day. You can get the content to change every day, but it'll have some sort of offset. To get around this, you could have several cron jobs which run for different segments of users.
Using the conv.user.locale field, you can derive their language. en-US is generally going to be for American users, which generally are going to live in the US. While this could result in an odd behavior for traveling, you can then bucket users into a particular period of execution. Running the task overnight, either 1AM or 4AM they'll probably be unaware but know that it updates overnight.
You could use the location helper to get the user's location more precisely. This may be a bit unnecessary, but you could use that value to determine their timezone and then derive that user's "midnight" to put in the correct Cron bucket.
I'm using JMeter 4.0 trying to create a stress test. The purpose is to emulate the types of requests we receive in production, which is generally an array of requests of different types with a certain frequency and occasionally (1 in 1000) duplicate requests of the same type within milliseconds of each other.
I've managed to create a thread group emulating frequent requests of different types and a second thread group emulating duplicate requests (using synchronizing timer to ensure the requests fire off together).
I'm almost finished. My only problem is that there is no relationship between the thread groups whatsoever. If I wanted to perform a duplicate request once every 1000 requests, I'd need to know how long it takes to perform an average request (which is complicated by the fact that there are several request types) and calculate the time it would require for roughly 1000 requests to be made, and add an appropriate constant timer in the other thread group.
This isn't ideal. I'll settle for this if I must, but I was hoping the bright minds of stackoverflow could shine some insight for my issue.
Some ideas I've had:
Add a run counter which cycles every 1000 normal requests and once run counter hits 1000, I perform a second request (though it would be under the same thread and after I've received the response from the first). Could this be made to work using a synchronized timer?
Use a constant throughput timer with "all active threads (shared)" set whose samples per minutes is set to 1000.
Is there a better way still? The actual requests are HTTP requests, though there are several steps prior in preparation of the message to send. I'm already using a constant throughput timer in the first thread group (random service requests) to maintain a specific amount of requests per minute, so I'm not sure if adding a second constant throughput timer in the other thread group would create issues.
Thank you for your time.
You can add If Controller with condition of 1 every 1000 threads
${__jexl3(${__threadNum} % 1000 == 0)}
and inside If Controller execute your duplicate HTTP Request
__threadNum return current thread/user number