I am trying to write a cloudwatch event / cronjob rule that triggers on every first working day of the month but if that day happens to be a public holiday in the united states then I want it to be triggered in the next working day.
Is there any way to achieve this using Cloudwatch?
Is there any way to achieve this in CRON?
If no then how are these kind of use cases solved?
Thankyou!
Cron is very simple, so I think the best approach would be to have an event that fires on a daily basis, but which triggers a lambda. That lambda can decide if it is the first working day of the month or not. I'm assuming that there is some way to look up online if a given day is a US public holiday.
Related
I am sorry but there is no code attached to this, as I simply don't know what direction to go in. I have a bot made for a clan in Anigame. Quite simply there are weekly donations,(in this case it's 30k). For someone to donate, they can do .cl donate [number].
Ex: .cl donate 30000 | This donates 30k to your clan which is the weekly donation required and means you have donated for the week.
Tracking donations is a pain in the ass so I wanted to make a bot to do it for me.
What I wanted to do is make it so that this person that just donated 30k can do .info and it says something like this:
Weekly: Done!
Debt: N/A
The debt being for people that have missed a week's donation.
EX: Someone hasn't donated for 2 weeks, has 60k debt. This is the third week, and if they decide to donate 90k that week, the bot makes it so weekly donation is paid and debt is paid.
I also don't know how to make that become possible, and I hope you [reader] understand where I'm trying to go with this.
I have the base cron job code to make sure it resets weekly, I just don't know how to do the code)
Tldr; How to make it so that .cl donate (number) updates a Weekly Number under the command [.info]. I wouldn't normally be so specific so I can learn how but I don't know the commands associated with doing this kind of thing. Thanks~
You should start with researching databases (for example SQLite), and then coding your bot to input values to that database on each command, then calculate the .info command based on the values that specific user has in the database, then your cron job could reset the database weekly (or the bot could do that too, you do you). Here's a good tutorial: SQLite tutorial
Kusto provides functions to get the start- and end-day of the week. These are invoked through startofweek() and endofweek(). startofweek() returns Sunday, and endofweek() returns Saturday.
In some countries, weeks are from Monday to Sunday, which I have been unable to locate how to change.
Is it possible to set the culture in kusto, such that startofweek() and endofweek() would return Monday and Sunday respectively?
No, I have not seen a setting where culture can be set in Kusto. Where operating systems and applications which make it possible to set such configurations, I see Kusto being being fairly basic and similar to .NET libraries where the DayOfWeek enum begins with Sunday at index 0 and there is no way to change that foundation.
The documentation indicates that "Start of the week is considered to be a Sunday." so I believe that is that. It is up to us users to adapt from there. (https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/startofweekfunction)
I'm sure you have done this yourself already, but here has been my approach.
startofweek(now()) + 1d
endofweek(now()) + 1d
I have an application that uses subscriptions for each member that joins. I'm having some issues with dates and calculations related with it. For example, let say a member joins on 2/10/2020 at 10:00. When the user submit the request to the server to process the subscription (the server is using UTC) the date that is being calculate is 2/10/2020 16:00 (because I'm -6:00 hours from UTC). This scenario is OK at this point, because the date is still the same (no matter the time). But, if we replicate this scenario when the user joins for example 2/10/2020 at 19:00, when the request is received and calculate the date, the result is 2/11/2020 01:00, and that produces an error in the invoice because the billing date of the invoice is wrong (one day after). What is the best way to implement this? I have read a lot of this topic, but most of the pages and questions are related in the other way, server to client, to parse of format dates to display to the user.
I have several questions related with this process.
Should I sent the date for the UI to the API? Or the timezone and
based on that, calculate the date in the API? (since the server have
UTC)
Moment.js library have a way to solve this or should be better with vanilla Javascript using Date?
Is there any HTTP header for the request to handle the time or date?
This really depends on what behavior you want to have. Before you try to fix anything, think through and decide on the exact requirements for what the billing date should be based on.
Is the user's time zone relevant? If so, you'll likely need to know what the user's time zone is. You'll be potentially assigning different dates to different invoices even if they're using the same UTC point in time. Your business might get confused on why some customers have invoice dates before or after the business day.
Or maybe the time zone of your company is more relevant? Many business work that way. All of your invoices will be aligned, but some customers might get confused on why their invoice date is before or after their current date.
Or maybe some customers snap to time zones of nearby offices, in the case of businesses with offices around the world.
Only you and your company can decide this. There are probably other options I'm not thinking through here. It's a business decision, not a technical one.
On your three questions:
That depends on what you decide above.
Libraries are a good idea for simplifying your code, but they're not a hard requirement. You can use the Date API, if you know what you're doing, but you may find libraries easier to work with. Also, Moment is in maintainance mode. For new development, the Moment team recommends you use Luxon instead of Moment. There are other popular modern libraries also, including date-fns and js-Joda.
There's the date header, but that's not going to help you with this.
I am doing a mobile game server using node.js. I used the Express and postgresql
I have two questions.
This game has a Inapp is 30 daily gems that user can get the gems in 30 days period. But I don't know how to implement the method let the server know the user bought this item and send the reward to this user every day.
This game has a special offer item in InApp. For example, a Christmas pack in 25/12 - 27/12. But I don't know how to set this 3 days can show this pack.
I am beginner in node.js. So I hope that you don't think my question is stupid. Thanks
Speaking at a high level, you have quite a few options.
For your gems requirement, you would probably have a field or table that represents this gem purchase, e.g a start date. If a user bought this package say on 1/1/2019 then your node server can have a process that runs once a day that queries the purchase table and give gems to any user where the current date is less than 30 days ahead of the purchased date.
Your table may look like:
user_id
date_purchased
gems_per_day
To implement this as a function that will run once a day, you may want to create a singular script for it and run it on a cron job once per day or create a Timer type class within Node that will run your function every 24 hours.
For your special offers, as part of your Store code, let's say you have a function that updates what items are currently available in the store, you run this code once per day (as one of the 2 methods mentioned above) and probably storing these items in your database. Similarly, you can check each day if the current date is within this "special offer period" and if it is, you can set that product within your database to be active.
Your table may look like:
product_id
enabled
or
product_id
start_dayMonth
end_dayMonth
Hope this gives you a few ideas of how you can lay this out. Happy to answer any questions
In my event sourced application developed using DDD, there are saving accounts that should accumulate interest every day. At the end of every year the accumulated interest should be capitalized. My question is: Should every daily calculation really be treated as a domain event?
An alternative could be to calculate the accumulated interest at a given point in time on the read side by traversing the transactions that has happened on the account up until that day (withdrawals, deposits etc), and sum the accumulated interest for each day.
The amount of events in the event store would quickly grow to millions, given that there could be hundreds of thousands saving accounts in the system calculating their accumulated interest each day. But at the same time it seems like a drawback to have to calculate the accumulated interest "on the fly" on the read side instead of raising an event every day.
I'm no banking expert, but InterestCredited looks like the event you really want to store since it will change the state of the system.
Accumulated interest is a virtual concept if I understand correctly - modelling it as an event of its own adds no value. You would be able to calculate the capitalized interest at the end of the year anyways regardless of daily InterestAccumulated events being present. Instead, a simple read-side value recalculated each day seems to match the need pretty well.
Interest accumulation is only a domain event when it gets credited/debited to an account. Until that occurs it doesn't mutate aggregate state. Consider corrective events, posting errors (e.g an NSF credit reversal). You would need to correct for every daily incorrect interest calculation between the original and correction.
The read side can take care of rolling up accrued interest at whatever intervals desired.
Should every daily calculation really be treated as a domain event?
What do your domain experts say?
You might also want to review chapter 11 of the blue book, which includes "Example: Earning Interest with Accounts". That may not directly answer your question about the domain events, but it should provide you with some extra context for framing your own analysis.
I'm not a domain expert, but my expectation would be that accrued interest has implications, either legal, or in the model, and that you would expect to have a consistent record of the accrual and its consequences on your model.
From your initial description, the impact on the model is annual, so I would expect to see the InterestCapitalized event only once per year per account. But I find it difficult to believe that daily accrued interest doesn't matter, especially in the face of changing balances and compounding interest, so I'm suspicious that the described requirement actually matches the needs of the business.
I wouldn't expect "millions" of events to be that big a problem; using the CQRS pattern, most of your reads are going to come out of rolled up results anyway, so that's not a big deal. The real hurt will be in trying to re-hydrate an aggregate with millions of events; but if you are facing performance problems there, you can look into loading the aggregate from snapshots.
And of course, if each account is calculating its own accrued interest, then you are only looking at 365 (ish) extra events per year, which is no sweat at all.