architecture – Event loop for console input

I have a server application that runs in an infinite loop, only reacting to SIGINT. It is put inside a screen process. If I have to make any changes (reload configuration, add new plugins, etc) I simply restart the whole process so the changes are picked up during initialization.

I’d love to refactor the application so that I have two ways of interacting with it: A web UI, and a console interface.

For the web UI I use a small embedded HTTP server and can hook up the requests to my event loop. But I’m unsure how I should implement the cli. Is it advantageous to provide a separate cli process, accessing the same embedded server? Or would it be preferrable to make my own application wait for text input? In the latter case, I’m struggling with implementing the event loop to poll both the web requests as well as the console at the same time.

php – WordPress schedule event function not running

I am totally new with the schedule event from WordPress.
For my theme I created a function that must run every minute.
To test my scheduler I created a test function that send me an email.
But I do not receive an email and I think my scheduler is not working.
Please who can help me a bit?
Below my code so far

add_action( 'my_test', 'test_scheduler');
add_filter( 'cron_schedules', function ( $schedules ) {
   $schedules('per_minute') = array(
       'interval' => 60,
       'display' => __( 'One Minute' )
   );
   return $schedules;
} );

//create event after theme setup
add_action("after_setup_theme", function(){
    if (! wp_next_scheduled ( 'my_test' )) {
        wp_schedule_event( time(), 'per_minute', 'my_test' );
    }
});

//delete event if theme is deactivated
add_action('switch_theme', function(){
    wp_clear_scheduled_hook( 'my_test' );
});

The code above is in the functions.php file.

postgresql – How to trigger when an event crosses now()?

Is it somehow possible in postgres 12 to trigger an event when a table with an tsrange column crosses now(), or someone insert something that where the tsrange is prior to now()?

Triggers, as far i know, only triggers when someone insert or updates a row.

Triggering when someone insert a row which has passed now, seem to doable
With trigger that triggers on all inserts, but i am not sure how to trigger an event, when a given timestamp in that row crosses now..

And can both trigger scenarios be combined into one?

sharepoint enterprise – ItemUpdated event not firing

I have this code where only ItemAdding is firing when I add new item in the list but ItemUpdated doesn’t fire. I am expeting that when new item is added then first ItemAdding fires (which is working) and then ItemUpdated is fired (which is not working).

ItemUpdated only fires after item has been created and then I manually edit record.

public override void ItemAdding(SPItemEventProperties properties)
{
   if (properties.ListTitle == "MyList")
   {
      base.ItemAdding(properties);
      properties.AfterProperties("Department") = "Information Technology";
   }
}

public override void ItemUpdated(SPItemEventProperties properties)
{
   //some code here
}

In elements.xml file I have written following for both events but no luck. Even if I remove this line then it still doesn’t work.

<Synchronization>Synchronous</Synchronization>

How to fix this issue?

postgresql – Ignoring temp table in Postgres event trigger

I am trying to have a trigger that gets invoked when new tables, except temporary tables, are created.

This is what I have tried:

CREATE OR REPLACE FUNCTION insert()
RETURNS event_trigger
AS $$
DECLARE
    r RECORD;
BEGIN
    FOR r IN SELECT * FROM pg_event_trigger_ddl_commands() LOOP
        RAISE NOTICE 'caught % event on %', r.command_tag, r.object_identity;
    END LOOP;
 END;
 $$
 LANGUAGE plpgsql;

CREATE EVENT TRIGGER insert_event ON ddl_command_end
  WHEN TAG IN ('CREATE TABLE', 'CREATE TABLE AS', 'CREATE FUNCTION', 'ALTER TABLE', 'DROP TABLE')
 EXECUTE PROCEDURE insert();

create TEMP table my_table(id serial primary key);

This is the output I see:

CREATE TABLE
CREATE FUNCTION
CREATE EVENT TRIGGER
CREATE FUNCTION
CREATE EVENT TRIGGER
NOTICE:  caught CREATE SEQUENCE event on pg_temp.my_table_id_seq
NOTICE:  caught CREATE TABLE event on pg_temp.my_table
NOTICE:  caught CREATE INDEX event on pg_temp.my_table_pkey
NOTICE:  caught ALTER SEQUENCE event on pg_temp.my_table_id_seq

How do I exclude temporary tables from invoking the trigger?

security – How we can secure the ClientID & ClientSecret inside our remote event receivers (Inside SharePoint Provider hosted app)

I have developed many remote event receivers and host them inside azure web apps. now the web.config file inside those remote event receivers contain the ClientId & ClientSecret, as follow:-

 <appSettings file="custom.config">
    <add key="ClientId" value="e***7" />
    <add key="ClientSecret" value="h***g=" />
  </appSettings>

Now if a hacker or an end user found those values inside the project code, then the user can control all the sites, as when we register the remote event receivers we grant them full control on the site collection.. so any advice how we can secure those details? so if someone access the source code of the RER then she/he can not view those details?

Thanks

Azure Event Hub vs Event Grid or something else?

I have a timer function that calls a group of APIs asynchronously and then converts the XML responses to SQL Server records to an on premises database. I want to send a message in case there is a failure in the response so that I can retry the API call. After reading the documentation for Event Hubs and Event Grids, I’m not sure if either one of those options satisfies my requirement. The following is the documentation I’ve read:

https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-about

https://docs.microsoft.com/en-us/azure/event-grid/compare-messaging-services

Any insight would be appreciated.

magento2 – Can’t get getCustomer() in custom event

If I observe customer_save_after event I can get information about the customer with $customer = $observer->getEvent()->getCustomer();.

However, if dispatching my custom event instead of customer_save_after I get

Error: Call to a member function getDataModel() on null

when I try to get it like $customerData = $customer->getDataModel();

I think this is because I can’t even get getCustomer() in an custom event.

Is there anything I could do to get the same data as from customer_save_after?

development – I am no longer able to debug/run my SharePoint Remote Event Receiver locally using Ngrok

Last month the below steps were working well for me to debug and test a SharePoint online remote event receiver locally:-

  1. Open Ngrok.exe >> run the following command inside ngrok:-
 ngrok authtoken 3***e
 ngrok http --host-header=rewrite  57269
  1. register a new app:- @ https://.sharepoint.com/sites//_layouts/15/AppRegNew.aspx >> enter the above Ngrok urls inside the App Redirect URL & App Domain.

  2. Inside the _layouts/15/appinv.aspx >> I search for the above app using Client ID >> and enter the following:-

 <AppPermissionRequests AllowAppOnlyPolicy="true">
   <AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
 </AppPermissionRequests>
  1. Update the service’s web config with the above ClientID and ClientSecret

  2. Register the new remove event receiver as follow:-

 Add-PnPEventReceiver -List "Order Management" -Name "TasksRER" -Url http://cc6e945e82f6.ngrok.io/service1.svc -EventReceiverType ItemUpdated -Synchronization Asynchronous

But today when I tried the above steps it failed >> where inside my event receiver when I tried to get the SharePoint context >> I will get that the Context is null:-

  public void ProcessOneWayEvent(SPRemoteEventProperties properties)
         {
             var prop = properties;
             var listItemID = properties.ItemEventProperties.ListItemId;
             var listTitle = properties.ItemEventProperties.ListTitle;
             using (ClientContext context = Helpers.GetAppOnlyContext(properties.ItemEventProperties.WebUrl))
             {
                 context.Load(context.Web);
                 context.ExecuteQuery();

Here is a screen shot from Visual Studio with the error i am getting when trying to get the context:-

enter image description here

Any advice if anything has been changed which is preventing me from running the above steps? which were working well last month?
Thanks

here is the code for the GetAppOnlyContext

     public class Helpers
         {
             public static ClientContext GetAppOnlyContext(string siteUrl)
             {
                 try
                 {
                     Uri siteUri = new Uri(siteUrl);
                     string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);
                     string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;
        
                     return TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), accessToken);
                 }
        
                 catch (Exception ex)
                 {
                     Trace.TraceInformation("GetAppOnlyContext failed. {0}", ex.Message);
                 }
                 return null;
             }
        
             public static ClientContext GetAuthenticatedContext(string siteUrl)
             {
                 string userName = WebConfigurationManager.AppSettings.Get("AuthenticatedUserName");
                 string password = WebConfigurationManager.AppSettings.Get("AuthenticatedUserPassword");
                 return GetAuthenticatedContext(siteUrl, userName, password);
             }
        
             public static ClientContext GetAuthenticatedContext(string siteUrl, string userName, SecureString password)
             {
                 ClientContext ctx = new ClientContext(siteUrl);
                 ctx.Credentials = new SharePointOnlineCredentials(userName, password);
                 return ctx;
             }
        
             public static ClientContext GetAuthenticatedContext(string siteUrl, string userName, string password)
             {
                 SecureString securePassword = GetPassword(password);
                 return GetAuthenticatedContext(siteUrl, userName, securePassword);
             }
        
             private static SecureString GetPassword(string passwd)
             {
                 var secure = new SecureString();
                 foreach (char c in passwd)
                 {
                     secure.AppendChar(c);
                 }
                 return secure;
             }
        
             public static string EmptyIfNull(object obj)
             {
                 return obj == null ? "" : obj.ToString();
             }
         }
     }  

seem this statement string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken; inside my Helpers.GetAppOnlyContext will raise this error token request failed, as follow:-

enter image description here