How to schedule timing for a JOB in Postgres using pgagent - postgresql

I have created a job using pgagent which I have scheduled on every 5 mins for that below is the code:
DO $$
DECLARE
jid integer;
scid integer;
BEGIN
-- Creating a new job
INSERT INTO pgagent.pga_job(
jobjclid, jobname, jobdesc, jobhostagent, jobenabled
) VALUES (
1::integer, 'refresh_mobile'::text, ''::text, ''::text, true
) RETURNING jobid INTO jid;
-- Steps
-- Inserting a step (jobid: NULL)
INSERT INTO pgagent.pga_jobstep (
jstjobid, jstname, jstenabled, jstkind,
jstconnstr, jstdbname, jstonerror,
jstcode, jstdesc
) VALUES (
jid, 'refresh_mobile_mv_data'::text, true, 's'::character(1),
''::text, 'ICSPGD'::name, 'f'::character(1),
'SELECT refresh_materialized_views(''mobile'');'::text, 'Please check. Issue occired while refreshing Mobile Data'::text
) ;
-- Schedules
-- Inserting a schedule
INSERT INTO pgagent.pga_schedule(
jscjobid, jscname, jscdesc, jscenabled,
jscstart, jscend, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths
) VALUES (
jid, 'minutly'::text, ''::text, true,
'2017-09-04 03:36:20-07'::timestamp with time zone, '2018-12-31 02:36:20-08'::timestamp with time zone,
-- Minutes
ARRAY[false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]::boolean[],
-- Hours
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]::boolean[],
-- Week days
ARRAY[true, true, true, true, true, true, true]::boolean[],
-- Month days
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]::boolean[],
-- Months
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true]::boolean[]
) RETURNING jscid INTO scid;
END
$$;
But when I am checking its statistics(in pgadmin) or via query "select * from pgagent.pga_job;" it shows that job are running at an interval of 1 hour.
For example: If the last job run time is 2017-10-05 03:05:00.703287-07 , then the next run time it shows : 2017-10-05 04:05:00-07.
Kindly help with the timing parameter. I am suppose to run this job on an interval of every 5 mins on a daily basis throughout.
Regards,

Have you tried something like this?
INSERT INTO pgagent.pga_schedule
(jscid, jscjobid, jscname, jscdesc, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths, jscenabled, jscstart, jscend)
VALUES(<SchId>, 29, 'minutly', '', '{t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f}', '{f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}', '{f,f,f,f,f,f,f}', '{f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}', '{f,f,f,f,f,f,f,f,f,f,f,f}', true, '2017-10-07 00:00:00', NULL);
Basically, what this insert is doing is marking the minutes 0,5,10,15,20,25,30,35,40,45,50 and 55 for every hour.
I don't know why you're creating it using insert statements, since the GUI offers a pretty neat way to schedule jobs. The same configuration can be done using the GUI like this:
I hope it helps :-)

Related

How to access the values only in flutter map

"turf_amenities": {
"turf_washroom": true,
"turf_water": true,
"turf_dressing": false,
"turf_parking": true,
"turf_gallery": true,
"turf_cafeteria": true
},
You can get the bool list like
final bools = data["turf_amenities"]?.values.toList();
print(bools);
final data = {
"turf_amenities": {
"turf_washroom": true,
"turf_water": true,
"turf_dressing": false,
"turf_parking": true,
"turf_gallery": true,
"turf_cafeteria": true
},
};
final values = data.values.toList();
print(
values); //[{turf_washroom: true, turf_water: true, turf_dressing: false, turf_parking: true, turf_gallery: true, turf_cafeteria: true}]
final bools = data["turf_amenities"]?.values.toList();
print(bools); //[true, true, false, true, true, true]

How to match two boolean tables and count match values and unmatch values

table_1
"mcqtest_id": 1,
"option_one_correct": true,
"option_two_correct": true,
"option_three_correct": true,
"option_four_correct": true,
"option_five_correct": false,
"option_six_correct": false,
"option_seven_correct": false,
"option_eight_correct": false,
"question_id": 1
table_2
"mcqtest_id": 1,
"option_one_correct": false,
"option_two_correct": true,
"option_three_correct": false,
"option_four_correct": true,
"option_five_correct": false,
"option_six_correct": false,
"option_seven_correct": false,
"option_eight_correct": false,
"question_id": 2
I want to find the match between this two boolean tables and if match count match values and else count unmatch values with postgresql query.
help me to understand and write this query

Scipy: Union of sparse boolean matrices

In Scipy, what is the most efficient way to get the union A+B+C of multiple boolean sparse (csr) matrices A,B,C (with the same shape)?
Union means among others:
sparsity changes
overlaps are possible
Just add them:
import scipy.sparse as sparse
x = sparse.csr_matrix([[True, True, False], [False, False, False], [True, False, False]] , dtype=bool)
y = sparse.csr_matrix([[False, True, False], [False, True, False], [False, True, False]], dtype=bool)
print((x + y).todense())
>>[[ True True False]
[False True False]
[ True True False]]
EDIT
If you want to access the indices directly, you can use coo format (which allows retrieving row and col index), stack the indices and use np.unique (disclaimer: I haven't checked for efficiency comparison):
import scipy.sparse as sparse
c2=sparse.eye(5, k=1, dtype=bool, format='coo')
c1=sparse.eye(5, dtype=bool, format='coo')
c3 = c1.copy()
c3.row, c3.col = np.unique(np.hstack((np.vstack((c1.col, c1.row)),np.vstack((c2.col, c2.row)))), axis=1)
c3.data = np.ones(c3.row.size, dtype=bool)
c3.todense()
>> matrix([[ True, False, False, False, False],
[ True, True, False, False, False],
[False, True, True, False, False],
[False, False, True, True, False],
[False, False, False, True, True]])

how to schedule a pgagent job through scripts/commandLine

I want to run jobs through PgAgent.
I am able to do that by creating a job in PgAgentJob through PgAdmin UI, as described here https://www.pgadmin.org/docs/pgadmin4/dev/pgagent_jobs.html.
But I want to use a sql script that can create a PgAgent job as we do in Oracle. Please suggest how I can achieve this.
To create a job in pgAgent use something like the following INSERT STATEMENTS (for a Routine Maintenance job) :
INSERT INTO pgagent.pga_job (jobid, jobjclid, jobname, jobdesc, jobenabled, jobhostagent)
SELECT jcl.jclid, 'MyJob', '', true, ''
FROM pgagent.pga_jobclass jcl WHERE jclname='Routine Maintenance';
To add a step to this job, which executes a SQL command ('delete from test where user_name=''test'';), use the following command:
INSERT INTO pgagent.pga_jobstep (jstjobid, jstname, jstdesc, jstenabled, jstkind, jstonerror, jstcode, jstdbname, jstconnstr)
SELECT (SELECT jobid
FROM pgagent.pga_job
WHERE jobname = 'MyJob'), 'MyStep', '', true, 's', 'f', 'delete from test where user_name=''test'';', 'postgres', '';
To create a schedule for this job (every day at 08:45), use the following command:
INSERT INTO pgagent.pga_schedule (jscjobid, jscname, jscdesc, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths, jscenabled, jscstart, jscend)
VALUES((SELECT jobid
FROM pgagent.pga_job
WHERE jobname = 'MyJob'), 'MySchedule', '', '{f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,t,f,f,f,f,f,f,f,f,f,f,f,f,f,f}',
'{f,f,f,f,f,f,f,f,t,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}', '{t,t,t,t,t,t,t}', '{t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t}',
'{t,t,t,t,t,t,t,t,t,t,t,t}', true, '2018-07-16 00:00:00', NULL);
Here a graphical representation of this schedule:
Here you can see a complete summary of these commands inside an anonymous block (generated by pgAdmin):
DO $$
DECLARE
jid integer;
scid integer;
BEGIN
-- Creating a new job
INSERT INTO pgagent.pga_job(
jobjclid, jobname, jobdesc, jobhostagent, jobenabled
) VALUES (
1::integer, 'MyJob'::text, ''::text, ''::text, true
) RETURNING jobid INTO jid;
-- Steps
-- Inserting a step (jobid: NULL)
INSERT INTO pgagent.pga_jobstep (
jstjobid, jstname, jstenabled, jstkind,
jstconnstr, jstdbname, jstonerror,
jstcode, jstdesc
) VALUES (
jid, 'MyStep'::text, true, 's'::character(1),
''::text, 'postgres'::name, 'f'::character(1),
'delete from test where user_name=''test'';'::text, ''::text
) ;
-- Schedules
-- Inserting a schedule
INSERT INTO pgagent.pga_schedule(
jscjobid, jscname, jscdesc, jscenabled,
jscstart, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths
) VALUES (
jid, 'MySchedule'::text, ''::text, true,
'2018-07-16 00:00:00+02'::timestamp with time zone,
-- Minutes
ARRAY[false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false]::boolean[],
-- Hours
ARRAY[false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]::boolean[],
-- Week days
ARRAY[true, true, true, true, true, true, true]::boolean[],
-- Month days
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]::boolean[],
-- Months
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true]::boolean[]
) RETURNING jscid INTO scid;
END
$$;

Error while loading serialization policy

I have a problem with my gwt project.
I've instantiated my project on two TomCat servers, and when I try to communicate server to server, Eclipse returns this error:
Jul 23, 2013 4:23:02 PM org.apache.catalina.core.ApplicationContext log
SEVERE: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract int it.ronf.client.RonfService.checkCarAgenzia(java.lang.String,java.lang.String)' threw an unexpected exception: com.google.gwt.user.client.rpc.InvocationException: Error while loading serialization policy 4B8D0D03E16542B6163548C2B2ACD7CA
at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:389)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:579)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: com.google.gwt.user.client.rpc.InvocationException: Error while loading serialization policy 4B8D0D03E16542B6163548C2B2ACD7CA
at com.gdevelop.gwt.syncrpc.RemoteServiceSyncProxy.<init>(RemoteServiceSyncProxy.java:89)
at com.gdevelop.gwt.syncrpc.RemoteServiceInvocationHandler.invoke(RemoteServiceInvocationHandler.java:99)
at com.sun.proxy.$Proxy0.CheckAuto(Unknown Source)
at it.ronf.server.RonfServiceImpl.checkCarAgenzia(RonfServiceImpl.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
... 21 more
Caused by: java.lang.NullPointerException: inputStream
at com.google.gwt.user.server.rpc.SerializationPolicyLoader.loadFromStream(SerializationPolicyLoader.java:110)
at com.gdevelop.gwt.syncrpc.RemoteServiceSyncProxy.<init>(RemoteServiceSyncProxy.java:87)
... 29 more
This is how I call the server to server function on the client side:
btnVerificaDisponibilit.addClickHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event){
RonfService.checkCarAgenzia("b","Mini", new AsyncCallback<Integer>(){
#Override
public void onFailure(Throwable caught){
}
#Override
public void onSuccess(Integer result){
if(result > 1){
btnAvviaTrasferimento.setVisible(true);
System.out.println("c'รจ");
}
else errorLabel.setText("Non ci sono modelli disponibile in altre agenzie.");
}
});
}
});
And this is the function on my server side:
#Override
public int checkCarAgenzia(String agenzia, String tipologia){
int n = 0;
if(agenzia.compareTo("b")==0){
final RonfService rpcService = (RonfService) SyncProxy.newProxyInstance(RonfService.class,"http://localhost:8081/Ronf-project/ronf/", "ronfservice");
n = rpcService.CheckAuto(tipologia);
}
else if(agenzia.compareTo("a")==0){
final RonfService rpcService = (RonfService) SyncProxy.newProxyInstance(RonfService.class, "http://localhost:8082/Ronf-project/ronf", "ronfservice");
n = rpcService.CheckAuto(tipologia);
}
return n;
}
#Override
public int CheckAuto(String tipologia){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List<Auto> auto = new ArrayList<Auto>(session.createQuery("from Auto where Tipologia ='" + tipologia + "' and Disponibilita='true'").list());
session.getTransaction().commit();
return auto.size();
}
Why does the serialization problem appear only when I try to communicate with server B but not when I try to communicate with server A?
ps: this is my rpc.gwt file
com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException, true, true, true, true, com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException/3936916533, 3936916533
com.google.gwt.user.client.rpc.RpcTokenException, true, true, false, false, com.google.gwt.user.client.rpc.RpcTokenException/2345075298, 2345075298
com.google.gwt.user.client.rpc.XsrfToken, false, false, true, true, com.google.gwt.user.client.rpc.XsrfToken/4254043109, 4254043109
it.ronf.client.RonfService, false, false, false, false, _, 1028614166
it.ronf.client.dto.AccountDTO, true, true, true, true, it.ronf.client.dto.AccountDTO/2817033572, 2817033572
it.ronf.client.dto.AgenziaDTO, true, true, true, true, it.ronf.client.dto.AgenziaDTO/2138136895, 2138136895
[Lit.ronf.client.dto.AgenziaDTO;, true, true, false, false, [Lit.ronf.client.dto.AgenziaDTO;/2014206060, 2014206060
it.ronf.client.dto.AutoDTO, true, true, true, true, it.ronf.client.dto.AutoDTO/3433806794, 3433806794
[Lit.ronf.client.dto.AutoDTO;, true, true, false, false, [Lit.ronf.client.dto.AutoDTO;/1522893402, 1522893402
it.ronf.client.dto.ClienteDTO, true, true, true, true, it.ronf.client.dto.ClienteDTO/2249269015, 2249269015
it.ronf.client.dto.NoleggioDTO, true, true, true, true, it.ronf.client.dto.NoleggioDTO/2812187262, 2812187262
[Lit.ronf.client.dto.NoleggioDTO;, true, true, false, false, [Lit.ronf.client.dto.NoleggioDTO;/1459858797, 1459858797
it.ronf.client.dto.RichiestaRifornimentoDTO, true, true, true, true, it.ronf.client.dto.RichiestaRifornimentoDTO/413727488, 413727488
[Lit.ronf.client.dto.RichiestaRifornimentoDTO;, true, true, false, false, [Lit.ronf.client.dto.RichiestaRifornimentoDTO;/793440202, 793440202
it.ronf.client.dto.RichiestaTrasferimentoDTO, true, true, true, true, it.ronf.client.dto.RichiestaTrasferimentoDTO/3484920730, 3484920730
[Lit.ronf.client.dto.RichiestaTrasferimentoDTO;, true, true, false, false, [Lit.ronf.client.dto.RichiestaTrasferimentoDTO;/1065675269, 1065675269
java.lang.Exception, true, false, true, false, java.lang.Exception/1920171873, 1920171873
java.lang.Long, true, true, true, true, java.lang.Long/4227064769, 4227064769
java.lang.Number, true, false, true, false, java.lang.Number/300033342, 300033342
java.lang.RuntimeException, true, false, true, false, java.lang.RuntimeException/515124647, 515124647
java.lang.String, true, true, true, true, java.lang.String/2004016611, 2004016611
java.lang.Throwable, true, false, true, false, java.lang.Throwable/2953622131, 2953622131
java.util.ArrayList, true, true, false, false, java.util.ArrayList/4159755760, 4159755760
java.util.Arrays$ArrayList, true, true, false, false, java.util.Arrays$ArrayList/2507071751, 2507071751
java.util.Collections$EmptyList, true, true, false, false, java.util.Collections$EmptyList/4157118744, 4157118744
java.util.Collections$SingletonList, true, true, false, false, java.util.Collections$SingletonList/1586180994, 1586180994
java.util.LinkedList, true, true, false, false, java.util.LinkedList/3953877921, 3953877921
java.util.Stack, true, true, false, false, java.util.Stack/1346942793, 1346942793
java.util.Vector, true, true, false, false, java.util.Vector/3057315478, 3057315478