Can Timer Triggers call Activity Triggers in Azure? - function

I am creating a timer trigger function that is going to do certain checks. If a certain conditional is hit, I want to send an email and have set this up through an Activity Trigger. I keep getting the error
The function 'activityTriggerName` doesn't exist', additional info: No orchestrator functions are currently registered!.
I am brand new to durable functions and triggers in Azure, any direction on if this is allowed or other ideas would be appreciated.

Activity functions can only be initiated by an Orchestrator. The usual pattern is to have a trigger function create an orchestrator and then the orchestrator initiates one or more activity functions.
If you’re using Visual Studio then the Orchestrator template will create a sample which includes an HTTP trigger, an orchestrator and an activity.

Related

Is there a way to check when a firebase function last ran?

I inherited project and I'm trying to sanitise the functions. I have 50 functions I'm wondering what's the best way to see when the functions were last run? From the firebase project console (functions tab) I can get logs for the different functions. Some functions have no logs. Can I assume if a function has no logs that it never ran?

Creating a task scheduler in GAS?

So I'm just getting back into scripting with GAS and I'm trying to make a scheduler/reminder system for tracking periodic maintenance that has to be done.
The idea is a form that fills info to a spreadsheet (easily done), and then iterate through the sheet and create events on a dedicated calendar for every 'job', with recurrence set to how often the job needs doing. ie: every 3 months, clean the drains.
I have this part of it working. What I'm wondering is... is it possible to have a script call a function at a specified date and time? Like instead of a calendar event that emails you a reminder about the event on the day of (or whenever), maybe call a function so that I can email them some details about the job (again, pulling from the sheet, which is simple enough) and maybe throw it at Pushbullet API to push to the user's phone/browser. I've played with PB's api, and everything, the ONLY part of this that I don't have working is the scheduled future script firing.
If this isn't possible, would anyone be able to recommend an alternative?
Edit: For clarification, I'd be wanting to set up a one-time execution of a function on say ... June 14th. In terms of recurrence, I can just have it set the next scheduled run during the execution.
If I understood correctly, you need to use the Trigger!
Yes, it’s possible. Use time-driven triggers. For details see https://developers.google.com/apps-script/guides/triggers/installable

Can you do something on a Google-Apps-Script fail?

Is there a way to have an automatic 'back-up' plan if my Google Apps Script fails? I'm thinking something along the lines of a python Try / Except.
For example, I am building a function to create a calendar event from a form (script is attached to the spreadsheet the form is linked to). The script creates an event number for the new form submission (storing it in the spreadsheet) and then makes the calendar event. If my function fails in making the event, there is a new event number in the spreadsheet, but no event in the calendar.
Does Google Scripts have a pre-built way to fail gracefully?
Or, is there a way to build an outer function that runs the original and has the graceful fail as (e.g.) the else of an if-then-else?
Apps Script is based on Javascript, so you can use the try...catch functionality.
If you are calling functions on your Apps Script back-end from your front-end you can also use the withFailureHandler to handle a failed execution.

Is there a way to run two functions at the same time(simultaneously/asynchrounously) with one function as an infinite loop?

I have two functions that I want to run at the same time but I can't just let them run separately as one function contains an infinite loop while(true). And the problem with JavaScript is that if you where to run two functions, it will finish running the function before running the next one; so if I run a function with a while(true) loop, it will never move onto the next function.
If you still don't understand, here is my code:
function onOpen(){ // Google Apps Script trigger
infLoop() //how to run both of these functions at the same time?
runScript()
}
function infLoop(){ //inf loop.
while(True){
Utilities.sleep(100)
DocumentApp.getActiveDocument()
.setname("dont change this name")
}
}
function runScript(){
//code...
}
Google apps script executes synchronously. For the most part, simultaneous/paralell processing is not possible. Based on your script, it seems you want two functions to run simultaneously onOpen. Possible workarounds(Some not tested):
Workaround#1: Use Different projects
Create a new project: In the editor(Legacy/Old editor only)>File>New>Project
First project's onOpen() will run infLoop()
Second project's onOpen() will run runScript()
Both functions will run simultaneously on open.
Workaround#2: Simple and Installable trigger1
Create a installable trigger for runScript()
Simple trigger onOpen() will run infLoop()
Both functions will run simultaneously on open.
You could use two installable triggers instead of simple and installable trigger.
Workaround#3: Web apps: Call from client
If there is a sidebar open or if a sheet is opened from web app, it is possible to call server functions repeatedly through google.script.run(which run asynchrously)
Here It is possible to run a function for 6 minutes(current runtime). But by repeatedly calling the server function, you can run the function for a long time(upto 90minutes/day = current trigger runtime quota/day)
Workaround#4: Web apps: UrlFetchApp#fetchAll2
UrlFetchApp#fetchAll runs asynchronously
Once a web app is published, the published url can be used with query parameters. If a function name is sent as a parameter and doGet() executes the function, .fetchAll can be used to multiple functions asynchronously.
Workaround#5: onEdit/onChange
If a edit is made, both functions(onEdit/onChange) run simultaneously.
Workaround#6: Sheets API/onChange
If a add-on/script makes a change through sheets api, onChange may get triggered. If triggered, every change made through sheets api causes onChange to run asynchronously.
To run two or more functions "at the same time" you should call each function separately. One way is to use promises from client side code.
Bear in mind that your server-side infinite loop eventually will cause that your script exceed the maximum execution time (6 minutes / 30 minutes depending on the account type that effective user is using).
Related
Using promises for mulitple queries to Google sheets
Running an infinite loop in Apps Script is futile, since there's an enforced maximum execution time of 6 minutes for most scripts. When you hit that limit the script execution will be killed.
Judging from your example script, what you're attempting to do is a scheduled job to set the document name. For that purpose, you would be better served using a time-driven trigger.
You could then structure your script like this:
function onOpen() {
// code...
}
function updateDocumentName() {
DocumentApp.getActiveDocument().setName("dont change this name")
}
Then, you can setup a time-driven trigger associated with the updateDocumentName() function.
One major difference to note: instead of executing the logic every 100ms, the highest frequency you can set with a time-driven trigger is once every 1 minute.
YES! Simply put one function inside the other.
function EmailSummary() {
// Modified from http://stackoverflow.com/a/22200230/1027723 .. SOURCE: https://mashe.hawksey.info/2015/07/tips-on-emailing-inline-google-charts-from-sheets-using-apps-script/
function emailCharts(sheet_name){ // eg "SF_EMAIL"
sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet_name)
var charts = sheet.getCharts();
if(charts.length==0){
MailApp.sendEmail({
...
Just make sure to indent correctly.

Google Sheets Add-on timed-trigger for a large data set

According to Google app script time-trigger documentation https://developers.google.com/apps-script/guides/triggers/installable#limitations,
Time-driven triggers cannot run more frequently than once per hour. How can I use app script to write an add-on that process large amount of data?
If I run a trigger, it will only allow me to trigger once. I can't chain the triggers so it can continuously run.
You cannot do so using triggers because they would run at most once per hour in the context of an add on.
What you can do is to initiate such processing client-side while possibly showing progress on a sidebar. The client js in the sidebar can chain server calls.Of course being all client-side means the user must have opened the file and if they close the browser tab or navigate away, the chain calls will stop. That can be handled by alerting the user and making them aware that a "sync" happens and sometimes takes a while. Currently there is no other way to handle this unless your client call and time trigger call another server which does the processing, like appengine or gce.