apscheduler: how to add jobid, jobname and other details in mongodbjobstore - apscheduler

I am using apscheduler python library to schedule jobs. It have jobstores where
nextruntime gets stored. My question is how we can add more details of respective job store. I have shared a image as how its being stored right now.
mongo= MongoClient("localhost",27017)
job_stores = {
'default': MongoDBJobStore(database="logs",client=mongo,collection="schedulejob")
}
executors = {
'default': {'type': 'threadpool', 'max_workers': 60}
}
job_defaults = {
'coalesce': True, # When the same task is triggered multiple times at the same time, it runs only once
'max_instances': 3,
'misfire_grace_time': 30, # The task is still executed after 30 seconds of expiration
}
sched = BackgroundScheduler(jobstores=job_stores, executors=executors, job_defaults=job_defaults, daemon=True)
sched.add_job(syncdata, 'interval', minutes=5, kwargs={"subdomain": "d3v-digite", "emailid": "sp"},
name="incrementaljob")
sched.add_listener(listen, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR)
sched.start()
In mongojob store following is stored:

You can get some details from the database. You have job_state.
In MongoDBJobStore you can find a method called lookup_job.
Or use this:
def lookup_job(self, job_id):
document = self.collection.find_one(job_id, ['job_state'])
return self._reconstitute_job(document['job_state']) if document else None
Also you can decode job_state in that way:
job_state = pickle.loads(job_state)
And if all is OK, you will receive a dictionary with a lot of useful data, for example:
{'version': 1, 'id': 'feef92e4832642ae8361bcf6fd0f6fef', 'func': '', 'trigger': <CronTrigger (month='*', day='*', day_of_week='*', hour='*', minute='8', timezone='UTC')>, 'executor': 'default', 'args': ['scheduler.jobs.curl_job.CurlJob', 'feef92e4832642ae8361bcf6fd0f6fef', 'scheduler.corescheduler.datastore.providers.mongodb.DatastoreMongoDB', {'user': '', 'password': '', 'hostname': '', 'port': , 'database': ''}, {'jobs_tablename': '', 'executions_tablename': 'scheduler_execution', 'auditlogs_tablename': 'scheduler_jobauditlog'}, 'http://localhost/jobs', 'GET'], 'kwargs': {'job_name': 'Awesome_job_222'}, 'name': 'Awesome_job_222', 'misfire_grace_time': 3600, 'coalesce': True, 'max_instances': 3, 'next_run_time': datetime.datetime(2021, 11, 24, 15, 8, tzinfo=<UTC>)}

Related

Google Analytics Data API shows different count than web ui

I am getting less count than actual web ui that I download as csv.
There are around 35k entries but I am getting only 600 something.
Here is my code.
dimensions = ["sessionSource","customEvent:order_id","date","platform"]
metrics = ['sessions']
request = {
"requests": [
{
"dateRanges": [
{
"startDate": "2022-10-15",
"endDate": "2022-10-17"
}
],
"dimensions": [{'name': name} for name in dimensions],
"metrics": [{'name': name} for name in metrics],
"limit": 10,
"return_property_quota": True,
"keep_empty_rows": True,
"data_loss_from_other_row": False
}
]
}
analytics = build('analyticsdata', 'v1beta', credentials=credentials)
response = analytics.properties().batchRunReports(property=property_id,
body=request).execute()
report_data = defaultdict(list)
I see limit is set to 10 in your query. If this is set, the response will only contain 10 rows.

How do I get Account Information Through Algorand TypeScript SDK?

So Basically I'm trying to get Account Information.
Method: Algodv2accountInformation,
returns the AccountInformation type, but after calling .do()
.i.e
Algodv2accountInformation.do()
the return type is a more generic
<Promise<Record<string, any>>
What is the right way to make this api call but have it return right Information.
<AccountInformation>
I just checked their docs,
It is confusing as docs says it returns
<AccountInformation>
Here's Link to docs
<AccountInformation> is encapsulating request, not response.
What you can do it leverage class,
as it extends Base Class which does takes in Record<string,any> as input.
So the JSON you get from running .do() on .
accountInformation(account.addr).do():
{
address: 'LFNDB6ADWN7M3HFA7TSBKW4ZV7Q3TAJ2TWAGHH35WFGQAVGTJGFVJXQASI',
amount: 10000000,
'amount-without-pending-rewards': 10000000,
'apps-local-state': [],
'apps-total-schema': { 'num-byte-slice': 0, 'num-uint': 0 },
assets: [],
'created-apps': [],
'created-assets': [],
'min-balance': 100000,
'pending-rewards': 0,
'reward-base': 0,
rewards: 0,
round: 32,
status: 'Offline',
'total-apps-opted-in': 0,
'total-assets-opted-in': 0,
'total-created-apps': 0,
'total-created-assets': 0
}
Could be passed to Account(Record<String, any>) as follows:
new algosdk.modelsv2.Account(info):
Account {
address: 'LFNDB6ADWN7M3HFA7TSBKW4ZV7Q3TAJ2TWAGHH35WFGQAVGTJGFVJXQASI',
amount: 10000000,
amountWithoutPendingRewards: undefined,
minBalance: undefined,
pendingRewards: undefined,
rewards: 0,
round: 32,
status: 'Offline',
totalAppsOptedIn: undefined,
totalAssetsOptedIn: undefined,
totalCreatedApps: undefined,
totalCreatedAssets: undefined,
appsLocalState: undefined,
appsTotalExtraPages: undefined,
appsTotalSchema: undefined,
assets: [],
authAddr: undefined,
createdApps: undefined,
createdAssets: undefined,
participation: undefined,
rewardBase: undefined,
sigType: undefined,
attribute_map: {
address: 'address',
amount: 'amount',
amountWithoutPendingRewards: 'amount-without-pending-rewards',
minBalance: 'min-balance',
pendingRewards: 'pending-rewards',
rewards: 'rewards',
round: 'round',
status: 'status',
totalAppsOptedIn: 'total-apps-opted-in',
totalAssetsOptedIn: 'total-assets-opted-in',
totalCreatedApps: 'total-created-apps',
totalCreatedAssets: 'total-created-assets',
appsLocalState: 'apps-local-state',
appsTotalExtraPages: 'apps-total-extra-pages',
appsTotalSchema: 'apps-total-schema',
assets: 'assets',
authAddr: 'auth-addr',
createdApps: 'created-apps',
createdAssets: 'created-assets',
participation: 'participation',
rewardBase: 'reward-base',
sigType: 'sig-type'
}
}
And! Voilla! you've got your account model object!
Actually there should be some method .getModel(),
I'll create a PR, as this should be part of SDK.

Sequelize.js : Sum with condition and group by

I'm a biginner using Sequelize.
I spend hours trying to get the following code runs but I can't
I quit some columns from the table for better understanding.
Finance table
I want to get this result:
[
{
'month': 11,
'year': 2021,
'commission_paid_sum': 2700,
'comission_notPaid_sum':2500,
},
{
'month': 12,
'year': 2021,
'commission_paid_sum': 0,
'comission_notPaid_sum':1000,
},
{
'month': 1,
'year': 2022,
'commission_paid_sum': 2000,
'comission_notPaid_sum':0,
},
]
I tried:
1- adding a attribute but I don't get how to add the "where/having condition" in the fn Sum
db.Finanzas.findAll({
attributes: ['mes', 'ano','is_paid',
[Sequelize.fn('sum', Sequelize.col('agents_commission')), 'commission_paid_sum'],
[Sequelize.fn('sum', Sequelize.col('agents_commission')), 'comission_notPaid_sum'],
],
group: [ 'month' , 'year'],
I've tried also using the literal feature, but in this, I wasn't able to split them by month/year in the result.
If you think that there was an alternative option, I'll be happy to heard about that.
Thanks in advance!
Alejandro
Try it.
const { literal } = require('sequelize');
const finances = await Finance.findAll({
group: ['month', 'year'],
attributes: [
'year',
'month',
[literal(`SUM(CASE WHEN "is_paid" THEN "agents_commission" ELSE 0 END)`), 'commission_paid_sum'],
[literal(`SUM(CASE WHEN "is_paid" THEN 0 ELSE "agents_commission" END)`), 'commission_notPaid_sum']
]
});

Odoo 14 - account.payment the invoice_ids is removed but what is it replaced with?

Till Odoo 12, while creating a payment using API calls for invoices, we had to populate the invoice_ids field on the account.payment module and it would automatically mark the corresponding invoices PAID once the payment is validated.
I understand there is no functionality loss, however, I don't know what is this functionality replaced with.
I tried using invoice_line_ids and the invoice still doesn't get marked as PAID. There is only 1 move_id and even if I try that the invoice still doesn't get marked as PAID.
any thoughts?
Edit: This is the json that I am trying to send to Odoo to register a payment against an invoice. but the response is :
"The register payment wizard should only be called on account.move or account.move.line records."
I created a separate content after passing args in the json but still the response remained the same.
{
"jsonrpc":"2.0",
"method":"call",
"params":{
"service": "object",
"method": "execute",
"args":[
"{{databaseName}}",
{{userId}},
"{{password}}",
"account.payment.register",
"create",
{
"can_edit_wizard":true,
"can_group_payments":false,
"payment_type":"inbound",
"partner_type":"customer",
"source_amount":5.48,
"source_amount_currency":5.48,
"source_currency_id":2,
"partner_id":505449,
"country_code":"US",
"journal_id":230,
"other_journal_id":false,
"show_other_journal":false,
"payment_method_id":7,
"partner_bank_id":false,
"group_payment":true,
"amount":5.48,
"currency_id":2,
"payment_date":"2022-02-04",
"communication":"Test Create Invoice 32",
"payment_difference_handling":"open",
"writeoff_account_id":false,
"writeoff_label":"Write-Off",
"active_model":"account.move",
"active_id":364660,
"active_ids":[
364660
]
}
]
}
}
Account payment wizard uses line_ids field which is supposed to be passed through the context using the active_ids key (Odoo will retrieve the account move lines using the active ids)
The active_model should be passed through the context, if the active model is different from account.move or account.move.line Odoo will raise the following error:
The register payment wizard should only be called on account.move or account.move.line records.
The following example will use the same logic used in Register Payment button to create and register invoice payment:
vals = {}
payment_register_id = models.execute_kw(db, uid, password, 'account.payment.register', 'create', [vals], {'context': {'active_model': 'account.move', 'active_ids': invoice_ids}})
models.execute_kw(db, uid, password, 'account.payment.register', 'action_create_payments', [[payment_register_id]])
The following values are the default values passed to the create method when we create a payment manually (Using the register payment button on a customer invoice form):
{'can_group_payments': False, 'payment_type': 'inbound', 'partner_type': 'customer', 'source_amount': 365125, 'source_amount_currency': 365125, 'source_currency_id': 2, 'company_id': 1, 'partner_id': 10, 'country_code': 'US', 'journal_id': 7, 'payment_method_id': 1, 'payment_token_id': False, 'partner_bank_id': False, 'group_payment': True, 'amount': 365125, 'currency_id': 2, 'payment_date': '2022-02-04', 'communication': 'INV/2021/12/0001', 'payment_difference_handling': 'open', 'writeoff_account_id': False, 'can_edit_wizard': True, 'writeoff_label': 'Write-Off'}
Edit
You can call the execute_kw method and pass context in kwargs
{'jsonrpc': '2.0',
'method': 'call',
'params': {
'service': 'object',
'method': 'execute_kw',
'args': ('{{databaseName}}',
{{userId}},
'{{password}}',
'account.payment.register',
'create',
[{'journal_id': 7, ...}],
{'context': {'active_model': 'account.move', 'active_ids': [23]}}
)
},
'id': 843350301
}
The following code is based on the JSON-RPC Library documentation example
import json
import random
import urllib.request
HOST =
PORT =
DB =
USER =
PASS =
def json_rpc(url, method, params):
data = {
"jsonrpc": "2.0",
"method": method,
"params": params,
"id": random.randint(0, 1000000000),
}
req = urllib.request.Request(url=url, data=json.dumps(data).encode(), headers={
"Content-Type":"application/json",
})
reply = json.loads(urllib.request.urlopen(req).read().decode('UTF-8'))
if reply.get("error"):
raise Exception(reply["error"])
return reply["result"]
def call(url, service, method, *args):
return json_rpc(url, "call", {"service": service, "method": method, "args": args})
# log in the given database
url = "http://%s:%s/jsonrpc" % (HOST, PORT)
uid = call(url, "common", "login", DB, USER, PASS)
args = [{'journal_id': 7}]
kwargs = {'context': {'active_model': 'account.move', 'active_ids': [23]}}
payment_register_id = call(url, "object", "execute_kw", DB, uid, PASS, 'account.payment.register', 'create', args, kwargs)
call(url, "object", "execute", DB, uid, PASS, 'account.payment.register', 'action_create_payments', [payment_register_id])

CEX order book market update

I am trying to use cex.io API to construct a live order book, but I am struggling understanding the message from the API.
I am subscribing with the following JSON:
{
"e": "order-book-subscribe",
"data": {
"pair": [
"BTC",
"USD"
],
"subscribe": false,
"depth": -1
},
"oid": "1435927928274_3_order-book-subscribe"
}
The first message is a snapshot of the order book, this one its ok.
But next, the messages are "just" updates, same as this one :
{
'e': 'md_update',
'data': {
'id': 92276361,
'pair': 'BTC:USD',
'time': 1505337293621,
'bids': [],
'asks': [
[4078.1692, 0.0]
]
}
}
How do I update the snapshot first received with the updates lines ?
How do I know, if some of the lines if there was match in the book ?
And also if I subscribe with depth = 1, would the updates only be for best bid / best ask ?
You simply match the updates with the current state of your internal orderbook. The API sends you the changes which are made to the orderbook on server side.
Example:
The update message is:
{
'e': 'md_update',
'data': {
'id': 92276361,
'pair': 'BTC:USD',
'time': 1505337293621,
'bids': [],
'asks': [
[4070, 0.0],
[4080, 1]
]
}
}
We see the ask with 4070 price has now an remaining amount of 0. So delete that entry from your orderbook.
Ask 4080 now has an remaining amount of 1. You check if there is already an ask with price 4080 in your orderbook. If so, update the amount to 1. If there is no ask with 4080 in your orderbook, add an entry with price 4080 and amount 1 to your orderbook.